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.

simplify module ctx due to backlink of module_ctx

+21 -30
+21 -30
src/ant.c
··· 11611 11611 return js->vm; 11612 11612 } 11613 11613 11614 - static ant_value_t js_get_func_module_ctx(ant_value_t func) { 11614 + static ant_value_t js_module_ctx_from_func(ant_value_t func) { 11615 11615 if (vtype(func) != T_FUNC) return js_mkundef(); 11616 - 11617 - ant_value_t func_obj = js_func_obj(func); 11618 - ant_value_t cfunc = get_slot(func_obj, SLOT_CFUNC); 11619 - if (vtype(cfunc) == T_CFUNC && js_as_cfunc(cfunc) == js_builtin_import) 11620 - return js_mkundef(); 11621 - 11622 - ant_value_t module_ctx = get_slot(func_obj, SLOT_MODULE_CTX); 11616 + ant_value_t module_ctx = get_slot(js_func_obj(func), SLOT_MODULE_CTX); 11623 11617 return is_object_type(module_ctx) ? module_ctx : js_mkundef(); 11624 11618 } 11625 11619 11626 - static ant_value_t js_get_active_frame_module_ctx(ant_t *js) { 11620 + static ant_value_t js_get_execution_module_ctx(ant_t *js) { 11627 11621 sv_vm_t *vm = js_get_active_vm(js); 11628 - if (!vm || vm->fp < 0) return js_mkundef(); 11629 - return js_get_func_module_ctx(vm->frames[vm->fp].callee); 11622 + if (vm && vm->fp >= 0) { 11623 + ant_value_t module_ctx = js_module_ctx_from_func(vm->frames[vm->fp].callee); 11624 + if (is_object_type(module_ctx)) return module_ctx; 11625 + } 11626 + 11627 + return js_module_eval_active_ctx(js); 11630 11628 } 11631 11629 11632 - static ant_value_t js_get_active_script_or_module_ctx(ant_t *js) { 11633 - ant_value_t module_ctx = js_get_func_module_ctx(js_getcurrentfunc(js)); 11630 + static ant_value_t js_get_import_owner_module_ctx(ant_t *js) { 11631 + ant_value_t module_ctx = js_module_ctx_from_func(js_getcurrentfunc(js)); 11634 11632 if (is_object_type(module_ctx)) return module_ctx; 11635 - 11636 - module_ctx = js_get_active_frame_module_ctx(js); 11637 - if (is_object_type(module_ctx)) return module_ctx; 11638 - 11639 - return js_module_eval_active_ctx(js); 11633 + return js_get_execution_module_ctx(js); 11640 11634 } 11641 11635 11642 - static const char *js_get_current_execution_owner_filename(ant_t *js) { 11643 - const char *filename = js_get_module_ctx_filename( 11644 - js, 11645 - js_get_active_script_or_module_ctx(js) 11646 - ); 11636 + static const char *js_get_execution_module_filename(ant_t *js) { 11637 + const char *filename = js_get_module_ctx_filename(js, js_get_execution_module_ctx(js)); 11647 11638 if (js_has_module_filename(filename)) return filename; 11648 11639 return js->filename; 11649 11640 } ··· 11651 11642 ant_value_t js_builtin_import(ant_t *js, ant_value_t *args, int nargs) { 11652 11643 if (nargs < 1) return js_mkerr(js, "import() requires a string specifier"); 11653 11644 11654 - ant_value_t module_ctx = js_get_active_script_or_module_ctx(js); 11645 + ant_value_t module_ctx = js_get_import_owner_module_ctx(js); 11655 11646 const char *base_path = js_get_module_ctx_filename(js, module_ctx); 11656 11647 11657 11648 if (!js_has_module_filename(base_path)) 11658 - base_path = js_get_current_execution_owner_filename(js); 11659 - 11649 + base_path = js_get_execution_module_filename(js); 11650 + 11660 11651 ant_value_t tla_promise = js_mkundef(); 11661 11652 ant_value_t ns = js_esm_import_dynamic(js, args[0], base_path, &tla_promise); 11662 11653 ··· 11701 11692 static ant_value_t js_get_current_import_meta(ant_t *js) { 11702 11693 ant_value_t import_meta = js_get_module_ctx_import_meta( 11703 11694 js, 11704 - js_get_active_script_or_module_ctx(js) 11695 + js_get_execution_module_ctx(js) 11705 11696 ); 11706 11697 if (vtype(import_meta) == T_OBJ) return import_meta; 11707 11698 return js_get_import_meta_prop(js); ··· 11717 11708 if (is_object_type(import_meta)) module_ctx = js_get_slot(import_meta, SLOT_MODULE_CTX); 11718 11709 11719 11710 if (!is_object_type(module_ctx)) 11720 - module_ctx = js_get_active_script_or_module_ctx(js); 11711 + module_ctx = js_get_import_owner_module_ctx(js); 11721 11712 11722 11713 base_path = js_get_module_ctx_filename(js, module_ctx); 11723 11714 if (!js_has_module_filename(base_path)) 11724 - base_path = js_get_current_execution_owner_filename(js); 11715 + base_path = js_get_execution_module_filename(js); 11725 11716 11726 11717 return js_esm_resolve_specifier(js, args[0], base_path); 11727 11718 } ··· 11845 11836 ant_value_t js_get_module_import_binding(ant_t *js) { 11846 11837 GC_ROOT_SAVE(root_mark, js); 11847 11838 11848 - ant_value_t module_ctx = js_get_active_script_or_module_ctx(js); 11839 + ant_value_t module_ctx = js_get_execution_module_ctx(js); 11849 11840 ant_value_t import_meta = js_get_module_ctx_import_meta(js, module_ctx); 11850 11841 11851 11842 GC_ROOT_PIN(js, module_ctx);