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
ac4cd17bb5
commit
44fa5dbf60
1 changed files with 56 additions and 1 deletions
57
qjs.c
57
qjs.c
|
@ -153,6 +153,34 @@ static int eval_file(JSContext *ctx, const char *filename, int module)
|
|||
eval_flags = JS_EVAL_TYPE_MODULE;
|
||||
else
|
||||
eval_flags = JS_EVAL_TYPE_GLOBAL;
|
||||
|
||||
|
||||
//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 = std.loadScript;\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);
|
||||
ret = eval_buf(ctx, buf, buf_len, filename, eval_flags);
|
||||
js_free(ctx, buf);
|
||||
return ret;
|
||||
|
@ -372,7 +400,7 @@ static const JSMallocFunctions mi_mf = {
|
|||
|
||||
void help(void)
|
||||
{
|
||||
printf("QuickJS-ng version %s\n"
|
||||
printf("QuickJS-ng DoneJS Edition version %s\n"
|
||||
"usage: " PROG_NAME " [options] [file [args]]\n"
|
||||
"-h --help list options\n"
|
||||
"-e --eval EXPR evaluate EXPR\n"
|
||||
|
@ -689,6 +717,33 @@ start:
|
|||
if (interactive) {
|
||||
js_std_eval_binary(ctx, qjsc_repl, qjsc_repl_size, 0);
|
||||
}
|
||||
//POLYFILLS FOR QJS REPL 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 = std.loadScript;\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 (JS_IsException(ret)) {
|
||||
ret = JS_GetException(ctx);
|
||||
|
|
Loading…
Reference in a new issue