diff --git a/.gitignore b/.gitignore index 02130c1..e878101 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ unicode_gen run_octane run_sunspider_like build/ +.vscode/ \ No newline at end of file diff --git a/qjs.c b/qjs.c index 41ff6cb..b4ee1c7 100644 --- a/qjs.c +++ b/qjs.c @@ -174,7 +174,7 @@ static int eval_file(JSContext *ctx, const char *filename, int module) " globalThis.loadFile = std.loadFile;\n" " globalThis.printf = console.log;\n" " globalThis.evalFile = std.loadScript;\n" - //" globalThis.require = 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" diff --git a/repl.js b/repl.js index 77b7752..3c73e1b 100644 --- a/repl.js +++ b/repl.js @@ -27,6 +27,11 @@ import * as os from "qjs:os"; 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(); } } @@ -35,20 +40,21 @@ if (typeof os !== 'undefined') { 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 = 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) { + /* init polyfills */ + g = globalThis + /* add 'bjson', 'os' and 'std' bindings */ g.bjson = bjson; g.os = os;