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.

lkp-based default lookups with js_get_slot for speed

+40 -18
+1
include/common.h
··· 43 43 SLOT_CTOR, 44 44 SLOT_SUPER, 45 45 SLOT_DEFAULT_CTOR, 46 + SLOT_DEFAULT, 46 47 SLOT_ERR_TYPE, 47 48 SLOT_OBSERVABLE_SUBSCRIBER, 48 49 SLOT_SUBSCRIPTION_OBSERVER,
+23 -18
src/ant.c
··· 3671 3671 return result; 3672 3672 } 3673 3673 3674 - static jsval_t setprop(struct js *js, jsval_t obj, jsval_t k, jsval_t v) { 3674 + static inline jsval_t setprop(struct js *js, jsval_t obj, jsval_t k, jsval_t v) { 3675 3675 return js_setprop(js, obj, k, v); 3676 3676 } 3677 3677 3678 - static inline jsval_t setprop_fast(struct js *js, jsval_t obj, const char *key, size_t len, jsval_t v) { 3678 + static inline jsval_t setprop_cstr(struct js *js, jsval_t obj, const char *key, size_t len, jsval_t v) { 3679 3679 jsval_t k = js_mkstr(js, key, len); 3680 3680 if (is_err(k)) return k; 3681 3681 return mkprop(js, obj, k, v, 0); ··· 3708 3708 return mkval(T_SYMBOL, payload); 3709 3709 } 3710 3710 3711 - static uint64_t sym_get_id(jsval_t v) { 3711 + static inline uint64_t sym_get_id(jsval_t v) { 3712 3712 return (vdata(v) >> 24) & PROPREF_PAYLOAD; 3713 3713 } 3714 3714 3715 - static jsoff_t sym_get_desc_off(jsval_t v) { 3715 + static inline jsoff_t sym_get_desc_off(jsval_t v) { 3716 3716 return vdata(v) & PROPREF_PAYLOAD; 3717 3717 } 3718 3718 ··· 3722 3722 return (const char *)&js->mem[off + sizeof(jsoff_t)]; 3723 3723 } 3724 3724 3725 - uint64_t js_sym_id(jsval_t sym) { 3725 + uint64_t inline js_sym_id(jsval_t sym) { 3726 3726 return sym_get_id(sym); 3727 3727 } 3728 3728 ··· 3740 3740 return (const char *)(uintptr_t)(data & ~(1ULL << 47)); 3741 3741 } 3742 3742 3743 - const char *js_sym_desc(struct js *js, jsval_t sym) { 3743 + const inline char *js_sym_desc(struct js *js, jsval_t sym) { 3744 3744 return sym_get_desc(js, sym); 3745 3745 } 3746 3746 ··· 3973 3973 return len == n && !memcmp(buf, s, n); 3974 3974 } 3975 3975 3976 - static bool is_strict_restricted(const char *buf, size_t len) { 3977 - return streq(buf, len, "eval", 4) || streq(buf, len, "arguments", 9); 3976 + static inline bool is_strict_restricted(const char *buf, size_t len) { 3977 + if (len == 4) return streq(buf, len, "eval", 4); 3978 + if (len == 9) return streq(buf, len, "arguments", 9); 3979 + return false; 3978 3980 } 3979 3981 3980 3982 static int encode_utf8(uint32_t cp, char *out) { ··· 13210 13212 const char *str = js_str(js, msg); 13211 13213 msg = js_mkstr(js, str, strlen(str)); 13212 13214 } 13213 - setprop_fast(js, this_val, "message", 7, msg); 13215 + js_mkprop_fast(js, this_val, "message", 7, msg); 13214 13216 } 13215 13217 13216 - setprop_fast(js, this_val, "name", 4, name); 13218 + js_mkprop_fast(js, this_val, "name", 4, name); 13217 13219 return this_val; 13218 13220 } 13219 13221 ··· 13230 13232 13231 13233 jsval_t errors = nargs > 0 ? args[0] : mkarr(js); 13232 13234 if (vtype(errors) != T_ARR) errors = mkarr(js); 13233 - setprop_fast(js, this_val, "errors", 6, errors); 13235 + js_mkprop_fast(js, this_val, "errors", 6, errors); 13234 13236 13235 13237 if (nargs > 1 && vtype(args[1]) != T_UNDEF) { 13236 13238 jsval_t msg = args[1]; ··· 13238 13240 const char *str = js_str(js, msg); 13239 13241 msg = js_mkstr(js, str, strlen(str)); 13240 13242 } 13241 - setprop_fast(js, this_val, "message", 7, msg); 13243 + js_mkprop_fast(js, this_val, "message", 7, msg); 13242 13244 } 13243 13245 13244 - setprop_fast(js, this_val, "name", 4, ANT_STRING("AggregateError")); 13246 + js_mkprop_fast(js, this_val, "name", 4, ANT_STRING("AggregateError")); 13245 13247 return this_val; 13246 13248 } 13247 13249 ··· 20382 20384 return result; 20383 20385 } 20384 20386 20385 - jsoff_t default_off = lkp(js, ns, "default", 7); 20386 - mod->default_export = default_off != 0 ? resolveprop(js, mkval(T_PROP, default_off)) : ns; 20387 + jsval_t default_val = js_get_slot(js, ns, SLOT_DEFAULT); 20388 + mod->default_export = js_type(default_val) != JS_UNDEF ? default_val : ns; 20387 20389 20388 20390 mod->is_loaded = true; 20389 20391 mod->is_loading = false; ··· 20666 20668 20667 20669 jsval_t default_val; 20668 20670 if (vtype(ns) == T_OBJ) { 20669 - jsoff_t default_off = lkp(js, ns, "default", 7); 20670 - default_val = default_off != 0 ? resolveprop(js, mkval(T_PROP, default_off)) : ns; 20671 + jsval_t slot_val = js_get_slot(js, ns, SLOT_DEFAULT); 20672 + default_val = js_type(slot_val) != JS_UNDEF ? slot_val : ns; 20671 20673 } else default_val = ns; 20672 20674 setprop(js, js->scope, js_mkstr(js, default_name, default_len), default_val); 20673 20675 ··· 20750 20752 jsval_t value = js_assignment(js); 20751 20753 if (is_err(value)) return value; 20752 20754 20753 - setprop(js, js->module_ns, js_mkstr(js, "default", 7), resolveprop(js, value)); 20755 + jsval_t resolved = resolveprop(js, value); 20756 + js_set_slot(js, js->module_ns, SLOT_DEFAULT, resolved); 20757 + js_mkprop_fast(js, js->module_ns, "default", 7, resolved); 20758 + 20754 20759 return value; 20755 20760 } 20756 20761
+3
tests/export-default-module.js
··· 1 + export default function greet(name) { 2 + return `Hello, ${name}!`; 3 + }
+3
tests/export-default-static.js
··· 1 + import greet from './export-default-module.js'; 2 + 3 + console.log(greet('world'));
+10
tests/export-default-test.js
··· 1 + async function main() { 2 + const mod = await import('./export-default-module.js'); 3 + console.log('module:', mod); 4 + console.log('default:', mod.default); 5 + if (typeof mod.default === 'function') { 6 + console.log(mod.default('world')); 7 + } 8 + } 9 + 10 + void main();