mirror of
https://github.com/DoneJS-Runtime/quickjs-done-nextgen.git
synced 2025-01-09 17:43:15 +00:00
Update qjs.c
This commit is contained in:
parent
71134f6280
commit
b72e49aef9
1 changed files with 28 additions and 29 deletions
57
qjs.c
57
qjs.c
|
@ -57,35 +57,6 @@ static const int trailer_size = TRAILER_SIZE;
|
||||||
static int qjs__argc;
|
static int qjs__argc;
|
||||||
static char **qjs__argv;
|
static char **qjs__argv;
|
||||||
|
|
||||||
// POLYFILLS
|
|
||||||
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";
|
|
||||||
|
|
||||||
|
|
||||||
static BOOL is_standalone(const char *exe)
|
static BOOL is_standalone(const char *exe)
|
||||||
{
|
{
|
||||||
FILE *exe_f = fopen(exe, "rb");
|
FILE *exe_f = fopen(exe, "rb");
|
||||||
|
@ -652,6 +623,34 @@ start:
|
||||||
if (!empty_run) {
|
if (!empty_run) {
|
||||||
js_std_add_helpers(ctx, argc - optind, argv + optind);
|
js_std_add_helpers(ctx, argc - optind, argv + optind);
|
||||||
|
|
||||||
|
// POLYFILLS
|
||||||
|
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";
|
||||||
|
|
||||||
/* make 'std' and 'os' visible to non module code */
|
/* make 'std' and 'os' visible to non module code */
|
||||||
if (load_std) {
|
if (load_std) {
|
||||||
const char *str =
|
const char *str =
|
||||||
|
|
Loading…
Reference in a new issue