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 error type support to typeof

+22 -3
+1
include/config.h
··· 55 55 SLOT_CTOR, 56 56 SLOT_SUPER, 57 57 SLOT_DEFAULT_CTOR, 58 + SLOT_ERR_TYPE, 58 59 SLOT_MAX = 255 59 60 } internal_slot_t; 60 61
+1
include/config.h.in
··· 44 44 SLOT_CTOR, 45 45 SLOT_SUPER, 46 46 SLOT_DEFAULT_CTOR, 47 + SLOT_ERR_TYPE, 47 48 SLOT_MAX = 255 48 49 } internal_slot_t; 49 50
+20 -3
src/ant.c
··· 2231 2231 } 2232 2232 } 2233 2233 2234 + static inline js_err_type_t get_error_type(struct js *js) { 2235 + if (!(js->flags & F_THROW)) return JS_ERR_GENERIC; 2236 + jsval_t err_type = get_slot(js, js->thrown_value, SLOT_ERR_TYPE); 2237 + if (vtype(err_type) != T_NUM) return JS_ERR_GENERIC; 2238 + return (js_err_type_t)(int)js_getnum(err_type); 2239 + } 2240 + 2234 2241 jsval_t js_mkerr_typed(struct js *js, js_err_type_t err_type, const char *xx, ...) { 2235 2242 va_list ap; 2236 2243 int line = 0, col = 0; ··· 2261 2268 jsval_t err_obj = js_mkobj(js); 2262 2269 js_set(js, err_obj, "name", js_mkstr(js, err_name, err_name_len)); 2263 2270 js_set(js, err_obj, "message", js_mkstr(js, error_msg, msg_len)); 2271 + set_slot(js, err_obj, SLOT_ERR_TYPE, js_mknum((double)err_type)); 2264 2272 2265 2273 jsval_t proto = js_get_ctor_proto(js, err_name, err_name_len); 2266 2274 if (vtype(proto) == T_OBJ) js_set_proto(js, err_obj, proto); ··· 4381 4389 js->consumed = 1; 4382 4390 t = next(js); 4383 4391 while (depth > 0 && t == TOK_RPAREN) { js->consumed = 1; t = next(js); depth--; } 4384 - if (t == TOK_DOT || t == TOK_LBRACKET || t == TOK_LPAREN || t == TOK_OPTIONAL_CHAIN) bare = false; 4392 + if (depth != 0 || t == TOK_DOT || t == TOK_LBRACKET || t == TOK_LPAREN || t == TOK_OPTIONAL_CHAIN) bare = false; 4385 4393 } 4386 4394 4387 4395 js->pos = pos; js->toff = toff; js->tlen = tlen; 4388 4396 js->tok = tok; js->consumed = consumed; js->had_newline = had_newline; 4397 + 4389 4398 return bare; 4390 4399 } 4391 4400 ··· 8906 8915 8907 8916 do_typeof: { 8908 8917 js->consumed = 1; 8918 + jsoff_t saved_pos = js->pos; 8919 + uint8_t saved_tok = js->tok, saved_consumed = js->consumed, saved_flags = js->flags; 8909 8920 bool bare = is_typeof_bare_ident(js); 8910 8921 jsval_t operand = js_unary(js); 8911 - if (is_err(operand) && bare) operand = js_mkundef(); 8912 - else if (is_err(operand)) return operand; 8922 + if (is_err(operand)) { 8923 + if (!bare || get_error_type(js) != JS_ERR_REFERENCE) return operand; 8924 + js->pos = saved_pos; js->tok = saved_tok; js->consumed = saved_consumed; 8925 + js->flags = (saved_flags & ~F_THROW) | F_NOEXEC; 8926 + js_unary(js); 8927 + js->flags = saved_flags & ~F_THROW; 8928 + operand = js_mkundef(); 8929 + } 8913 8930 return do_op(js, TOK_TYPEOF, js_mkundef(), operand); 8914 8931 } 8915 8932