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 special object type check for prototypes

+64 -55
+6 -8
src/ant.c
··· 8958 8958 jsval_t obj = mkobj(js, 0); 8959 8959 jsval_t saved_this = js->this_val; 8960 8960 jsval_t saved_new_target = js->new_target; 8961 - js->this_val = obj; 8962 8961 8963 8962 jsval_t ctor = js_group(js); 8964 - if (is_err(ctor)) { js->this_val = saved_this; return ctor; } 8963 + if (is_err(ctor)) { return ctor; } 8965 8964 8966 8965 while (next(js) == TOK_DOT || next(js) == TOK_LBRACKET) { 8967 8966 ctor = resolve_coderef(js, ctor); 8968 - if (is_err(ctor)) { js->this_val = saved_this; return ctor; } 8967 + if (is_err(ctor)) { return ctor; } 8969 8968 8970 8969 if (js->tok == TOK_DOT) { 8971 8970 js->consumed = 1; 8972 8971 if (next(js) != TOK_IDENTIFIER && !is_keyword_propname(js->tok)) { 8973 - js->this_val = saved_this; 8974 8972 return js_mkerr_typed(js, JS_ERR_SYNTAX, "identifier expected"); 8975 8973 } 8976 8974 js->consumed = 1; ··· 8978 8976 } else { 8979 8977 js->consumed = 1; 8980 8978 jsval_t idx = js_expr(js); 8981 - if (is_err(idx)) { js->this_val = saved_this; return idx; } 8982 - if (next(js) != TOK_RBRACKET) { js->this_val = saved_this; return js_mkerr_typed(js, JS_ERR_SYNTAX, "] expected"); } 8979 + if (is_err(idx)) { return idx; } 8980 + if (next(js) != TOK_RBRACKET) { return js_mkerr_typed(js, JS_ERR_SYNTAX, "] expected"); } 8983 8981 js->consumed = 1; 8984 8982 ctor = do_op(js, TOK_BRACKET, ctor, idx); 8985 8983 } 8986 8984 } 8987 8985 8988 8986 ctor = resolve_coderef(js, ctor); 8989 - if (is_err(ctor)) { js->this_val = saved_this; return ctor; } 8987 + if (is_err(ctor)) { return ctor; } 8990 8988 if (vtype(ctor) == T_PROP || vtype(ctor) == T_PROPREF) ctor = resolveprop(js, ctor); 8991 8989 8992 8990 js->new_target = ctor; ··· 8996 8994 if (next(js) == TOK_LPAREN) { 8997 8995 jsval_t params = js_call_params(js); 8998 8996 if (is_err(params)) { 8999 - pop_this(); js->this_val = saved_this; 8997 + pop_this(); 9000 8998 js->new_target = saved_new_target; return params; 9001 8999 } 9002 9000 result = do_op(js, TOK_CALL, ctor, params);
+8 -2
src/errors.c
··· 311 311 js_set(js, err_obj, "message", js_mkstr(js, error_msg, msg_len)); 312 312 js_set_slot(js, err_obj, SLOT_ERR_TYPE, js_mknum((double)err_type)); 313 313 314 - if (vtype(props) == T_OBJ) js_merge_obj(js, err_obj, props); 314 + int props_type = vtype(props); 315 + if ((TYPE_FLAG(props_type) & T_SPECIAL_OBJECT_MASK) != 0) { 316 + js_merge_obj(js, err_obj, props); 317 + } 315 318 jsval_t proto = js_get_ctor_proto(js, err_name, err_name_len); 316 - if (vtype(proto) == T_OBJ) js_set_proto(js, err_obj, proto); 319 + int proto_type = vtype(proto); 320 + if ((TYPE_FLAG(proto_type) & T_SPECIAL_OBJECT_MASK) != 0) { 321 + js_set_proto(js, err_obj, proto); 322 + } 317 323 318 324 js->flags |= F_THROW; 319 325 js->thrown_value = err_obj;
+7 -7
src/modules/buffer.c
··· 198 198 jsval_t obj = js_mkobj(js); 199 199 jsval_t proto = js_get_ctor_proto(js, "ArrayBuffer", 11); 200 200 201 - if (vtype(proto) == T_OBJ) js_set_proto(js, obj, proto); 201 + if (is_special_object(proto)) js_set_proto(js, obj, proto); 202 202 js_set_slot(js, obj, SLOT_BUFFER, ANT_PTR(data)); 203 203 js_set(js, obj, "byteLength", js_mknum((double)length)); 204 204 ··· 235 235 jsval_t new_obj = js_mkobj(js); 236 236 jsval_t proto = js_get_ctor_proto(js, "ArrayBuffer", 11); 237 237 238 - if (vtype(proto) == T_OBJ) js_set_proto(js, new_obj, proto); 238 + if (is_special_object(proto)) js_set_proto(js, new_obj, proto); 239 239 js_set_slot(js, new_obj, SLOT_BUFFER, ANT_PTR(new_data)); 240 240 js_set(js, new_obj, "byteLength", js_mknum((double)new_length)); 241 241 ··· 319 319 static jsval_t create_arraybuffer_obj(struct js *js, ArrayBufferData *buffer) { 320 320 jsval_t ab_obj = js_mkobj(js); 321 321 jsval_t ab_proto = js_get_ctor_proto(js, "ArrayBuffer", 11); 322 - if (vtype(ab_proto) == T_OBJ) js_set_proto(js, ab_obj, ab_proto); 322 + if (is_special_object(ab_proto)) js_set_proto(js, ab_obj, ab_proto); 323 323 324 324 js_set_slot(js, ab_obj, SLOT_BUFFER, js_mknum((double)(uintptr_t)buffer)); 325 325 js_set(js, ab_obj, "byteLength", js_mknum((double)buffer->length)); ··· 345 345 346 346 jsval_t obj = js_mkobj(js); 347 347 jsval_t proto = js_get_ctor_proto(js, type_name, strlen(type_name)); 348 - if (vtype(proto) == T_OBJ) js_set_proto(js, obj, proto); 348 + if (is_special_object(proto)) js_set_proto(js, obj, proto); 349 349 350 350 js_set_slot(js, obj, SLOT_BUFFER, js_mktypedarray(ta_data)); 351 351 js_set(js, obj, "length", js_mknum((double)length)); ··· 802 802 803 803 jsval_t obj = js_mkobj(js); 804 804 jsval_t proto = js_get_ctor_proto(js, "DataView", 8); 805 - if (vtype(proto) == T_OBJ) js_set_proto(js, obj, proto); 805 + if (is_special_object(proto)) js_set_proto(js, obj, proto); 806 806 807 807 js_set_slot(js, obj, SLOT_DATA, ANT_PTR(dv_data)); 808 808 js_mkprop_fast(js, obj, "buffer", 6, args[0]); ··· 1393 1393 // Buffer.isBuffer(obj) 1394 1394 static jsval_t js_buffer_isBuffer(struct js *js, jsval_t *args, int nargs) { 1395 1395 if (nargs < 1) return js_mkfalse(); 1396 - if (vtype(args[0]) != T_OBJ) return js_mkfalse(); 1396 + if (!is_special_object(args[0])) return js_mkfalse(); 1397 1397 1398 1398 jsval_t proto = js_get_proto(js, args[0]); 1399 1399 jsval_t buffer_proto = js_get_ctor_proto(js, "Buffer", 6); ··· 1543 1543 jsval_t obj = js_mkobj(js); 1544 1544 jsval_t proto = js_get_ctor_proto(js, "SharedArrayBuffer", 17); 1545 1545 1546 - if (vtype(proto) == T_OBJ) js_set_proto(js, obj, proto); 1546 + if (is_special_object(proto)) js_set_proto(js, obj, proto); 1547 1547 js_set_slot(js, obj, SLOT_BUFFER, ANT_PTR(data)); 1548 1548 js_set(js, obj, "byteLength", js_mknum((double)length)); 1549 1549
+4 -3
src/modules/fetch.c
··· 271 271 char *body = NULL; 272 272 size_t body_len = 0; 273 273 274 - if (vtype(options_val) == T_OBJ) { 274 + int options_type = vtype(options_val); 275 + if (is_special_object(options_val)) { 275 276 jsval_t method_val = js_get(js, options_val, "method"); 276 277 if (vtype(method_val) == T_STR) { 277 278 char *method_str = js_getstr(js, method_val, NULL); ··· 302 303 snprintf(user_agent, sizeof(user_agent), "ant/%s", ANT_VERSION); 303 304 tlsuv_http_req_header(req->http_req, "User-Agent", user_agent); 304 305 305 - if (vtype(options_val) == T_OBJ) { 306 + if ((TYPE_FLAG(options_type) & T_SPECIAL_OBJECT_MASK) != 0) { 306 307 jsval_t headers_val = js_get(js, options_val, "headers"); 307 - if (vtype(headers_val) == T_OBJ) { 308 + if (is_special_object(headers_val)) { 308 309 ant_iter_t iter = js_prop_iter_begin(js, headers_val); 309 310 const char *key; 310 311 size_t key_len;
+2 -2
src/modules/fs.c
··· 275 275 276 276 jsval_t stat_obj = js_mkobj(req->js); 277 277 jsval_t proto = js_get_ctor_proto(req->js, "Stats", 5); 278 - if (vtype(proto) == T_OBJ) js_set_proto(req->js, stat_obj, proto); 278 + if (is_special_object(proto)) js_set_proto(req->js, stat_obj, proto); 279 279 280 280 uv_stat_t *st = &uv_req->statbuf; 281 281 js_set_slot(req->js, stat_obj, SLOT_DATA, js_mknum((double)st->st_mode)); ··· 967 967 static jsval_t create_stats_object(struct js *js, struct stat *st) { 968 968 jsval_t stat_obj = js_mkobj(js); 969 969 jsval_t proto = js_get_ctor_proto(js, "Stats", 5); 970 - if (vtype(proto) == T_OBJ) js_set_proto(js, stat_obj, proto); 970 + if (is_special_object(proto)) js_set_proto(js, stat_obj, proto); 971 971 972 972 js_set_slot(js, stat_obj, SLOT_DATA, js_mknum((double)st->st_mode)); 973 973 js_set(js, stat_obj, "size", js_mknum((double)st->st_size));
+1 -1
src/modules/navigator.c
··· 249 249 options = args[1]; 250 250 callback = args[2]; 251 251 252 - if (vtype(options) == T_OBJ) { 252 + if (is_special_object(options)) { 253 253 jsval_t mode_val = js_get(js, options, "mode"); 254 254 if (vtype(mode_val) == T_STR) { 255 255 size_t mode_len;
+24 -22
src/modules/observable.c
··· 42 42 (void)args; (void)nargs; 43 43 jsval_t subscription = js_getthis(js); 44 44 45 - if (vtype(subscription) != T_OBJ) return js_mkerr_typed(js, JS_ERR_TYPE, "Subscription.closed getter called on non-object"); 45 + if (!is_special_object(subscription)) { 46 + return js_mkerr_typed(js, JS_ERR_TYPE, "Subscription.closed getter called on non-object"); 47 + } 46 48 return subscription_closed(js, subscription) ? js_mktrue() : js_mkfalse(); 47 49 } 48 50 ··· 50 52 (void)args; (void)nargs; 51 53 jsval_t subscription = js_getthis(js); 52 54 53 - if (vtype(subscription) != T_OBJ) { 55 + if (!is_special_object(subscription)) { 54 56 return js_mkerr_typed(js, JS_ERR_TYPE, "Subscription.unsubscribe called on non-object"); 55 57 } 56 58 ··· 72 74 (void)args; (void)nargs; 73 75 jsval_t O = js_getthis(js); 74 76 75 - if (vtype(O) != T_OBJ) { 77 + if (!is_special_object(O)) { 76 78 return js_mkerr_typed(js, JS_ERR_TYPE, "SubscriptionObserver.closed getter called on non-object"); 77 79 } 78 80 79 81 jsval_t subscription = js_get_slot(js, O, SLOT_DATA); 80 - if (vtype(subscription) != T_OBJ) { 82 + if (!is_special_object(subscription)) { 81 83 return js_mkerr_typed(js, JS_ERR_TYPE, "Invalid SubscriptionObserver"); 82 84 } 83 85 ··· 87 89 static jsval_t js_subobs_next(struct js *js, jsval_t *args, int nargs) { 88 90 jsval_t O = js_getthis(js); 89 91 90 - if (vtype(O) != T_OBJ) { 92 + if (!is_special_object(O)) { 91 93 return js_mkerr_typed(js, JS_ERR_TYPE, "SubscriptionObserver.next called on non-object"); 92 94 } 93 95 94 96 jsval_t subscription = js_get_slot(js, O, SLOT_DATA); 95 - if (vtype(subscription) != T_OBJ) { 97 + if (!is_special_object(subscription)) { 96 98 return js_mkerr_typed(js, JS_ERR_TYPE, "Invalid SubscriptionObserver"); 97 99 } 98 100 99 101 if (subscription_closed(js, subscription)) return js_mkundef(); 100 102 101 103 jsval_t observer = js_get_slot(js, subscription, SLOT_SUBSCRIPTION_OBSERVER); 102 - if (vtype(observer) != T_OBJ) return js_mkundef(); 104 + if (!is_special_object(observer)) return js_mkundef(); 103 105 104 106 jsval_t nextMethod = js_get(js, observer, "next"); 105 107 if (is_callable(nextMethod)) { ··· 115 117 static jsval_t js_subobs_error(struct js *js, jsval_t *args, int nargs) { 116 118 jsval_t O = js_getthis(js); 117 119 118 - if (vtype(O) != T_OBJ) { 120 + if (!is_special_object(O)) { 119 121 return js_mkerr_typed(js, JS_ERR_TYPE, "SubscriptionObserver.error called on non-object"); 120 122 } 121 123 122 124 jsval_t subscription = js_get_slot(js, O, SLOT_DATA); 123 - if (vtype(subscription) != T_OBJ) { 125 + if (!is_special_object(subscription)) { 124 126 return js_mkerr_typed(js, JS_ERR_TYPE, "Invalid SubscriptionObserver"); 125 127 } 126 128 ··· 129 131 jsval_t observer = js_get_slot(js, subscription, SLOT_SUBSCRIPTION_OBSERVER); 130 132 js_set_slot(js, subscription, SLOT_SUBSCRIPTION_OBSERVER, js_mkundef()); 131 133 132 - if (vtype(observer) == T_OBJ) { 134 + if (is_special_object(observer)) { 133 135 jsval_t errorMethod = js_get(js, observer, "error"); 134 136 if (is_callable(errorMethod)) { 135 137 jsval_t exception = (nargs > 0) ? args[0] : js_mkundef(); ··· 147 149 (void)args; (void)nargs; 148 150 jsval_t O = js_getthis(js); 149 151 150 - if (vtype(O) != T_OBJ) { 152 + if (!is_special_object(O)) { 151 153 return js_mkerr_typed(js, JS_ERR_TYPE, "SubscriptionObserver.complete called on non-object"); 152 154 } 153 155 154 156 jsval_t subscription = js_get_slot(js, O, SLOT_DATA); 155 - if (vtype(subscription) != T_OBJ) { 157 + if (!is_special_object(subscription)) { 156 158 return js_mkerr_typed(js, JS_ERR_TYPE, "Invalid SubscriptionObserver"); 157 159 } 158 160 ··· 161 163 jsval_t observer = js_get_slot(js, subscription, SLOT_SUBSCRIPTION_OBSERVER); 162 164 js_set_slot(js, subscription, SLOT_SUBSCRIPTION_OBSERVER, js_mkundef()); 163 165 164 - if (vtype(observer) == T_OBJ) { 166 + if (is_special_object(observer)) { 165 167 jsval_t completeMethod = js_get(js, observer, "complete"); 166 168 if (is_callable(completeMethod)) { 167 169 jsval_t result = js_call_with_this(js, completeMethod, observer, NULL, 0); ··· 193 195 jsval_t F = js_getcurrentfunc(js); 194 196 jsval_t subscription = js_get_slot(js, F, SLOT_DATA); 195 197 196 - if (vtype(subscription) != T_OBJ) return js_mkundef(); 198 + if (!is_special_object(subscription)) return js_mkundef(); 197 199 198 200 jsval_t unsubscribe = js_get(js, subscription, "unsubscribe"); 199 201 if (is_callable(unsubscribe)) { ··· 211 213 if (vtype(subscriberResult) == T_NULL || vtype(subscriberResult) == T_UNDEF) return js_mkundef(); 212 214 if (is_callable(subscriberResult)) return subscriberResult; 213 215 214 - if (vtype(subscriberResult) == T_OBJ) { 216 + if (is_special_object(subscriberResult)) { 215 217 jsval_t result = js_get(js, subscriberResult, "unsubscribe"); 216 218 if (vtype(result) == T_UNDEF) { 217 219 return js_mkerr_typed(js, JS_ERR_TYPE, "Subscriber return value must have an unsubscribe method"); ··· 229 231 static jsval_t js_observable_subscribe(struct js *js, jsval_t *args, int nargs) { 230 232 jsval_t O = js_getthis(js); 231 233 232 - if (vtype(O) != T_OBJ) { 234 + if (!is_special_object(O)) { 233 235 return js_mkerr_typed(js, JS_ERR_TYPE, "Observable.prototype.subscribe called on non-object"); 234 236 } 235 237 ··· 249 251 js_set(js, observer, "next", nextCallback); 250 252 js_set(js, observer, "error", errorCallback); 251 253 js_set(js, observer, "complete", completeCallback); 252 - } else if (nargs > 0 && vtype(args[0]) == T_OBJ) { 254 + } else if (nargs > 0 && is_special_object(args[0])) { 253 255 observer = args[0]; 254 256 } else observer = js_mkobj(js); 255 257 ··· 331 333 js_call_with_this(js, next, observer, next_args, 1); 332 334 } 333 335 334 - if (vtype(subscription) == T_OBJ && subscription_closed(js, subscription)) return js_mkundef(); 336 + if (is_special_object(subscription) && subscription_closed(js, subscription)) return js_mkundef(); 335 337 } 336 338 337 339 jsval_t complete = js_get(js, observer, "complete"); ··· 354 356 jsval_t F = js_getcurrentfunc(js); 355 357 356 358 jsval_t observable = js_get_slot(js, F, SLOT_DATA); 357 - if (vtype(observable) != T_OBJ) return js_mkundef(); 359 + if (!is_special_object(observable)) return js_mkundef(); 358 360 359 361 jsval_t subscribe = js_get(js, observable, "subscribe"); 360 362 if (is_callable(subscribe)) { ··· 381 383 } 382 384 383 385 jsval_t iterator = js_call_with_this(js, iteratorMethod, iterable, NULL, 0); 384 - if (vtype(iterator) != T_OBJ) { 386 + if (!is_special_object(iterator)) { 385 387 return js_mkerr_typed(js, JS_ERR_TYPE, "Iterator must return an object"); 386 388 } 387 389 ··· 408 410 js_call_with_this(js, obs_next, observer, next_args, 1); 409 411 } 410 412 411 - if (vtype(subscription) == T_OBJ && subscription_closed(js, subscription)) { 413 + if (is_special_object(subscription) && subscription_closed(js, subscription)) { 412 414 jsval_t returnMethod = js_get(js, iterator, "return"); 413 415 if (is_callable(returnMethod)) js_call_with_this(js, returnMethod, iterator, NULL, 0); 414 416 return js_mkundef(); ··· 429 431 if (is_callable(observableMethod)) { 430 432 jsval_t observable = js_call_with_this(js, observableMethod, x, NULL, 0); 431 433 432 - if (vtype(observable) != T_OBJ) { 434 + if (!is_special_object(observable)) { 433 435 return js_mkerr_typed(js, JS_ERR_TYPE, "@@observable must return an object"); 434 436 } 435 437
+2 -1
src/modules/os.c
··· 710 710 char idx[16]; 711 711 snprintf(idx, sizeof(idx), "%d", i); 712 712 jsval_t entry = js_get(js, iface_arr, idx); 713 - if (vtype(entry) == T_OBJ) 713 + if (is_special_object(entry)) { 714 714 js_set(js, entry, "mac", js_mkstr(js, mac_str, strlen(mac_str))); 715 + } 715 716 } 716 717 } 717 718
+1 -1
src/modules/path.c
··· 399 399 // path.format(pathObject) 400 400 static jsval_t builtin_path_format(struct js *js, jsval_t *args, int nargs) { 401 401 if (nargs < 1) return js_mkerr(js, "format() requires a path object argument"); 402 - if (vtype(args[0]) != T_OBJ) return js_mkerr(js, "format() argument must be an object"); 402 + if (!is_special_object(args[0])) return js_mkerr(js, "format() argument must be an object"); 403 403 404 404 jsval_t obj = args[0]; 405 405
+3 -3
src/modules/process.c
··· 414 414 if (!rt->js) return; 415 415 416 416 jsval_t process_obj = js_get(rt->js, js_glob(rt->js), "process"); 417 - if (vtype(process_obj) != T_OBJ) return; 417 + if (!is_special_object(process_obj)) return; 418 418 419 419 jsval_t stdout_obj = js_get(rt->js, process_obj, "stdout"); 420 - if (vtype(stdout_obj) != T_OBJ) return; 420 + if (!is_special_object(stdout_obj)) return; 421 421 422 422 int rows = 0, cols = 0; 423 423 get_tty_size(STDOUT_FILENO, &rows, &cols); ··· 760 760 int64_t user_usec = rusage.ru_utime.tv_sec * 1000000LL + rusage.ru_utime.tv_usec; 761 761 int64_t sys_usec = rusage.ru_stime.tv_sec * 1000000LL + rusage.ru_stime.tv_usec; 762 762 763 - if (nargs > 0 && vtype(args[0]) == T_OBJ) { 763 + if (nargs > 0 && is_special_object(args[0])) { 764 764 jsval_t prev_user = js_get(js, args[0], "user"); 765 765 jsval_t prev_system = js_get(js, args[0], "system"); 766 766 if (vtype(prev_user) == T_NUM) user_usec -= (int64_t)js_getnum(prev_user);
+3 -3
src/modules/readline.c
··· 863 863 emit_event(js, iface, "resume", NULL, 0); 864 864 } 865 865 866 - if (nargs >= 2 && vtype(args[1]) == T_OBJ) { 866 + if (nargs >= 2 && is_special_object(args[1])) { 867 867 jsval_t key = args[1]; 868 868 jsval_t name_val = js_get(js, key, "name"); 869 869 jsval_t ctrl_val = js_get(js, key, "ctrl"); ··· 1059 1059 if (nargs < 1) return js_mkerr(js, "createInterface requires options"); 1060 1060 1061 1061 jsval_t options = args[0]; 1062 - if (vtype(options) != T_OBJ) return js_mkerr(js, "options must be an object"); 1062 + if (!is_special_object(options)) return js_mkerr(js, "options must be an object"); 1063 1063 1064 1064 rl_interface_t *iface = calloc(1, sizeof(rl_interface_t)); 1065 1065 if (!iface) return js_mkerr(js, "out of memory"); ··· 1294 1294 js_set(js, lib, get_toStringTag_sym_key(), js_mkstr(js, "readline/promises", 17)); 1295 1295 1296 1296 return lib; 1297 - } 1297 + }
+3 -2
src/modules/reflect.c
··· 143 143 144 144 if (call_args) free(call_args); 145 145 146 - if (vtype(result) == T_OBJ || vtype(result) == T_FUNC) { 146 + int result_type = vtype(result); 147 + if (result_type == T_FUNC || is_special_object(result)) { 147 148 return result; 148 149 } 149 150 return new_obj; ··· 223 224 if (t != T_OBJ && t != T_FUNC) return js_mkfalse(); 224 225 225 226 if (vtype(key) != T_STR) return js_mkfalse(); 226 - if (vtype(descriptor) != T_OBJ) return js_mkfalse(); 227 + if (!is_special_object(descriptor)) return js_mkfalse(); 227 228 228 229 char *key_str = js_getstr(js, key, NULL); 229 230 if (!key_str) return js_mkfalse();