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.

improve symbol primitives

+27 -5
+3 -3
examples/results.txt
··· 679 679 compat-table/es6/String.prototype.startsWith.js: OK 680 680 compat-table/es6/String.prototype.startsWith.throws-regex.js: OK 681 681 compat-table/es6/String.raw.js: OK 682 - compat-table/es6/Symbol.JSON.stringify.object.js: TypeError: Object.defineProperty called on non-object 682 + compat-table/es6/Symbol.JSON.stringify.object.js: OK 683 683 compat-table/es6/Symbol.JSON.stringify.primitive.js: OK 684 - compat-table/es6/Symbol.Object.js: failed 684 + compat-table/es6/Symbol.Object.js: OK 685 685 compat-table/es6/Symbol.String.js: OK 686 686 compat-table/es6/Symbol.defineProperty.js: OK 687 687 compat-table/es6/Symbol.global-registry.js: OK 688 688 compat-table/es6/Symbol.hidden-keys.js: OK 689 689 compat-table/es6/Symbol.js: OK 690 - compat-table/es6/Symbol.no-coerce.js: failed 690 + compat-table/es6/Symbol.no-coerce.js: OK 691 691 compat-table/es6/Symbol.no-new.js: OK 692 692 compat-table/es6/Symbol.prototype.js: OK 693 693 compat-table/es6/Symbol.typeof.js: OK
+2 -2
src/ant.c
··· 4583 4583 if (js_try_get_string_index(js, obj, key, key_len, &indexed)) return indexed; 4584 4584 } 4585 4585 4586 - if (t == T_STR || t == T_NUM || t == T_BOOL || t == T_BIGINT) { 4586 + if (t == T_STR || t == T_NUM || t == T_BOOL || t == T_BIGINT || t == T_SYMBOL) { 4587 4587 ant_offset_t off = lkp_proto(js, obj, key, key_len); 4588 4588 if (off != 0) return propref_load(js, off); 4589 4589 return js_mkundef(); ··· 5330 5330 uint8_t t = vtype(arg); 5331 5331 5332 5332 if (t == T_OBJ || t == T_ARR || t == T_FUNC) return arg; 5333 - if (t == T_STR || t == T_NUM || t == T_BOOL || t == T_BIGINT) { 5333 + if (t == T_STR || t == T_NUM || t == T_BOOL || t == T_BIGINT || t == T_SYMBOL) { 5334 5334 ant_value_t wrapper = js_mkobj(js); 5335 5335 if (is_err(wrapper)) return wrapper; 5336 5336 set_slot(wrapper, SLOT_PRIMITIVE, arg);
+19
src/modules/symbol.c
··· 57 57 static ant_value_t builtin_Symbol_toString(ant_t *js, ant_value_t *args, int nargs) { 58 58 ant_value_t this_val = js_getthis(js); 59 59 60 + if (vtype(this_val) != T_SYMBOL && is_object_type(this_val)) { 61 + ant_value_t prim = js_get_slot(this_val, SLOT_PRIMITIVE); 62 + if (vtype(prim) == T_SYMBOL) this_val = prim; 63 + } 64 + 60 65 if (vtype(this_val) != T_SYMBOL) { 61 66 return js_mkerr(js, "Symbol.prototype.toString requires a symbol"); 62 67 } 63 68 64 69 return js_symbol_to_string(js, this_val); 70 + } 71 + 72 + static ant_value_t builtin_Symbol_valueOf(ant_t *js, ant_value_t *args, int nargs) { 73 + ant_value_t this_val = js_getthis(js); 74 + 75 + if (vtype(this_val) != T_SYMBOL && is_object_type(this_val)) { 76 + ant_value_t prim = js_get_slot(this_val, SLOT_PRIMITIVE); 77 + if (vtype(prim) == T_SYMBOL) return prim; 78 + } 79 + 80 + if (vtype(this_val) == T_SYMBOL) return this_val; 81 + return js_mkerr_typed(js, JS_ERR_TYPE, "Symbol.prototype.valueOf requires a symbol"); 65 82 } 66 83 67 84 static ant_value_t builtin_Symbol_description(ant_t *js, ant_value_t *args, int nargs) { ··· 324 341 325 342 if (is_object_type(object_proto)) js_set_proto_init(symbol_proto, object_proto); 326 343 js_set(js, symbol_proto, "toString", js_mkfun(builtin_Symbol_toString)); 344 + js_set(js, symbol_proto, "valueOf", js_mkfun(builtin_Symbol_valueOf)); 345 + js_set_sym(js, symbol_proto, get_toPrimitive_sym(), js_mkfun(builtin_Symbol_valueOf)); 327 346 js_set_getter_desc(js, symbol_proto, "description", 11, js_mkfun(builtin_Symbol_description), JS_DESC_C); 328 347 329 348 ant_value_t symbol_ctor = js_mkobj(js);
+3
src/silver/ops/arithmetic.h
··· 25 25 if (vtype(lu) == T_BIGINT || vtype(ru) == T_BIGINT) { 26 26 return js_mkerr(js, "Cannot mix BigInt value and other types"); 27 27 } 28 + if (vtype(lu) == T_SYMBOL || vtype(ru) == T_SYMBOL) { 29 + return js_mkerr_typed(js, JS_ERR_TYPE, "Cannot convert a Symbol value"); 30 + } 28 31 if (is_non_numeric(lu) || is_non_numeric(ru)) { 29 32 ant_value_t l_str = coerce_to_str_concat(js, l); 30 33 if (is_err(l_str)) return l_str;