fix require polyfill

This commit is contained in:
The Ghost of FOSS' Past 2024-10-24 15:04:42 -05:00
parent 18c24ca20e
commit 6930c1ef9d
2 changed files with 11 additions and 4 deletions

6
.gitignore vendored
View file

@ -5,6 +5,12 @@ examples/*.so
microbench*.txt microbench*.txt
qjs qjs
qjsc qjsc
qjscalc
qjscalc.c
hello.c
hello
hello_module
repl.c
run-test262 run-test262
test262 test262
test262_*.txt test262_*.txt

9
qjs.c
View file

@ -494,11 +494,12 @@ int main(int argc, char **argv)
"globalThis.os = os;\n"; "globalThis.os = os;\n";
eval_buf(ctx, str, strlen(str), "<input>", JS_EVAL_TYPE_MODULE); eval_buf(ctx, str, strlen(str), "<input>", JS_EVAL_TYPE_MODULE);
} }
//POLYFILLS BEGIN //POLYFILLS BEGIN
const char *reqPF = "function require(x) { \n" const char *reqPF = "async function require(x) { {\n"
" import { y } from `String(x)` \n" " const y = await import(x);" // use dynamic import.
" return y \n" " return y;\n"
"}"; "}\n";
eval_buf(ctx, reqPF, strlen(reqPF), "<input>", JS_EVAL_TYPE_MODULE); eval_buf(ctx, reqPF, strlen(reqPF), "<input>", JS_EVAL_TYPE_MODULE);
for(i = 0; i < include_count; i++) { for(i = 0; i < include_count; i++) {