Compare commits
2 commits
63e1762670
...
4fb5334ebc
Author | SHA1 | Date | |
---|---|---|---|
4fb5334ebc | |||
15ffddb20a |
1 changed files with 25 additions and 9 deletions
34
qjs.c
34
qjs.c
|
@ -496,6 +496,30 @@ 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
|
||||||
|
|
||||||
|
////Require and Global
|
||||||
|
const char *reqPF = "async function require(x) {\n"
|
||||||
|
" const y = await import(x);" // use dynamic import.
|
||||||
|
" return y;\n"
|
||||||
|
"}\n"
|
||||||
|
"globalThis.require = require;\n"
|
||||||
|
"globalThis.global = globalThis;\n";
|
||||||
|
eval_buf(ctx, reqPF, strlen(reqPF), "<input>", JS_EVAL_TYPE_MODULE);
|
||||||
|
|
||||||
|
|
||||||
|
const char *timeoutPF = "global.setTimeout = os.setTimeout\n"
|
||||||
|
"global.sleep = os.sleep";
|
||||||
|
eval_buf(ctx, timeoutPF, strlen(timeoutPF), "<input>", JS_EVAL_TYPE_MODULE);
|
||||||
|
|
||||||
|
const char *stdGlobals = "global.urlGet = std.urlGet\n"
|
||||||
|
"global.loadFile = std.loadFile\n"
|
||||||
|
"global.printf = std.printf\n"
|
||||||
|
"global.evalFile = std.loadScript\n"
|
||||||
|
"global.getURL = std.urlGet";
|
||||||
|
eval_buf(ctx, stdGlobals, strlen(stdGlobals), "<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))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -519,20 +543,12 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
js_std_loop(ctx);
|
js_std_loop(ctx);
|
||||||
}
|
}
|
||||||
//POLYFILLS BEGIN
|
|
||||||
const char *reqPF = "async function require(x) {\n"
|
|
||||||
" const y = await import(x);" // use dynamic import.
|
|
||||||
" return y;\n"
|
|
||||||
"}\n"
|
|
||||||
"globalThis.require = require;\n"
|
|
||||||
"globalThis.global = globalThis;\n";
|
|
||||||
eval_buf(ctx, reqPF, strlen(reqPF), "<input>", JS_EVAL_TYPE_MODULE);
|
|
||||||
if (dump_memory) {
|
if (dump_memory) {
|
||||||
JSMemoryUsage stats;
|
JSMemoryUsage stats;
|
||||||
JS_ComputeMemoryUsage(rt, &stats);
|
JS_ComputeMemoryUsage(rt, &stats);
|
||||||
JS_DumpMemoryUsage(stdout, &stats, rt);
|
JS_DumpMemoryUsage(stdout, &stats, rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
js_std_free_handlers(rt);
|
js_std_free_handlers(rt);
|
||||||
JS_FreeContext(ctx);
|
JS_FreeContext(ctx);
|
||||||
JS_FreeRuntime(rt);
|
JS_FreeRuntime(rt);
|
||||||
|
|
Loading…
Reference in a new issue