mirror of
https://github.com/DoneJS-Runtime/quickjs-done-nextgen.git
synced 2025-01-09 17:43:15 +00:00
Prefix stdlib modules with "qjs:"
Fixes: https://github.com/quickjs-ng/quickjs/issues/616
This commit is contained in:
parent
3339ef7137
commit
cc11a829e8
17 changed files with 38 additions and 25 deletions
|
@ -33,7 +33,7 @@ Returns `quickjs-ng/<version>`.
|
|||
|
||||
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.
|
||||
|
||||
|
|
|
@ -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'}`);
|
||||
|
|
|
@ -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'}`);
|
||||
|
|
BIN
gen/repl.c
BIN
gen/repl.c
Binary file not shown.
BIN
gen/test_fib.c
BIN
gen/test_fib.c
Binary file not shown.
6
qjs.c
6
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));
|
||||
|
|
4
qjsc.c
4
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);
|
||||
|
|
10
quickjs.c
10
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);
|
||||
}
|
||||
|
|
6
repl.js
6
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 */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 += "";
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import * as os from "os";
|
||||
import * as os from "qjs:os";
|
||||
import { assert } from "./assert.js";
|
||||
|
||||
var worker;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue