@mikrojs/native 0.14.0-pr-229.gbbf898a → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CMakeLists.txt
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikrojs/native",
|
|
3
|
-
"version": "0.14.0
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Mikro.js C++ runtime library and Node.js native addon",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"esp32",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"cmake-js": "^8.0.0",
|
|
84
84
|
"node-addon-api": "^8.7.0",
|
|
85
85
|
"node-gyp-build": "^4.8.4",
|
|
86
|
-
"@mikrojs/quickjs": "0.14.0
|
|
86
|
+
"@mikrojs/quickjs": "0.14.0"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
89
|
"@swc/core": "^1.15.30",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/modules.cpp
CHANGED
|
@@ -262,6 +262,12 @@ static JSModuleDef* mik_module_loader_inner(JSContext* ctx, const char* module_n
|
|
|
262
262
|
{
|
|
263
263
|
JSModuleDef* ext_m = mik__load_builtin(ctx, module_name);
|
|
264
264
|
if (ext_m) return ext_m;
|
|
265
|
+
/* NULL with an exception pending means the builtin was found but
|
|
266
|
+
* failed to load (deserialization or import resolution). Don't fall
|
|
267
|
+
* through to filesystem resolution — it would replace the real error
|
|
268
|
+
* with a generic "failed to resolve" one. Same probe as the mikro/
|
|
269
|
+
* branch above (JS_HasException, not JS_GetException + JS_IsNull). */
|
|
270
|
+
if (JS_HasException(ctx)) return NULL;
|
|
265
271
|
}
|
|
266
272
|
|
|
267
273
|
return mik_module_load_from_fs(ctx, module_name);
|
|
@@ -654,6 +660,18 @@ static bool mik__is_anchored_name(const char* name) {
|
|
|
654
660
|
strncmp(name, "@mikrojs/", 9) == 0;
|
|
655
661
|
}
|
|
656
662
|
|
|
663
|
+
/* A name registered via MIK_REGISTER_BUILTIN() is bytecode compiled into the
|
|
664
|
+
* firmware — the same trust level as @mikrojs builtins, regardless of the
|
|
665
|
+
* package's npm scope. */
|
|
666
|
+
static bool mik__is_ext_builtin_name(const char* name) {
|
|
667
|
+
for (mik_ext_builtin_t* p = mik__ext_builtin_head; p != nullptr; p = p->next) {
|
|
668
|
+
if (strcmp(p->name, name) == 0) {
|
|
669
|
+
return true;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return false;
|
|
673
|
+
}
|
|
674
|
+
|
|
657
675
|
/* Record an edge in the module dependency graph: `base` imports `target`.
|
|
658
676
|
* No-ops if the MIKRuntime is absent, base is empty/non-module, or target
|
|
659
677
|
* is anchored. Keyed by normalized names. */
|
|
@@ -674,10 +692,13 @@ static char* mik__module_normalizer_impl(JSContext* ctx, const char* base_name,
|
|
|
674
692
|
|
|
675
693
|
static const char internal_prefix[] = "native:";
|
|
676
694
|
if (strncmp(name, internal_prefix, strlen(internal_prefix)) == 0) {
|
|
677
|
-
// Only
|
|
695
|
+
// Only firmware-embedded modules (native:, mikro/, @mikrojs/, registered
|
|
696
|
+
// external builtins) may import native: internals
|
|
678
697
|
if (strncmp(base_name, "native:", 7) != 0 && strncmp(base_name, "mikro/", 6) != 0 &&
|
|
679
|
-
strncmp(base_name, "@mikrojs/", 9) != 0) {
|
|
680
|
-
JS_ThrowTypeError(
|
|
698
|
+
strncmp(base_name, "@mikrojs/", 9) != 0 && !mik__is_ext_builtin_name(base_name)) {
|
|
699
|
+
JS_ThrowTypeError(
|
|
700
|
+
ctx, "Cannot import '%s': native modules can only be imported by firmware builtins",
|
|
701
|
+
name);
|
|
681
702
|
return NULL;
|
|
682
703
|
}
|
|
683
704
|
}
|
|
@@ -689,10 +710,8 @@ static char* mik__module_normalizer_impl(JSContext* ctx, const char* base_name,
|
|
|
689
710
|
}
|
|
690
711
|
/* Check if this bare specifier matches an external builtin (board/driver
|
|
691
712
|
* package). If so, pass through unchanged to avoid filesystem resolution. */
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
return js_strdup(ctx, name);
|
|
695
|
-
}
|
|
713
|
+
if (mik__is_ext_builtin_name(name)) {
|
|
714
|
+
return js_strdup(ctx, name);
|
|
696
715
|
}
|
|
697
716
|
/* Bare specifier — try node_modules resolution.
|
|
698
717
|
* Heap-allocate the dir buffer to keep the normalizer stack frame
|