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.

disable generators

+11 -75
examples/spec/generators.js examples/spec/generators.js.disabled
+1 -1
meson.build
··· 74 74 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 75 75 76 76 version_conf = configuration_data() 77 - version_conf.set('ANT_VERSION', '0.1.1.14') 77 + version_conf.set('ANT_VERSION', '0.1.1.15') 78 78 version_conf.set('ANT_GIT_HASH', git_hash) 79 79 version_conf.set('ANT_BUILD_DATE', build_date) 80 80
+10 -74
src/ant.c
··· 15999 15999 return res; 16000 16000 } 16001 16001 16002 - jsval_t js_call(struct js *js, jsval_t func, jsval_t *args, int nargs) { 16002 + static jsval_t js_call_internal(struct js *js, jsval_t func, jsval_t bound_this, jsval_t *args, int nargs, bool use_bound_this) { 16003 16003 if (vtype(func) == T_CFUNC) { 16004 16004 jsval_t (*fn)(struct js *, jsval_t *, int) = (jsval_t(*)(struct js *, jsval_t *, int)) vdata(func); 16005 16005 return fn(js, args, nargs); ··· 16010 16010 jsval_t native_val = resolveprop(js, mkval(T_PROP, native_off)); 16011 16011 if (vtype(native_val) == T_CFUNC) { 16012 16012 jsval_t saved_func = js->current_func; 16013 + jsval_t saved_this = js->this_val; 16013 16014 js->current_func = func; 16015 + if (use_bound_this) js->this_val = bound_this; 16014 16016 jsval_t (*fn)(struct js *, jsval_t *, int) = (jsval_t(*)(struct js *, jsval_t *, int)) vdata(native_val); 16015 16017 jsval_t res = fn(js, args, nargs); 16016 16018 js->current_func = saved_func; 16019 + js->this_val = saved_this; 16017 16020 return res; 16018 16021 } 16019 16022 } ··· 16117 16120 size_t body_len = fnlen - fnpos - 1; 16118 16121 16119 16122 jsval_t saved_this = js->this_val; 16120 - js->this_val = js_glob(js); 16123 + js->this_val = use_bound_this ? bound_this : js_glob(js); 16121 16124 16122 16125 js->flags = F_CALL; 16123 16126 jsval_t res = js_eval(js, &fn[fnpos], body_len); ··· 16132 16135 return js_mkerr(js, "not a function"); 16133 16136 } 16134 16137 16138 + jsval_t js_call(struct js *js, jsval_t func, jsval_t *args, int nargs) { 16139 + return js_call_internal(js, func, js_mkundef(), args, nargs, false); 16140 + } 16141 + 16135 16142 jsval_t js_call_with_this(struct js *js, jsval_t func, jsval_t bound_this, jsval_t *args, int nargs) { 16136 - if (vtype(func) == T_CFUNC) { 16137 - jsval_t (*fn)(struct js *, jsval_t *, int) = (jsval_t(*)(struct js *, jsval_t *, int)) vdata(func); 16138 - return fn(js, args, nargs); 16139 - } else if (vtype(func) == T_FUNC) { 16140 - jsval_t func_obj = mkval(T_OBJ, vdata(func)); 16141 - jsoff_t native_off = lkp(js, func_obj, "__native_func", 13); 16142 - if (native_off != 0) { 16143 - jsval_t native_val = resolveprop(js, mkval(T_PROP, native_off)); 16144 - if (vtype(native_val) == T_CFUNC) { 16145 - jsval_t saved_func = js->current_func; 16146 - jsval_t saved_this = js->this_val; 16147 - js->current_func = func; 16148 - js->this_val = bound_this; 16149 - jsval_t (*fn)(struct js *, jsval_t *, int) = (jsval_t(*)(struct js *, jsval_t *, int)) vdata(native_val); 16150 - jsval_t res = fn(js, args, nargs); 16151 - js->current_func = saved_func; 16152 - js->this_val = saved_this; 16153 - return res; 16154 - } 16155 - } 16156 - jsoff_t code_off = lkp(js, func_obj, "__code", 6); 16157 - if (code_off == 0) return js_mkerr(js, "function has no code"); 16158 - jsval_t code_val = resolveprop(js, mkval(T_PROP, code_off)); 16159 - if (vtype(code_val) != T_STR) return js_mkerr(js, "function code not string"); 16160 - jsoff_t fnlen, fnoff = vstr(js, code_val, &fnlen); 16161 - const char *fn = (const char *) (&js->mem[fnoff]); 16162 - 16163 - jsoff_t fnpos = 1; 16164 - jsval_t saved_scope = js->scope; 16165 - jsoff_t scope_off = lkp(js, func_obj, "__scope", 7); 16166 - if (scope_off != 0) { 16167 - jsval_t closure_scope = resolveprop(js, mkval(T_PROP, scope_off)); 16168 - if (vtype(closure_scope) == T_OBJ) js->scope = closure_scope; 16169 - } 16170 - 16171 - uint8_t saved_flags = js->flags; 16172 - js->flags = 0; 16173 - mkscope(js); 16174 - js->flags = saved_flags; 16175 - int arg_idx = 0; 16176 - 16177 - while (fnpos < fnlen) { 16178 - fnpos = skiptonext(fn, fnlen, fnpos, NULL); 16179 - if (fnpos < fnlen && fn[fnpos] == ')') break; 16180 - jsoff_t identlen = 0; 16181 - uint8_t tok = parseident(&fn[fnpos], fnlen - fnpos, &identlen); 16182 - if (tok != TOK_IDENTIFIER) break; 16183 - jsval_t v = arg_idx < nargs ? args[arg_idx] : js_mkundef(); 16184 - setprop(js, js->scope, js_mkstr(js, &fn[fnpos], identlen), v); 16185 - arg_idx++; 16186 - fnpos = skiptonext(fn, fnlen, fnpos + identlen, NULL); 16187 - if (fnpos < fnlen && fn[fnpos] == ',') fnpos++; 16188 - } 16189 - 16190 - if (fnpos < fnlen && fn[fnpos] == ')') fnpos++; 16191 - fnpos = skiptonext(fn, fnlen, fnpos, NULL); 16192 - if (fnpos < fnlen && fn[fnpos] == '{') fnpos++; 16193 - size_t body_len = fnlen - fnpos - 1; 16194 - 16195 - jsval_t saved_this = js->this_val; 16196 - js->this_val = bound_this; 16197 - 16198 - js->flags = F_CALL; 16199 - jsval_t res = js_eval(js, &fn[fnpos], body_len); 16200 - if (!is_err(res) && !(js->flags & F_RETURN)) res = js_mkundef(); 16201 - 16202 - js->this_val = saved_this; 16203 - delscope(js); 16204 - js->scope = saved_scope; 16205 - return res; 16206 - } 16207 - return js_mkerr(js, "not a function"); 16143 + return js_call_internal(js, func, bound_this, args, nargs, true); 16208 16144 } 16209 16145 16210 16146 js_prop_iter_t js_prop_iter_begin(struct js *js, jsval_t obj) {