Update qjs.c

This commit is contained in:
The Ghost of FOSS' Future 2025-01-09 00:43:27 +00:00 committed by GitHub
parent 2cb4872308
commit 5fd2efe534
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

60
qjs.c
View file

@ -636,36 +636,6 @@ start:
eval_buf(ctx, str, strlen(str), "<input>", JS_EVAL_TYPE_MODULE); eval_buf(ctx, str, strlen(str), "<input>", JS_EVAL_TYPE_MODULE);
} }
//POLYFILLS FOR QJS FILES BEGIN
const char *pf = "globalThis.global = globalThis;\n"
"global.console.error = console.log\n"
"global.console.warn = console.log\n"
"globalThis.breakFunction = () => { throw new Error('Function Break'); };\n"
"\n"
"if (typeof os !== 'undefined') {\n"
" globalThis.sleep = os.sleep;\n"
" async function setTimeout2(func, ms) {globalThis.clearTimeout = false; await sleep(ms); if (!clearTimeout) { func(); } }\n"
" globalThis.setTimeout = setTimeout2\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.doneRequire = std.loadFile;\n"
" globalThis.printf = console.log;\n"
" globalThis.evalFile = std.loadScript;\n"
" globalThis.require = (moduleSpecifier) => import(moduleSpecifier).then(mod => mod.default || mod);\n"
" globalThis.stdRequire = globalThis.require;\n"
" globalThis.safeGlobals = {} \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);
for(i = 0; i < include_count; i++) { for(i = 0; i < include_count; i++) {
if (eval_file(ctx, include_list[i], 0)) if (eval_file(ctx, include_list[i], 0))
goto fail; goto fail;
@ -711,6 +681,36 @@ start:
goto fail; goto fail;
} }
//POLYFILLS FOR QJS FILES BEGIN
const char *pf = "globalThis.global = globalThis;\n"
"global.console.error = console.log\n"
"global.console.warn = console.log\n"
"globalThis.breakFunction = () => { throw new Error('Function Break'); };\n"
"\n"
"if (typeof os !== 'undefined') {\n"
" globalThis.sleep = os.sleep;\n"
" async function setTimeout2(func, ms) {globalThis.clearTimeout = false; await sleep(ms); if (!clearTimeout) { func(); } }\n"
" globalThis.setTimeout = setTimeout2\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.doneRequire = std.loadFile;\n"
" globalThis.printf = console.log;\n"
" globalThis.evalFile = std.loadScript;\n"
" globalThis.require = (moduleSpecifier) => import(moduleSpecifier).then(mod => mod.default || mod);\n"
" globalThis.stdRequire = globalThis.require;\n"
" globalThis.safeGlobals = {} \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);
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);
} }