add validation checks, move polyfills so os and std functions work
Some checks are pending
ci / Linux (Ubuntu) (push) Waiting to run
ci / linux-asan (push) Waiting to run
ci / linux-msan (push) Waiting to run
ci / linux-ubsan (push) Waiting to run
ci / macOS (push) Waiting to run
ci / macos-asan (push) Waiting to run
ci / macos-ubsan (push) Waiting to run
ci / freebsd (push) Waiting to run
ci / qemu-alpine (arm32v6) (push) Waiting to run
ci / qemu-alpine (arm32v7) (push) Waiting to run
ci / qemu-alpine (arm64v8) (push) Waiting to run
ci / qemu-alpine (i386) (push) Waiting to run
ci / qemu-alpine (s390x) (push) Waiting to run
Some checks are pending
ci / Linux (Ubuntu) (push) Waiting to run
ci / linux-asan (push) Waiting to run
ci / linux-msan (push) Waiting to run
ci / linux-ubsan (push) Waiting to run
ci / macOS (push) Waiting to run
ci / macos-asan (push) Waiting to run
ci / macos-ubsan (push) Waiting to run
ci / freebsd (push) Waiting to run
ci / qemu-alpine (arm32v6) (push) Waiting to run
ci / qemu-alpine (arm32v7) (push) Waiting to run
ci / qemu-alpine (arm64v8) (push) Waiting to run
ci / qemu-alpine (i386) (push) Waiting to run
ci / qemu-alpine (s390x) (push) Waiting to run
This commit is contained in:
parent
94d52bfdc6
commit
24692fbb5f
1 changed files with 32 additions and 17 deletions
49
qjs.c
49
qjs.c
|
@ -496,23 +496,6 @@ int main(int argc, char **argv)
|
||||||
eval_buf(ctx, str, strlen(str), "<input>", JS_EVAL_TYPE_MODULE);
|
eval_buf(ctx, str, strlen(str), "<input>", JS_EVAL_TYPE_MODULE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//POLYFILLS BEGIN
|
|
||||||
const char *pf = "async function require(x) {\n"
|
|
||||||
" const y = await import(x);" // use dynamic import.
|
|
||||||
" return y;\n"
|
|
||||||
"}\n"
|
|
||||||
"globalThis.require = require;\n"
|
|
||||||
"globalThis.setTimeout = os.setTimeout;\n"
|
|
||||||
"globalThis.clearTimeout = os.clearTimeout;\n"
|
|
||||||
"globalThis.sleep = os.sleep;\n"
|
|
||||||
"globalThis.urlGet = std.urlGet;\n"
|
|
||||||
"globalThis.loadFile = std.loadFile;\n"
|
|
||||||
"globalThis.printf = std.printf;\n"
|
|
||||||
"globalThis.evalFile = std.loadScript;\n"
|
|
||||||
"globalThis.getURL = std.urlGet;\n"
|
|
||||||
"globalThis.global = globalThis;\n";
|
|
||||||
eval_buf(ctx, pf, strlen(pf), "<input>", JS_EVAL_TYPE_MODULE);
|
|
||||||
|
|
||||||
|
|
||||||
for(i = 0; i < include_count; i++) {
|
for(i = 0; i < include_count; i++) {
|
||||||
if (eval_file(ctx, include_list[i], module))
|
if (eval_file(ctx, include_list[i], module))
|
||||||
|
@ -535,6 +518,38 @@ int main(int argc, char **argv)
|
||||||
if (interactive) {
|
if (interactive) {
|
||||||
js_std_eval_binary(ctx, qjsc_repl, qjsc_repl_size, 0);
|
js_std_eval_binary(ctx, qjsc_repl, qjsc_repl_size, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//POLYFILLS BEGIN
|
||||||
|
const char *pf = "async function require(x) {\n"
|
||||||
|
" const y = await import(x);\n"
|
||||||
|
" return y;\n"
|
||||||
|
"}\n"
|
||||||
|
"globalThis.require = require;\n"
|
||||||
|
"globalThis.global = globalThis;\n"
|
||||||
|
"global.console.error = console.log\n"
|
||||||
|
"global.console.warn = console.log\n"
|
||||||
|
"\n"
|
||||||
|
"if (typeof os !== 'undefined') {\n"
|
||||||
|
" globalThis.setTimeout = os.setTimeout;\n"
|
||||||
|
" globalThis.clearTimeout = os.clearTimeout;\n"
|
||||||
|
" globalThis.sleep = os.sleep;\n"
|
||||||
|
"} else {\n"
|
||||||
|
" console.error('os is not defined.');\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"if (typeof std !== 'undefined') {\n"
|
||||||
|
" globalThis.urlGet = std.urlGet;\n"
|
||||||
|
" globalThis.loadFile = std.loadFile;\n"
|
||||||
|
" globalThis.printf = std.printf;\n"
|
||||||
|
" globalThis.evalFile = std.loadScript;\n"
|
||||||
|
" globalThis.getURL = std.urlGet;\n"
|
||||||
|
"} else {\n"
|
||||||
|
" console.error('std is not defined.');\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
|
||||||
|
eval_buf(ctx, pf, strlen(pf), "<input>", JS_EVAL_TYPE_MODULE);
|
||||||
|
|
||||||
js_std_loop(ctx);
|
js_std_loop(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue