diff --git a/docs/docs/stdlib.md b/docs/docs/stdlib.md index 6dd83bc..1e383e8 100644 --- a/docs/docs/stdlib.md +++ b/docs/docs/stdlib.md @@ -33,7 +33,7 @@ Returns `quickjs-ng/`. Shorthand for `std.gc()`. -## `bjson` module +## `qjs:bjson` module ### `bjson.write(obj, [flags])` @@ -58,7 +58,7 @@ Supported flags: - `READ_OBJ_REFERENCE`: allow de-serializing object references - `READ_OBJ_SAB`: allow de-serializing SharedArrayBuffer instances -## `os` module +## `qjs:os` module The `os` module provides Operating System specific functions: @@ -323,7 +323,7 @@ The worker instances have the following properties: received message. The thread is not terminated if there is at least one non `null` `onmessage` handler. -## `std` module +## `qjs:std` module The `std` module provides wrappers to libc (`stdlib.h` and `stdio.h`) and a few other utilities. diff --git a/examples/test_fib.js b/examples/test_fib.js index 4bdf9dc..f22c576 100644 --- a/examples/test_fib.js +++ b/examples/test_fib.js @@ -1,5 +1,5 @@ /* example of JS module importing a C module */ -import * as os from "os"; +import * as os from "qjs:os"; const isWin = os.platform === 'win32'; const { fib } = await import(`./fib.${isWin ? 'dll' : 'so'}`); diff --git a/examples/test_point.js b/examples/test_point.js index 7400420..1e0fafa 100644 --- a/examples/test_point.js +++ b/examples/test_point.js @@ -1,5 +1,5 @@ /* example of JS module importing a C module */ -import * as os from "os"; +import * as os from "qjs:os"; const isWin = os.platform === 'win32'; const { Point } = await import(`./point.${isWin ? 'dll' : 'so'}`); diff --git a/gen/repl.c b/gen/repl.c index 5024e94..f92b09d 100644 Binary files a/gen/repl.c and b/gen/repl.c differ diff --git a/gen/test_fib.c b/gen/test_fib.c index 097cd76..579f9d0 100644 Binary files a/gen/test_fib.c and b/gen/test_fib.c differ diff --git a/qjs.c b/qjs.c index 5631543..30d4577 100644 --- a/qjs.c +++ b/qjs.c @@ -164,9 +164,9 @@ static JSContext *JS_NewCustomContext(JSRuntime *rt) if (!ctx) return NULL; /* system modules */ - js_init_module_std(ctx, "std"); - js_init_module_os(ctx, "os"); - js_init_module_bjson(ctx, "bjson"); + js_init_module_std(ctx, "qjs:std"); + js_init_module_os(ctx, "qjs:os"); + js_init_module_bjson(ctx, "qjs:bjson"); JSValue global = JS_GetGlobalObject(ctx); JS_SetPropertyFunctionList(ctx, global, global_obj, countof(global_obj)); diff --git a/qjsc.c b/qjsc.c index 1ef26ee..8e0b58b 100644 --- a/qjsc.c +++ b/qjsc.c @@ -375,7 +375,11 @@ int main(int argc, char **argv) stack_size = 0; memset(&dynamic_module_list, 0, sizeof(dynamic_module_list)); + /* add system modules */ + namelist_add(&cmodule_list, "qjs:std", "std", 0); + namelist_add(&cmodule_list, "qjs:os", "os", 0); + namelist_add(&cmodule_list, "qjs:bjson", "bjson", 0); namelist_add(&cmodule_list, "std", "std", 0); namelist_add(&cmodule_list, "os", "os", 0); namelist_add(&cmodule_list, "bjson", "bjson", 0); diff --git a/quickjs.c b/quickjs.c index c79b509..da72553 100644 --- a/quickjs.c +++ b/quickjs.c @@ -26267,6 +26267,16 @@ static char *js_default_module_normalize_name(JSContext *ctx, int len; if (name[0] != '.') { + /* Backwards compatibility for stdlib rename. */ + static const char names[] = "qjs:bjson\0qjs:std\0qjs:os"; + for (const char *p = names; p < endof(names); p += 1 + strlen(p)) { + if (!strcmp(name, p+4)) { +#ifndef NDEBUG + printf("WARN: Standard library modules should be prefixed with `qjs:`. Example: %s\n", p); +#endif + return js_strdup(ctx, p); + } + } /* if no initial dot, the module name is not modified */ return js_strdup(ctx, name); } diff --git a/repl.js b/repl.js index 78f354e..00dd52b 100644 --- a/repl.js +++ b/repl.js @@ -22,9 +22,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -import * as std from "std"; -import * as os from "os"; -import * as bjson from "bjson"; +import * as std from "qjs:std"; +import * as os from "qjs:os"; +import * as bjson from "qjs:bjson"; (function(g) { /* add 'bjson', 'os' and 'std' bindings */ diff --git a/run-test262.c b/run-test262.c index 9f44ac4..3c88496 100644 --- a/run-test262.c +++ b/run-test262.c @@ -1695,9 +1695,9 @@ JSContext *JS_NewCustomContext(JSRuntime *rt) ctx = JS_NewContext(rt); if (ctx && local) { - js_init_module_std(ctx, "std"); - js_init_module_os(ctx, "os"); - js_init_module_bjson(ctx, "bjson"); + js_init_module_std(ctx, "qjs:std"); + js_init_module_os(ctx, "qjs:os"); + js_init_module_bjson(ctx, "qjs:bjson"); } return ctx; } diff --git a/tests/detect_module/4.js b/tests/detect_module/4.js index 3ee1df7..5713f31 100644 --- a/tests/detect_module/4.js +++ b/tests/detect_module/4.js @@ -1,3 +1,3 @@ // imports should classify it as a module, even when not at the top os.now() -import * as os from "os" +import * as os from "qjs:os" diff --git a/tests/microbench.js b/tests/microbench.js index c8cb4c7..5560c24 100644 --- a/tests/microbench.js +++ b/tests/microbench.js @@ -22,8 +22,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -import * as std from "std"; -import * as os from "os"; +import * as std from "qjs:std"; +import * as os from "qjs:os"; function pad(str, n) { str += ""; diff --git a/tests/test_bjson.js b/tests/test_bjson.js index a957cee..4976015 100644 --- a/tests/test_bjson.js +++ b/tests/test_bjson.js @@ -1,5 +1,5 @@ -import * as std from "std"; -import * as bjson from "bjson"; +import * as std from "qjs:std"; +import * as bjson from "qjs:bjson"; import { assert } from "./assert.js"; function base64decode(s) { diff --git a/tests/test_builtin.js b/tests/test_builtin.js index 0dbe243..4c29503 100644 --- a/tests/test_builtin.js +++ b/tests/test_builtin.js @@ -1,4 +1,4 @@ -import * as os from "os"; +import * as os from "qjs:os"; import { assert, assertThrows } from "./assert.js"; // Keep this at the top; it tests source positions. diff --git a/tests/test_std.js b/tests/test_std.js index b9ea6e2..0f70c6d 100644 --- a/tests/test_std.js +++ b/tests/test_std.js @@ -1,5 +1,5 @@ -import * as std from "std"; -import * as os from "os"; +import * as std from "qjs:std"; +import * as os from "qjs:os"; import { assert } from "./assert.js"; const isWin = os.platform === 'win32'; diff --git a/tests/test_worker.js b/tests/test_worker.js index bd0d0b9..8309c18 100644 --- a/tests/test_worker.js +++ b/tests/test_worker.js @@ -1,4 +1,4 @@ -import * as os from "os"; +import * as os from "qjs:os"; import { assert } from "./assert.js"; var worker; diff --git a/tests/test_worker_module.js b/tests/test_worker_module.js index 91a83f6..7280c69 100644 --- a/tests/test_worker_module.js +++ b/tests/test_worker_module.js @@ -1,6 +1,5 @@ /* Worker code for test_worker.js */ -import * as std from "std"; -import * as os from "os"; +import * as os from "qjs:os"; var parent = os.Worker.parent;