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.

add support for non-function expressions

+85 -10
+1 -1
meson.build
··· 75 75 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 76 76 77 77 version_conf = configuration_data() 78 - version_conf.set('ANT_VERSION', '0.1.3.19') 78 + version_conf.set('ANT_VERSION', '0.1.3.20') 79 79 version_conf.set('ANT_GIT_HASH', git_hash) 80 80 version_conf.set('ANT_BUILD_DATE', build_date) 81 81
+84 -9
src/ant.c
··· 641 641 642 642 static jsval_t call_js(struct js *js, const char *fn, jsoff_t fnlen, jsval_t closure_scope); 643 643 static jsval_t call_js_internal(struct js *js, const char *fn, jsoff_t fnlen, jsval_t closure_scope, jsval_t *bound_args, int bound_argc); 644 + static jsval_t call_js_internal_nfe(struct js *js, const char *fn, jsoff_t fnlen, jsval_t closure_scope, jsval_t *bound_args, int bound_argc, jsval_t func_name, jsval_t func_val); 644 645 static jsval_t call_js_with_args(struct js *js, jsval_t func, jsval_t *args, int nargs); 645 646 static jsval_t call_js_code_with_args(struct js *js, const char *fn, jsoff_t fnlen, jsval_t closure_scope, jsval_t *args, int nargs); 647 + static jsval_t call_js_code_with_args_nfe(struct js *js, const char *fn, jsoff_t fnlen, jsval_t closure_scope, jsval_t *args, int nargs, jsval_t func_name, jsval_t func_val); 646 648 static jsval_t start_async_in_coroutine(struct js *js, const char *code, size_t code_len, jsval_t closure_scope, jsval_t *args, int nargs); 647 649 static inline bool push_this(jsval_t this_value); 648 650 static inline jsval_t pop_this(void); ··· 1619 1621 if (klen == 12 && memcmp(key, "__bound_this", 12) == 0) return true; 1620 1622 if (klen == 12 && memcmp(key, "__bound_args", 12) == 0) return true; 1621 1623 if (klen == 13 && memcmp(key, "__target_func", 13) == 0) return true; 1624 + if (klen == 11 && memcmp(key, "constructor", 11) == 0) return true; 1625 + if (klen == 8 && memcmp(key, "__getter", 8) == 0) return true; 1626 + if (klen == 8 && memcmp(key, "__setter", 8) == 0) return true; 1627 + if (klen == 8 && memcmp(key, "__strict", 8) == 0) return true; 1628 + if (klen == 15 && memcmp(key, "__strict_args__", 15) == 0) return true; 1629 + if (klen == 20 && memcmp(key, "__strict_eval_scope__", 20) == 0) return true; 1630 + if (klen == 19 && memcmp(key, "__primitive_value__", 19) == 0) return true; 1631 + if (klen == 6 && memcmp(key, "__time", 6) == 0) return true; 1632 + if (klen == 5 && memcmp(key, "__map", 5) == 0) return true; 1633 + if (klen == 5 && memcmp(key, "__set", 5) == 0) return true; 1634 + if (klen == 9 && memcmp(key, "__weakmap", 9) == 0) return true; 1635 + if (klen == 9 && memcmp(key, "__weakset", 9) == 0) return true; 1636 + if (klen == 15 && memcmp(key, "__with_object__", 15) == 0) return true; 1637 + if (klen == 18 && memcmp(key, "__esm_module_scope", 18) == 0) return true; 1638 + if (klen == 13 && memcmp(key, "__proxy_ref__", 13) == 0) return true; 1639 + if (klen == 10 && memcmp(key, "__handlers", 10) == 0) return true; 1640 + if (klen == 6 && memcmp(key, "__keys", 6) == 0) return true; 1641 + if (klen == 6 && memcmp(key, "__vals", 6) == 0) return true; 1642 + if (klen == 7 && memcmp(key, "__state", 7) == 0) return true; 1643 + if (klen == 13 && memcmp(key, "__field_count", 13) == 0) return true; 1644 + if (klen == 8 && memcmp(key, "__fields", 8) == 0) return true; 1645 + if (klen == 8 && memcmp(key, "__source", 8) == 0) return true; 1622 1646 return false; 1623 1647 } 1624 1648 ··· 4758 4782 } 4759 4783 4760 4784 static jsval_t call_js_internal(struct js *js, const char *fn, jsoff_t fnlen, jsval_t closure_scope, jsval_t *bound_args, int bound_argc) { 4785 + return call_js_internal_nfe(js, fn, fnlen, closure_scope, bound_args, bound_argc, js_mkundef(), js_mkundef()); 4786 + } 4787 + 4788 + static jsval_t call_js_internal_nfe(struct js *js, const char *fn, jsoff_t fnlen, jsval_t closure_scope, jsval_t *bound_args, int bound_argc, jsval_t func_name, jsval_t func_val) { 4761 4789 jsoff_t fnpos = 1; 4762 4790 jsval_t saved_scope = js->scope; 4763 4791 jsval_t target_this = peek_this(); ··· 4902 4930 size_t n = fnlen - fnpos - 1U; 4903 4931 4904 4932 bool func_strict = is_strict_function_body(&fn[fnpos], n); 4933 + 4934 + if (!func_strict && vtype(func_val) == T_FUNC) { 4935 + jsval_t func_obj = mkval(T_OBJ, vdata(func_val)); 4936 + jsoff_t strict_off = lkp(js, func_obj, "__strict", 8); 4937 + if (strict_off != 0) { 4938 + jsval_t strict_val = resolveprop(js, mkval(T_PROP, strict_off)); 4939 + func_strict = (vtype(strict_val) == T_BOOL && vdata(strict_val) == 1); 4940 + } 4941 + } 4942 + 4905 4943 setup_arguments(js, function_scope, args, argc, func_strict); 4944 + 4945 + if (vtype(func_name) == T_STR && vtype(func_val) == T_FUNC) { 4946 + jsoff_t len; 4947 + (void)vstr(js, func_name, &len); 4948 + if (len > 0) { 4949 + jsval_t prop = mkprop(js, function_scope, func_name, func_val, true); 4950 + (void)prop; 4951 + } 4952 + } 4906 4953 4907 4954 if (func_strict && (vtype(target_this) == T_UNDEF || vtype(target_this) == T_NULL || 4908 4955 (vtype(target_this) == T_OBJ && vdata(target_this) == 0))) { ··· 5032 5079 push_this(bound_this); 5033 5080 } 5034 5081 5035 - jsval_t result = call_js_code_with_args(js, fn, fnlen, closure_scope, args, nargs); 5082 + jsval_t func_name = js_mkundef(); 5083 + jsoff_t name_off = lkp(js, func_obj, "name", 4); 5084 + if (name_off != 0) { 5085 + func_name = resolveprop(js, mkval(T_PROP, name_off)); 5086 + } 5087 + 5088 + jsval_t result = call_js_code_with_args_nfe(js, fn, fnlen, closure_scope, args, nargs, func_name, func); 5036 5089 5037 5090 if (combined_args) ANT_GC_FREE(combined_args); 5038 5091 return result; 5039 5092 } 5040 5093 5041 5094 static jsval_t call_js_code_with_args(struct js *js, const char *fn, jsoff_t fnlen, jsval_t closure_scope, jsval_t *args, int nargs) { 5095 + return call_js_code_with_args_nfe(js, fn, fnlen, closure_scope, args, nargs, js_mkundef(), js_mkundef()); 5096 + } 5097 + 5098 + static jsval_t call_js_code_with_args_nfe(struct js *js, const char *fn, jsoff_t fnlen, jsval_t closure_scope, jsval_t *args, int nargs, jsval_t func_name, jsval_t func_val) { 5042 5099 jsoff_t parent_scope_offset; 5043 5100 if (vtype(closure_scope) == T_OBJ) { 5044 5101 parent_scope_offset = (jsoff_t) vdata(closure_scope); ··· 5051 5108 utarray_push_back(global_scope_stack, &parent_scope_offset); 5052 5109 jsval_t function_scope = mkobj(js, parent_scope_offset); 5053 5110 js->scope = function_scope; 5111 + 5112 + if (vtype(func_name) == T_STR && vtype(func_val) == T_FUNC) { 5113 + jsoff_t len; 5114 + (void)vstr(js, func_name, &len); 5115 + if (len > 0) { 5116 + jsval_t prop = mkprop(js, function_scope, func_name, func_val, true); 5117 + (void)prop; 5118 + } 5119 + } 5054 5120 5055 5121 jsoff_t fnpos = 1; 5056 5122 int arg_idx = 0; ··· 5282 5348 } 5283 5349 } 5284 5350 5351 + jsval_t nfe_name_val = js_mkundef(); 5352 + jsoff_t nfe_name_off = lkp(js, func_obj, "name", 4); 5353 + if (nfe_name_off != 0) { 5354 + nfe_name_val = resolveprop(js, mkval(T_PROP, nfe_name_off)); 5355 + } 5356 + 5285 5357 if (fnlen == 16 && memcmp(code_str, "__builtin_Object", 16) == 0) { 5286 5358 res = call_c(js, builtin_Object); 5287 5359 } else { ··· 5292 5364 const char *func_name = NULL; 5293 5365 const char *this_name = NULL; 5294 5366 5295 - jsoff_t name_off = lkp(js, func_obj, "name", 4); 5296 - if (name_off != 0) { 5297 - jsval_t name_val = resolveprop(js, mkval(T_PROP, name_off)); 5298 - if (vtype(name_val) == T_STR) { 5299 - jsoff_t name_len, name_offset = vstr(js, name_val, &name_len); 5300 - func_name = (const char *)&js->mem[name_offset]; 5301 - } 5367 + if (vtype(nfe_name_val) == T_STR) { 5368 + jsoff_t name_len, name_offset = vstr(js, nfe_name_val, &name_len); 5369 + func_name = (const char *)&js->mem[name_offset]; 5302 5370 } 5303 5371 5304 5372 if (vtype(target_this) != T_OBJ) goto skip_constructor_name; ··· 5405 5473 res = start_async_in_coroutine(js, code_str, fnlen, closure_scope, bound_args, bound_argc); 5406 5474 pop_call_frame(); 5407 5475 } else { 5408 - res = call_js_internal(js, code_str, fnlen, closure_scope, bound_args, bound_argc); 5476 + res = call_js_internal_nfe(js, code_str, fnlen, closure_scope, bound_args, bound_argc, nfe_name_val, func); 5409 5477 pop_call_frame(); 5410 5478 } 5411 5479 ··· 6870 6938 if (is_err(scope_key)) return scope_key; 6871 6939 jsval_t res4 = setprop(js, func_obj, scope_key, js->scope); 6872 6940 if (is_err(res4)) return res4; 6941 + 6942 + if (flags & F_STRICT) { 6943 + jsval_t strict_key = js_mkstr(js, "__strict", 8); 6944 + if (is_err(strict_key)) return strict_key; 6945 + jsval_t res_strict = setprop(js, func_obj, strict_key, js_mktrue()); 6946 + if (is_err(res_strict)) return res_strict; 6947 + } 6873 6948 } 6874 6949 6875 6950 jsval_t func = mkval(T_FUNC, (unsigned long) vdata(func_obj));