Update qjs.c

This commit is contained in:
The Ghost of FOSS' Future 2025-01-09 01:12:04 +00:00 committed by GitHub
parent 23d4991413
commit 68e14c7e8e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

14
qjs.c
View file

@ -624,7 +624,7 @@ start:
if (!empty_run) {
js_std_add_helpers(ctx, argc - optind, argv + optind);
//POLYFILLS FOR QJS FILES BEGIN
//POLYFILLS
const char *pf = "globalThis.global = globalThis;\n"
"global.console.error = console.log\n"
"global.console.warn = console.log\n"
@ -652,20 +652,18 @@ start:
" console.error('std is not defined.');\n"
"}\n";
/* make 'std' and 'os' visible to non module code */
if (load_std) {
const char *str =
const stdAndOS *str =
"import * as bjson from 'qjs:bjson';\n"
"import * as std from 'qjs:std';\n"
"import * as os from 'qjs:os';\n"
"globalThis.bjson = bjson;\n"
"globalThis.std = std;\n"
"globalThis.os = os;\n";
eval_buf(ctx, str, strlen(str), "<input>", JS_EVAL_TYPE_MODULE);
/* make 'std' 'os' and polyfills visible to non module code */
eval_buf(ctx, stdAndOS, strlen(stdAndOS), "<input>", JS_EVAL_TYPE_MODULE);
eval_buf(ctx, pf, strlen(pf), "<input>", JS_EVAL_TYPE_MODULE);
} else {
eval_buf(ctx, pf, strlen(pf), "<input>", JS_EVAL_TYPE_MODULE);
}
for(i = 0; i < include_count; i++) {
if (eval_file(ctx, include_list[i], 0))