MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

centralize module import context for import.meta and dynamic import

+253 -56
+1
include/common.h
··· 25 25 SLOT_BUFFER, 26 26 SLOT_TARGET_FUNC, 27 27 SLOT_NAME, 28 + SLOT_MODULE_CTX, 28 29 SLOT_MAP, 29 30 SLOT_SET, 30 31 SLOT_PRIMITIVE,
+1 -3
include/esm/loader.h
··· 14 14 15 15 typedef struct ant_module_t { 16 16 ant_value_t module_ns; 17 - ant_value_t import_meta; 17 + ant_value_t module_ctx; 18 18 ant_value_t prev_import_meta_prop; 19 - const char *filename; 20 - const char *parent_path; 21 19 ant_module_format_t format; 22 20 struct ant_module_t *prev; 23 21 } ant_module_t;
+14 -8
include/internal.h
··· 296 296 297 297 ant_value_t js_define_own_prop(ant_t *js, ant_value_t obj, const char *key, size_t klen, ant_value_t v); 298 298 ant_value_t js_create_import_meta(ant_t *js, const char *filename, bool is_main); 299 + ant_value_t js_create_module_context(ant_t *js, const char *filename, bool is_main); 300 + ant_value_t js_get_module_import_binding(ant_t *js); 299 301 ant_value_t js_instance_proto_from_new_target(ant_t *js, ant_value_t fallback_proto); 300 302 301 303 ant_value_t coerce_to_str(ant_t *js, ant_value_t v); ··· 358 360 return ctx ? ctx->module_ns : js_mkundef(); 359 361 } 360 362 361 - static inline ant_value_t js_module_eval_active_import_meta(ant_t *js) { 363 + static inline ant_value_t js_module_eval_active_ctx(ant_t *js) { 362 364 ant_module_t *ctx = js->module; 363 - return ctx ? ctx->import_meta : js_mkundef(); 365 + return ctx ? ctx->module_ctx : js_mkundef(); 364 366 } 365 367 366 - static inline const char *js_module_eval_active_filename(ant_t *js) { 367 - ant_module_t *ctx = js->module; 368 - return ctx ? ctx->filename : js->filename; 368 + static inline ant_value_t js_module_eval_active_import_meta(ant_t *js) { 369 + ant_value_t module_ctx = js_module_eval_active_ctx(js); 370 + return is_object_type(module_ctx) ? js_get(js, module_ctx, "meta") : js_mkundef(); 369 371 } 370 372 371 - static inline const char *js_module_eval_active_parent_path(ant_t *js) { 372 - ant_module_t *ctx = js->module; 373 - return ctx ? ctx->parent_path : NULL; 373 + static inline const char *js_module_eval_active_filename(ant_t *js) { 374 + ant_value_t module_ctx = js_module_eval_active_ctx(js); 375 + if (is_object_type(module_ctx)) { 376 + ant_value_t filename = js_get(js, module_ctx, "filename"); 377 + if (vtype(filename) == T_STR) return js_getstr(js, filename, NULL); 378 + } 379 + return js->filename; 374 380 } 375 381 376 382 static inline ant_module_format_t js_module_eval_active_format(ant_t *js) {
+1 -1
include/silver/opcode.h
··· 229 229 OP_DEF( WITH_PUT_VAR, 8, 1, 0, atom) /* val -> (check with-obj then fallback) */ 230 230 OP_DEF( WITH_DEL_VAR, 5, 0, 1, atom) /* -> bool (delete from with-obj/global) */ 231 231 232 - OP_DEF( SPECIAL_OBJ, 2, 0, 1, u8) /* arguments, mapped args, etc. */ 232 + OP_DEF( SPECIAL_OBJ, 2, 0, 1, u8) /* arguments, new.target, super, module import */ 233 233 OP_DEF( EMPTY, 1, 0, 1, none) /* push T_EMPTY (array hole) */ 234 234 OP_DEF( DEBUGGER, 1, 0, 0, none) 235 235 OP_DEF( NOP, 1, 0, 0, none)
+196 -32
src/ant.c
··· 11239 11239 return filename && filename[0]; 11240 11240 } 11241 11241 11242 + static ant_value_t js_get_import_func(ant_t *js) { 11243 + ant_value_t glob = js_glob(js); 11244 + ant_offset_t import_off = lkp(js, glob, "import", 6); 11245 + if (import_off == 0) return js_mkundef(); 11246 + return propref_load(js, import_off); 11247 + } 11248 + 11249 + static ant_value_t js_get_module_ctx_import_meta(ant_t *js, ant_value_t module_ctx) { 11250 + if (!is_object_type(module_ctx)) return js_mkundef(); 11251 + return js_get(js, module_ctx, "meta"); 11252 + } 11253 + 11254 + static const char *js_get_module_ctx_filename(ant_t *js, ant_value_t module_ctx) { 11255 + if (!is_object_type(module_ctx)) return NULL; 11256 + 11257 + ant_value_t filename = js_get(js, module_ctx, "filename"); 11258 + if (vtype(filename) != T_STR) return NULL; 11259 + return js_getstr(js, filename, NULL); 11260 + } 11261 + 11262 + static ant_value_t js_get_current_module_ctx(ant_t *js) { 11263 + ant_value_t me = js_getcurrentfunc(js); 11264 + if (vtype(me) == T_FUNC) { 11265 + ant_value_t module_ctx = get_slot(me, SLOT_MODULE_CTX); 11266 + if (is_object_type(module_ctx)) return module_ctx; 11267 + } 11268 + 11269 + return js_module_eval_active_ctx(js); 11270 + } 11271 + 11272 + static sv_vm_t *js_get_active_vm(ant_t *js) { 11273 + if (!js) return NULL; 11274 + if (js->active_async_coro && js->active_async_coro->sv_vm) 11275 + return js->active_async_coro->sv_vm; 11276 + return js->vm; 11277 + } 11278 + 11279 + static ant_value_t js_get_caller_module_ctx(ant_t *js) { 11280 + sv_vm_t *vm = js_get_active_vm(js); 11281 + if (!vm || vm->fp < 0) return js_module_eval_active_ctx(js); 11282 + 11283 + for (int i = vm->fp; i >= 0; i--) { 11284 + ant_value_t callee = vm->frames[i].callee; 11285 + if (vtype(callee) != T_FUNC) continue; 11286 + 11287 + ant_value_t module_ctx = get_slot(js_func_obj(callee), SLOT_MODULE_CTX); 11288 + if (is_object_type(module_ctx)) return module_ctx; 11289 + } 11290 + 11291 + return js_module_eval_active_ctx(js); 11292 + } 11293 + 11242 11294 static const char *js_get_current_module_filename(ant_t *js) { 11243 - const char *active = js_module_eval_active_filename(js); 11244 - if (js_has_module_filename(active)) return active; 11295 + const char *filename = js_get_module_ctx_filename(js, js_get_current_module_ctx(js)); 11296 + if (js_has_module_filename(filename)) return filename; 11245 11297 return js->filename; 11246 11298 } 11247 11299 11248 11300 static ant_value_t builtin_import(ant_t *js, ant_value_t *args, int nargs) { 11249 11301 if (nargs < 1) return js_mkerr(js, "import() requires a string specifier"); 11250 - const char *base_path = js_get_current_module_filename(js); 11302 + const char *base_path = NULL; 11303 + 11304 + ant_value_t me = js_getcurrentfunc(js); 11305 + ant_value_t global_import = js_get_import_func(js); 11306 + ant_value_t module_ctx = js_mkundef(); 11307 + 11308 + if (vtype(me) == T_FUNC) { 11309 + module_ctx = (me == global_import) 11310 + ? js_get_caller_module_ctx(js) 11311 + : get_slot(me, SLOT_MODULE_CTX); 11312 + 11313 + if (!is_object_type(module_ctx)) module_ctx = js_get_caller_module_ctx(js); 11314 + base_path = js_get_module_ctx_filename(js, module_ctx); 11315 + } 11316 + 11317 + if (!js_has_module_filename(base_path)) 11318 + base_path = js_get_current_module_filename(js); 11251 11319 11252 11320 ant_value_t tla_promise = js_mkundef(); 11253 11321 ant_value_t ns = js_esm_import_dynamic(js, args[0], base_path, &tla_promise); 11322 + 11254 11323 if (is_err(ns)) return builtin_Promise_reject(js, &ns, 1); 11255 11324 11256 11325 if (vtype(tla_promise) == T_PROMISE) { ··· 11271 11340 } 11272 11341 11273 11342 static ant_value_t js_get_import_meta_prop(ant_t *js) { 11274 - ant_value_t glob = js_glob(js); 11275 - ant_offset_t import_off = lkp(js, glob, "import", 6); 11276 - if (import_off == 0) return js_mkundef(); 11277 - 11278 - ant_value_t import_fn = propref_load(js, import_off); 11343 + ant_value_t import_fn = js_get_import_func(js); 11279 11344 if (vtype(import_fn) != T_FUNC) return js_mkundef(); 11280 11345 return js_get(js, js_func_obj(import_fn), "meta"); 11281 11346 } 11282 11347 11283 11348 static void js_set_import_meta_prop(ant_t *js, ant_value_t import_meta) { 11284 - ant_value_t glob = js_glob(js); 11285 - ant_offset_t import_off = lkp(js, glob, "import", 6); 11286 - if (import_off == 0) return; 11349 + ant_value_t import_fn = js_get_import_func(js); 11350 + if (vtype(import_fn) != T_FUNC) return; 11351 + js_setprop(js, js_func_obj(import_fn), js_mkstr(js, "meta", 4), import_meta); 11352 + } 11287 11353 11288 - ant_value_t import_fn = propref_load(js, import_off); 11354 + static void js_set_import_module_ctx(ant_t *js, ant_value_t module_ctx) { 11355 + if (!is_object_type(module_ctx)) return; 11356 + ant_value_t import_fn = js_get_import_func(js); 11289 11357 if (vtype(import_fn) != T_FUNC) return; 11290 - js_setprop(js, js_func_obj(import_fn), js_mkstr(js, "meta", 4), import_meta); 11358 + js_set_slot_wb(js, js_func_obj(import_fn), SLOT_MODULE_CTX, module_ctx); 11291 11359 } 11292 11360 11293 11361 static ant_value_t js_get_current_import_meta(ant_t *js) { 11294 - ant_value_t import_meta = js_module_eval_active_import_meta(js); 11362 + ant_value_t import_meta = js_get_module_ctx_import_meta(js, js_get_current_module_ctx(js)); 11295 11363 if (vtype(import_meta) == T_OBJ) return import_meta; 11296 11364 return js_get_import_meta_prop(js); 11297 11365 } ··· 11301 11369 11302 11370 const char *base_path = NULL; 11303 11371 ant_value_t import_meta = js_getthis(js); 11372 + ant_value_t module_ctx = js_mkundef(); 11373 + 11374 + if (is_object_type(import_meta)) module_ctx = js_get_slot(import_meta, SLOT_MODULE_CTX); 11304 11375 11305 - if (vtype(import_meta) == T_OBJ) { 11306 - ant_value_t filename = js_get(js, import_meta, "filename"); 11307 - if (vtype(filename) == T_STR) base_path = js_getstr(js, filename, NULL); 11376 + if (!is_object_type(module_ctx)) { 11377 + ant_value_t me = js_getcurrentfunc(js); 11378 + if (vtype(me) == T_FUNC) module_ctx = get_slot(me, SLOT_MODULE_CTX); 11308 11379 } 11309 11380 11381 + base_path = js_get_module_ctx_filename(js, module_ctx); 11310 11382 if (!js_has_module_filename(base_path)) base_path = js_get_current_module_filename(js); 11383 + 11311 11384 return js_esm_resolve_specifier(js, args[0], base_path); 11312 11385 } 11313 11386 ··· 11349 11422 free(filename_copy); 11350 11423 } 11351 11424 11352 - ant_value_t js_create_import_meta(ant_t *js, const char *filename, bool is_main) { 11425 + static ant_value_t js_create_import_meta_for_context( 11426 + ant_t *js, 11427 + ant_value_t module_ctx, 11428 + const char *filename, 11429 + bool is_main 11430 + ) { 11353 11431 if (!filename) return js_mkundef(); 11354 11432 11355 11433 ant_value_t import_meta = mkobj(js, 0); 11356 11434 if (is_err(import_meta)) return import_meta; 11357 - 11435 + 11436 + js_set_slot_wb(js, import_meta, SLOT_MODULE_CTX, module_ctx); 11437 + 11358 11438 bool is_url = esm_is_url(filename); 11359 11439 bool is_builtin = esm_has_builtin_scheme(filename); 11360 11440 11361 11441 ant_value_t url_val = (is_url || is_builtin) 11362 11442 ? js_mkstr(js, filename, strlen(filename)) 11363 11443 : js_esm_make_file_url(js, filename); 11364 - 11365 11444 if (!is_err(url_val)) js_setprop(js, import_meta, js_mkstr(js, "url", 3), url_val); 11366 11445 11367 - ant_value_t filename_val = js_mkstr(js, filename, strlen(filename)); 11368 - if (!is_err(filename_val)) js_setprop(js, import_meta, js_mkstr(js, "filename", 8), filename_val); 11446 + ant_value_t filename_val = js_get(js, module_ctx, "filename"); 11447 + if (vtype(filename_val) == T_STR) 11448 + js_setprop(js, import_meta, js_mkstr(js, "filename", 8), filename_val); 11369 11449 11370 11450 if (is_url || is_builtin) js_set_import_meta_special_dirname(js, import_meta, filename, is_builtin); 11371 11451 else js_set_import_meta_path_dirname(js, import_meta, filename); 11372 11452 11373 11453 js_setprop(js, import_meta, js_mkstr(js, "main", 4), is_main ? js_true : js_false); 11374 - ant_value_t resolve_fn = js_mkfun(builtin_import_meta_resolve); 11454 + 11455 + ant_value_t resolve_fn = js_heavy_mkfun(js, builtin_import_meta_resolve, js_mkundef()); 11456 + if (vtype(resolve_fn) == T_FUNC) 11457 + js_set_slot_wb(js, js_func_obj(resolve_fn), SLOT_MODULE_CTX, module_ctx); 11375 11458 js_setprop(js, import_meta, js_mkstr(js, "resolve", 7), resolve_fn); 11376 - 11459 + 11377 11460 return import_meta; 11378 11461 } 11379 11462 11463 + ant_value_t js_create_module_context(ant_t *js, const char *filename, bool is_main) { 11464 + GC_ROOT_SAVE(root_mark, js); 11465 + if (!js_has_module_filename(filename)) { 11466 + GC_ROOT_RESTORE(js, root_mark); 11467 + return js_mkundef(); 11468 + } 11469 + 11470 + ant_value_t module_ctx = js_mkobj(js); 11471 + if (is_err(module_ctx)) { 11472 + GC_ROOT_RESTORE(js, root_mark); 11473 + return module_ctx; 11474 + } 11475 + GC_ROOT_PIN(js, module_ctx); 11476 + 11477 + ant_value_t filename_val = js_mkstr(js, filename, strlen(filename)); 11478 + if (is_err(filename_val)) { 11479 + GC_ROOT_RESTORE(js, root_mark); 11480 + return filename_val; 11481 + } 11482 + GC_ROOT_PIN(js, filename_val); 11483 + js_setprop(js, module_ctx, js_mkstr(js, "filename", 8), filename_val); 11484 + 11485 + ant_value_t import_meta = js_create_import_meta_for_context(js, module_ctx, filename, is_main); 11486 + if (is_err(import_meta)) { 11487 + GC_ROOT_RESTORE(js, root_mark); 11488 + return import_meta; 11489 + } 11490 + GC_ROOT_PIN(js, import_meta); 11491 + js_setprop(js, module_ctx, js_mkstr(js, "meta", 4), import_meta); 11492 + 11493 + GC_ROOT_RESTORE(js, root_mark); 11494 + return module_ctx; 11495 + } 11496 + 11497 + ant_value_t js_create_import_meta(ant_t *js, const char *filename, bool is_main) { 11498 + ant_value_t module_ctx = js_create_module_context(js, filename, is_main); 11499 + if (is_err(module_ctx)) return module_ctx; 11500 + return js_get_module_ctx_import_meta(js, module_ctx); 11501 + } 11502 + 11503 + ant_value_t js_get_module_import_binding(ant_t *js) { 11504 + GC_ROOT_SAVE(root_mark, js); 11505 + ant_value_t module_ctx = js_module_eval_active_ctx(js); 11506 + ant_value_t import_meta = js_get_module_ctx_import_meta(js, module_ctx); 11507 + GC_ROOT_PIN(js, module_ctx); 11508 + GC_ROOT_PIN(js, import_meta); 11509 + 11510 + if (!is_object_type(module_ctx) || vtype(import_meta) != T_OBJ) { 11511 + GC_ROOT_RESTORE(js, root_mark); 11512 + return js_mkundef(); 11513 + } 11514 + 11515 + ant_value_t import_obj = js_mkobj(js); 11516 + if (is_err(import_obj)) { 11517 + GC_ROOT_RESTORE(js, root_mark); 11518 + return import_obj; 11519 + } 11520 + 11521 + GC_ROOT_PIN(js, import_obj); 11522 + ant_value_t function_proto = js_get_slot(js_glob(js), SLOT_FUNC_PROTO); 11523 + 11524 + if (vtype(function_proto) == T_UNDEF) 11525 + function_proto = js_get_ctor_proto(js, "Function", 8); 11526 + GC_ROOT_PIN(js, function_proto); 11527 + 11528 + if (is_object_type(function_proto)) js_set_proto_wb(js, import_obj, function_proto); 11529 + set_slot(import_obj, SLOT_CFUNC, js_mkfun(builtin_import)); 11530 + js_set_slot_wb(js, import_obj, SLOT_MODULE_CTX, module_ctx); 11531 + js_setprop(js, import_obj, js_mkstr(js, "meta", 4), import_meta); 11532 + 11533 + ant_value_t import_fn = js_obj_to_func(import_obj); 11534 + GC_ROOT_RESTORE(js, root_mark); 11535 + return import_fn; 11536 + } 11537 + 11380 11538 void js_setup_import_meta(ant_t *js, const char *filename) { 11381 11539 if (!filename) return; 11382 11540 11383 - ant_value_t import_meta = js_create_import_meta(js, filename, true); 11384 - if (is_err(import_meta)) return; 11541 + ant_value_t module_ctx = js_create_module_context(js, filename, true); 11542 + ant_value_t import_meta = js_get_module_ctx_import_meta(js, module_ctx); 11543 + if (is_err(import_meta) || vtype(import_meta) == T_UNDEF) return; 11544 + 11545 + js_set_import_module_ctx(js, module_ctx); 11385 11546 js_set_import_meta_prop(js, import_meta); 11386 11547 } 11387 11548 ··· 11392 11553 ctx->prev_import_meta_prop = js_get_import_meta_prop(js); 11393 11554 js->module = ctx; 11394 11555 11395 - if (vtype(ctx->import_meta) != T_UNDEF) 11396 - js_set_import_meta_prop(js, ctx->import_meta); 11556 + ant_value_t import_meta = js_get_module_ctx_import_meta(js, ctx->module_ctx); 11557 + if (vtype(import_meta) != T_UNDEF) js_set_import_meta_prop(js, import_meta); 11397 11558 } 11398 11559 11399 11560 void js_module_eval_ctx_pop(ant_t *js, ant_module_t *ctx) { ··· 12532 12693 if (sv_vm_is_strict(js->vm) && 12533 12694 ((key_len == 6 && memcmp(key, "caller", 6) == 0) || 12534 12695 (key_len == 9 && memcmp(key, "arguments", 9) == 0))) { 12535 - *out = js_mkerr_typed(js, JS_ERR_TYPE, 12536 - "'%.*s' not allowed on functions in strict mode", 12537 - (int)key_len, key); 12696 + *out = js_mkerr_typed( 12697 + js, JS_ERR_TYPE, 12698 + "'%.*s' not allowed on functions in strict mode", 12699 + (int)key_len, key 12700 + ); 12538 12701 return true; 12539 12702 } 12540 12703 12541 12704 ant_value_t func_obj = js_func_obj(obj); 12542 - ant_value_t import_meta = js_get_current_import_meta(js); 12705 + ant_value_t import_meta = js_get_module_ctx_import_meta(js, js_get_slot(func_obj, SLOT_MODULE_CTX)); 12706 + if (vtype(import_meta) == T_UNDEF) import_meta = js_get_current_import_meta(js); 12543 12707 if (key_len == 4 && memcmp(key, "meta", 4) == 0 && vtype(import_meta) != T_UNDEF) { 12544 12708 ant_value_t cfunc = js_get_slot(func_obj, SLOT_CFUNC); 12545 12709 if (vtype(cfunc) == T_CFUNC && js_as_cfunc(cfunc) == builtin_import) {
+3 -6
src/esm/loader.c
··· 196 196 const char *fallback_parent_path, 197 197 ant_module_t *out_ctx 198 198 ) { 199 - ant_module_t *parent_ctx = js->module; 200 - ant_value_t import_meta = js_create_import_meta(js, resolved_path, is_main); 201 - if (is_err(import_meta)) return import_meta; 199 + ant_value_t module_ctx = js_create_module_context(js, resolved_path, is_main); 200 + if (is_err(module_ctx)) return module_ctx; 202 201 203 202 *out_ctx = (ant_module_t){ 204 203 .module_ns = ns, 205 - .import_meta = import_meta, 204 + .module_ctx = module_ctx, 206 205 .prev_import_meta_prop = js_mkundef(), 207 - .filename = resolved_path, 208 - .parent_path = parent_ctx ? parent_ctx->filename : fallback_parent_path, 209 206 .format = format, 210 207 .prev = NULL, 211 208 };
+1 -1
src/gc/objects.c
··· 451 451 452 452 for (ant_module_t *ctx = js->module; ctx; ctx = ctx->prev) { 453 453 gc_mark_value(js, ctx->module_ns); 454 - gc_mark_value(js, ctx->import_meta); 454 + gc_mark_value(js, ctx->module_ctx); 455 455 gc_mark_value(js, ctx->prev_import_meta_prop); 456 456 } 457 457
+1
src/modules/io.c
··· 590 590 [SLOT_BUFFER] = "BUFFER", 591 591 [SLOT_TARGET_FUNC] = "TARGET_FUNC", 592 592 [SLOT_NAME] = "NAME", 593 + [SLOT_MODULE_CTX] = "MODULE_CTX", 593 594 [SLOT_MAP] = "MAP", 594 595 [SLOT_SET] = "SET", 595 596 [SLOT_PRIMITIVE] = "PRIMITIVE",
+22 -5
src/silver/compiler.c
··· 541 541 return c && (c->mode == SV_COMPILE_EVAL || c->mode == SV_COMPILE_REPL); 542 542 } 543 543 544 + static inline bool has_module_import_binding(const sv_compiler_t *c) { 545 + for (const sv_compiler_t *cur = c; cur; cur = cur->enclosing) { 546 + if (cur->mode == SV_COMPILE_MODULE) return true; 547 + } 548 + return false; 549 + } 550 + 544 551 static inline bool has_implicit_arguments_obj(const sv_compiler_t *c) { 545 552 return c && !c->is_arrow && c->enclosing; 546 553 } ··· 1199 1206 } 1200 1207 1201 1208 static void hoist_one_func(sv_compiler_t *c, sv_ast_t *node) { 1202 - sv_func_t *fn = compile_function_body(c, node, SV_COMPILE_SCRIPT); 1209 + sv_func_t *fn = compile_function_body(c, node, c->mode); 1203 1210 if (!fn) return; 1204 1211 int idx = add_constant(c, mkval(T_CFUNC, (uintptr_t)fn)); 1205 1212 emit_op(c, OP_CLOSURE); ··· 1533 1540 1534 1541 case N_IMPORT: 1535 1542 compile_expr(c, node->right); 1536 - emit_op(c, OP_IMPORT); 1543 + if (has_module_import_binding(c)) { 1544 + emit_get_var(c, "import", 6); 1545 + emit_op(c, OP_SWAP); 1546 + emit_op(c, OP_CALL); 1547 + emit_u16(c, 1); 1548 + } else emit_op(c, OP_IMPORT); 1537 1549 break; 1538 1550 1539 1551 case N_REGEXP: ··· 4301 4313 } 4302 4314 4303 4315 free(param_bind_locals); 4316 + if (mode == SV_COMPILE_MODULE && comp.enclosing && !comp.enclosing->enclosing) { 4317 + int import_local = add_local(&comp, "import", 6, true, comp.scope_depth); 4318 + emit_op(&comp, OP_SPECIAL_OBJ); 4319 + emit(&comp, 3); 4320 + emit_put_local(&comp, import_local); 4321 + } 4322 + 4304 4323 if (node->body) { 4305 4324 if (node->body->type == N_BLOCK) { 4306 4325 if (!repl_top) { ··· 4309 4328 hoist_lexical_decls(&comp, &node->body->args); 4310 4329 } 4311 4330 hoist_func_decls(&comp, &node->body->args); 4312 - } else if (!repl_top) { 4313 - hoist_var_decls(&comp, node->body); 4314 - } 4331 + } else if (!repl_top) hoist_var_decls(&comp, node->body); 4315 4332 } 4316 4333 } 4317 4334
+5
src/silver/glue.c
··· 249 249 250 250 ant_value_t func_obj = mkobj(js, 0); 251 251 closure->func_obj = func_obj; 252 + ant_value_t module_ctx = js_module_eval_active_ctx(js); 253 + 252 254 js_mark_constructor(func_obj, !child->is_arrow && !child->is_method); 253 255 js_setprop(js, func_obj, js->length_str, tov((double)child->param_count)); 254 256 js_set_descriptor(js, func_obj, "length", 6, JS_DESC_C); 257 + 258 + if (is_object_type(module_ctx)) 259 + js_set_slot_wb(js, func_obj, SLOT_MODULE_CTX, module_ctx); 255 260 256 261 ant_value_t func_val = mkval(T_FUNC, (uintptr_t)closure); 257 262 if (!child->is_arrow && !child->is_method)
+4
src/silver/ops/coercion.h
··· 253 253 sv_frame_t *frame, uint8_t *ip 254 254 ) { 255 255 uint8_t which = sv_get_u8(ip + 1); 256 + if (which == 3) { 257 + vm->stack[vm->sp++] = js_get_module_import_binding(js); 258 + return; 259 + } 256 260 if (which == 1) { 257 261 vm->stack[vm->sp++] = frame ? frame->new_target : js_mkundef(); 258 262 return;
+4
src/silver/ops/upvalues.h
··· 114 114 115 115 ant_value_t func_obj = mkobj(js, 0); 116 116 closure->func_obj = func_obj; 117 + ant_value_t module_ctx = js_module_eval_active_ctx(js); 117 118 118 119 js_mark_constructor(func_obj, !child->is_arrow && !child->is_method); 119 120 js_setprop(js, func_obj, js->length_str, tov((double)child->param_count)); 120 121 js_set_descriptor(js, func_obj, "length", 6, JS_DESC_C); 122 + 123 + if (is_object_type(module_ctx)) 124 + js_set_slot_wb(js, func_obj, SLOT_MODULE_CTX, module_ctx); 121 125 122 126 if (!child->is_arrow && !child->is_method) sv_setup_function_prototype(js, func_obj, func_val); 123 127 if (child->is_strict) js_set_slot(func_obj, SLOT_STRICT, js_true);