Skip to content

Commit ec224aa

Browse files
committed
Prefix stdlib modules with "qjs:"
Fixes: #616
1 parent caa1bf5 commit ec224aa

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

qjs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ static JSContext *JS_NewCustomContext(JSRuntime *rt)
164164
if (!ctx)
165165
return NULL;
166166
/* system modules */
167-
js_init_module_std(ctx, "std");
168-
js_init_module_os(ctx, "os");
169-
js_init_module_bjson(ctx, "bjson");
167+
js_init_module_std(ctx, "qjs:std");
168+
js_init_module_os(ctx, "qjs:os");
169+
js_init_module_bjson(ctx, "qjs:bjson");
170170

171171
JSValue global = JS_GetGlobalObject(ctx);
172172
JS_SetPropertyFunctionList(ctx, global, global_obj, countof(global_obj));

quickjs.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26267,6 +26267,29 @@ static char *js_default_module_normalize_name(JSContext *ctx,
2626726267
int len;
2626826268

2626926269
if (name[0] != '.') {
26270+
/* Backwards compatibility for stdlib rename. */
26271+
static char *prefix = "qjs:";
26272+
static char *names[] = {
26273+
"bjson",
26274+
"std",
26275+
"os",
26276+
NULL
26277+
};
26278+
int i;
26279+
for (i = 0; names[i]; i++) {
26280+
if (!strcmp(name, names[i])) {
26281+
#ifndef NDEBUG
26282+
printf("WARN: Standard library modules should be prefixed with `qjs:`. Example: qjs:%s\n", name);
26283+
#endif
26284+
len = strlen(prefix) + strlen(name) + 1;
26285+
filename = js_mallocz(ctx, len);
26286+
if (!filename)
26287+
return NULL;
26288+
pstrcat(filename, len, prefix);
26289+
pstrcat(filename, len, name);
26290+
return filename;
26291+
}
26292+
}
2627026293
/* if no initial dot, the module name is not modified */
2627126294
return js_strdup(ctx, name);
2627226295
}

run-test262.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,9 +1695,9 @@ JSContext *JS_NewCustomContext(JSRuntime *rt)
16951695

16961696
ctx = JS_NewContext(rt);
16971697
if (ctx && local) {
1698-
js_init_module_std(ctx, "std");
1699-
js_init_module_os(ctx, "os");
1700-
js_init_module_bjson(ctx, "bjson");
1698+
js_init_module_std(ctx, "qjs:std");
1699+
js_init_module_os(ctx, "qjs:os");
1700+
js_init_module_bjson(ctx, "qjs:bjson");
17011701
}
17021702
return ctx;
17031703
}

0 commit comments

Comments
 (0)