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
c4c48bf47b
commit
2cb01b10a4
1 changed files with 18 additions and 18 deletions
36
qjs.c
36
qjs.c
|
@ -138,24 +138,7 @@ static int eval_file(JSContext *ctx, const char *filename, int module)
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
int ret, eval_flags;
|
int ret, eval_flags;
|
||||||
size_t buf_len;
|
size_t buf_len;
|
||||||
|
//POLYFILLS FOR QJS FILES BEGIN
|
||||||
buf = js_load_file(ctx, &buf_len, filename);
|
|
||||||
if (!buf) {
|
|
||||||
perror(filename);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (module < 0) {
|
|
||||||
module = (js__has_suffix(filename, ".mjs") ||
|
|
||||||
JS_DetectModule((const char *)buf, buf_len));
|
|
||||||
}
|
|
||||||
if (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"
|
const char *pf = "globalThis.global = globalThis;\n"
|
||||||
"global.console.error = console.log\n"
|
"global.console.error = console.log\n"
|
||||||
"global.console.warn = console.log\n"
|
"global.console.warn = console.log\n"
|
||||||
|
@ -184,6 +167,23 @@ static int eval_file(JSContext *ctx, const char *filename, int module)
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
eval_buf(ctx, pf, strlen(pf), "<input>", JS_EVAL_TYPE_MODULE);
|
eval_buf(ctx, pf, strlen(pf), "<input>", JS_EVAL_TYPE_MODULE);
|
||||||
|
|
||||||
|
|
||||||
|
buf = js_load_file(ctx, &buf_len, filename);
|
||||||
|
if (!buf) {
|
||||||
|
perror(filename);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (module < 0) {
|
||||||
|
module = (js__has_suffix(filename, ".mjs") ||
|
||||||
|
JS_DetectModule((const char *)buf, buf_len));
|
||||||
|
}
|
||||||
|
if (module)
|
||||||
|
eval_flags = JS_EVAL_TYPE_MODULE;
|
||||||
|
else
|
||||||
|
eval_flags = JS_EVAL_TYPE_GLOBAL;
|
||||||
|
|
||||||
ret = eval_buf(ctx, buf, buf_len, filename, eval_flags);
|
ret = eval_buf(ctx, buf, buf_len, filename, eval_flags);
|
||||||
js_free(ctx, buf);
|
js_free(ctx, buf);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in a new issue