move globals back to qjs.c
Some checks failed
ci / Linux (Ubuntu) (push) Has been cancelled
ci / linux-asan (push) Has been cancelled
ci / linux-msan (push) Has been cancelled
ci / linux-ubsan (push) Has been cancelled
ci / macOS (push) Has been cancelled
ci / macos-asan (push) Has been cancelled
ci / macos-ubsan (push) Has been cancelled
ci / freebsd (push) Has been cancelled
ci / qemu-alpine (arm32v6) (push) Has been cancelled
ci / qemu-alpine (arm32v7) (push) Has been cancelled
ci / qemu-alpine (arm64v8) (push) Has been cancelled
ci / qemu-alpine (i386) (push) Has been cancelled
ci / qemu-alpine (s390x) (push) Has been cancelled
Some checks failed
ci / Linux (Ubuntu) (push) Has been cancelled
ci / linux-asan (push) Has been cancelled
ci / linux-msan (push) Has been cancelled
ci / linux-ubsan (push) Has been cancelled
ci / macOS (push) Has been cancelled
ci / macos-asan (push) Has been cancelled
ci / macos-ubsan (push) Has been cancelled
ci / freebsd (push) Has been cancelled
ci / qemu-alpine (arm32v6) (push) Has been cancelled
ci / qemu-alpine (arm32v7) (push) Has been cancelled
ci / qemu-alpine (arm64v8) (push) Has been cancelled
ci / qemu-alpine (i386) (push) Has been cancelled
ci / qemu-alpine (s390x) (push) Has been cancelled
This commit is contained in:
parent
868bc825e1
commit
bad2bdc661
2 changed files with 26 additions and 28 deletions
26
qjs.c
26
qjs.c
|
@ -718,6 +718,32 @@ start:
|
||||||
js_std_eval_binary(ctx, qjsc_repl, qjsc_repl_size, 0);
|
js_std_eval_binary(ctx, qjsc_repl, qjsc_repl_size, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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.printf = console.log;\n"
|
||||||
|
" globalThis.evalFile = std.loadScript;\n"
|
||||||
|
" globalThis.require = (moduleSpecifier) => import(moduleSpecifier).then(mod => mod.default || mod);\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 (standalone || compile_file) {
|
if (standalone || compile_file) {
|
||||||
if (JS_IsException(ret)) {
|
if (JS_IsException(ret)) {
|
||||||
ret = JS_GetException(ctx);
|
ret = JS_GetException(ctx);
|
||||||
|
|
28
repl.js
28
repl.js
|
@ -26,35 +26,7 @@ import * as std from "qjs:std";
|
||||||
import * as os from "qjs:os";
|
import * as os from "qjs:os";
|
||||||
import * as bjson from "qjs:bjson";
|
import * as bjson from "qjs:bjson";
|
||||||
|
|
||||||
|
|
||||||
globalThis.global = globalThis
|
|
||||||
globalThis.safeGlobal = {}
|
|
||||||
global.console.error = console.log
|
|
||||||
global.console.warn = console.log
|
|
||||||
|
|
||||||
if (typeof os !== 'undefined') {
|
|
||||||
globalThis.sleep = os.sleep
|
|
||||||
async function setTimeout2(func, ms) {globalThis.clearTimeout = false; await sleep(ms); if (!clearTimeout) { func(); } }
|
|
||||||
globalThis.setTimeout = setTimeout2
|
|
||||||
} else {
|
|
||||||
console.error('os is not defined.')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof std !== 'undefined') {
|
|
||||||
globalThis.urlGet = std.urlGet
|
|
||||||
globalThis.loadFile = std.loadFile
|
|
||||||
globalThis.printf = console.log
|
|
||||||
globalThis.evalFile = std.loadScript
|
|
||||||
globalThis.require = (moduleSpecifier) => import(moduleSpecifier).then(mod => mod.default || mod);
|
|
||||||
globalThis.getURL = std.urlGet
|
|
||||||
} else {
|
|
||||||
console.error('std is not defined.');
|
|
||||||
}
|
|
||||||
|
|
||||||
(function(g) {
|
(function(g) {
|
||||||
/* init polyfills */
|
|
||||||
g = globalThis
|
|
||||||
|
|
||||||
/* add 'bjson', 'os' and 'std' bindings */
|
/* add 'bjson', 'os' and 'std' bindings */
|
||||||
g.bjson = bjson;
|
g.bjson = bjson;
|
||||||
g.os = os;
|
g.os = os;
|
||||||
|
|
Loading…
Reference in a new issue