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.

migrate to Symbol.toStringTag

+102 -76
+17
examples/spec/modules.js
··· 1 1 import { test, summary } from './helpers.js'; 2 2 3 + import * as path from 'ant:path'; 4 + import * as fs from 'ant:fs'; 5 + import * as shell from 'ant:shell'; 6 + import * as ffi from 'ant:ffi'; 7 + 3 8 console.log('Module Tests\n'); 4 9 5 10 test('import.meta exists', typeof import.meta, 'object'); ··· 8 13 9 14 test('module imported test', typeof test, 'function'); 10 15 test('module imported summary', typeof summary, 'function'); 16 + 17 + test('Atomics toStringTag', Object.prototype.toString.call(Atomics), '[object Atomics]'); 18 + test('console toStringTag', Object.prototype.toString.call(console), '[object console]'); 19 + test('JSON toStringTag', Object.prototype.toString.call(JSON), '[object JSON]'); 20 + test('process toStringTag', Object.prototype.toString.call(process), '[object process]'); 21 + test('Buffer toStringTag', Object.prototype.toString.call(Buffer), '[object Buffer]'); 22 + test('crypto toStringTag', Object.prototype.toString.call(crypto), '[object Crypto]'); 23 + 24 + test('path toStringTag', Object.prototype.toString.call(path), '[object path]'); 25 + test('fs toStringTag', Object.prototype.toString.call(fs), '[object fs]'); 26 + test('shell toStringTag', Object.prototype.toString.call(shell), '[object shell]'); 27 + test('ffi toStringTag', Object.prototype.toString.call(ffi), '[object FFI]'); 11 28 12 29 summary();
+3
examples/spec/symbols.js
··· 29 29 test('Symbol.toStringTag exists', typeof Symbol.toStringTag, 'symbol'); 30 30 test('Symbol.hasInstance exists', typeof Symbol.hasInstance, 'symbol'); 31 31 32 + const custom = { [Symbol.toStringTag]: 'MyCustomType' }; 33 + test('Symbol.toStringTag custom', Object.prototype.toString.call(custom), '[object MyCustomType]'); 34 + 32 35 summary();
+2
include/modules/symbol.h
··· 5 5 6 6 void init_symbol_module(void); 7 7 jsval_t get_iterator_symbol(void); 8 + 8 9 const char *get_iterator_sym_key(void); 10 + const char *get_toStringTag_sym_key(void); 9 11 10 12 #endif
+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.2.0') 77 + version_conf.set('ANT_VERSION', '0.1.2.1') 78 78 version_conf.set('ANT_GIT_HASH', git_hash) 79 79 version_conf.set('ANT_BUILD_DATE', build_date) 80 80
+18 -8
src/ant.c
··· 1199 1199 jsoff_t pklen = offtolen(loadoff(js, pkoff)); 1200 1200 const char *pkstr = (const char *) &js->mem[pkoff + sizeof(jsoff_t)]; 1201 1201 1202 - if (!streq(pkstr, pklen, "__proto__", 9) && !streq(pkstr, pklen, "constructor", 11) && !streq(pkstr, pklen, "@@toStringTag", 13) && !streq(pkstr, pklen, "__getter", 8)) { 1202 + const char *tag_key = get_toStringTag_sym_key(); 1203 + size_t tag_key_len = strlen(tag_key); 1204 + if (!streq(pkstr, pklen, "__proto__", 9) && !streq(pkstr, pklen, "constructor", 11) && !streq(pkstr, pklen, tag_key, tag_key_len) && !streq(pkstr, pklen, "__getter", 8)) { 1203 1205 has_proto_props = true; 1204 1206 break; 1205 1207 } ··· 1223 1225 jsoff_t pklen = offtolen(loadoff(js, pkoff)); 1224 1226 const char *pkstr = (const char *) &js->mem[pkoff + sizeof(jsoff_t)]; 1225 1227 1226 - if (!streq(pkstr, pklen, "__proto__", 9) && !streq(pkstr, pklen, "constructor", 11) && !streq(pkstr, pklen, "@@toStringTag", 13) && !streq(pkstr, pklen, "__getter", 8)) { 1228 + const char *tag_key2 = get_toStringTag_sym_key(); 1229 + size_t tag_key_len2 = strlen(tag_key2); 1230 + if (!streq(pkstr, pklen, "__proto__", 9) && !streq(pkstr, pklen, "constructor", 11) && !streq(pkstr, pklen, tag_key2, tag_key_len2) && !streq(pkstr, pklen, "__getter", 8)) { 1227 1231 if (!proto_first) n += cpy(buf + n, len - n, ",\n", 2); 1228 1232 proto_first = false; 1229 1233 n += add_indent(buf + n, len - n, stringify_indent); ··· 1261 1265 n += (size_t) snprintf(buf + n, len - n, "<ref *%d> ", self_ref); 1262 1266 } 1263 1267 1264 - jsoff_t tag_off = lkp_proto(js, obj, "@@toStringTag", 13); 1268 + const char *tostring_tag_key = get_toStringTag_sym_key(); 1269 + jsoff_t tag_off = lkp_proto(js, obj, tostring_tag_key, strlen(tostring_tag_key)); 1265 1270 bool is_map = false, is_set = false; 1266 1271 jsoff_t tlen = 0, toff = 0; 1267 1272 const char *tag_str = NULL; ··· 1381 1386 const char *key = (char *) &js->mem[koff + sizeof(koff)]; 1382 1387 1383 1388 bool is_desc = (klen > 7 && key[0] == '_' && key[1] == '_' && key[2] == 'd' && key[3] == 'e' && key[4] == 's' && key[5] == 'c' && key[6] == '_'); 1384 - bool should_hide = streq(key, klen, "__proto__", 9) || streq(key, klen, "@@toStringTag", 13) || streq(key, klen, "__getter", 8) || is_desc; 1389 + const char *tag_sym_key = get_toStringTag_sym_key(); 1390 + bool should_hide = streq(key, klen, "__proto__", 9) || streq(key, klen, tag_sym_key, strlen(tag_sym_key)) || streq(key, klen, "__getter", 8) || is_desc; 1385 1391 1386 1392 if (!should_hide) { 1387 1393 char desc_key[128]; ··· 1494 1500 jsoff_t klen = offtolen(loadoff(js, koff)); 1495 1501 const char *kstr = (const char *) &js->mem[koff + sizeof(jsoff_t)]; 1496 1502 1497 - if (!is_internal_prop(kstr, klen) && !streq(kstr, klen, "name", 4) && !streq(kstr, klen, "@@toStringTag", 13) && !streq(kstr, klen, "__getter", 8)) { 1503 + const char *func_tag_key = get_toStringTag_sym_key(); 1504 + if (!is_internal_prop(kstr, klen) && !streq(kstr, klen, "name", 4) && !streq(kstr, klen, func_tag_key, strlen(func_tag_key)) && !streq(kstr, klen, "__getter", 8)) { 1498 1505 if (!first) n += cpy(buf + n, len - n, ",\n", 2); 1499 1506 first = false; 1500 1507 n += add_indent(buf + n, len - n, stringify_indent); ··· 10527 10534 10528 10535 if (t == T_OBJ || t == T_ARR || t == T_FUNC) { 10529 10536 jsval_t check_obj = (t == T_FUNC) ? mkval(T_OBJ, vdata(obj)) : obj; 10530 - jsoff_t tag_off = lkp(js, check_obj, "@@toStringTag", 13); 10537 + const char *tostr_tag_key = get_toStringTag_sym_key(); 10538 + jsoff_t tag_off = lkp(js, check_obj, tostr_tag_key, strlen(tostr_tag_key)); 10531 10539 if (tag_off != 0) { 10532 10540 jsval_t tag_val = resolveprop(js, mkval(T_PROP, tag_off)); 10533 10541 if (vtype(tag_val) == T_STR) { ··· 16004 16012 setprop(js, map_proto, js_mkstr(js, "clear", 5), js_mkfun(map_clear)); 16005 16013 setprop(js, map_proto, js_mkstr(js, "size", 4), js_mkfun(map_size)); 16006 16014 setprop(js, map_proto, js_mkstr(js, "entries", 7), js_mkfun(map_entries)); 16007 - setprop(js, map_proto, js_mkstr(js, "@@toStringTag", 13), js_mkstr(js, "Map", 3)); 16015 + const char *map_tag_key = get_toStringTag_sym_key(); 16016 + js_set(js, map_proto, map_tag_key, js_mkstr(js, "Map", 3)); 16008 16017 16009 16018 jsval_t set_proto_obj = js_mkobj(js); 16010 16019 set_proto(js, set_proto_obj, object_proto); ··· 16014 16023 setprop(js, set_proto_obj, js_mkstr(js, "clear", 5), js_mkfun(set_clear)); 16015 16024 setprop(js, set_proto_obj, js_mkstr(js, "size", 4), js_mkfun(set_size)); 16016 16025 setprop(js, set_proto_obj, js_mkstr(js, "values", 6), js_mkfun(set_values)); 16017 - setprop(js, set_proto_obj, js_mkstr(js, "@@toStringTag", 13), js_mkstr(js, "Set", 3)); 16026 + const char *set_tag_key = get_toStringTag_sym_key(); 16027 + js_set(js, set_proto_obj, set_tag_key, js_mkstr(js, "Set", 3)); 16018 16028 16019 16029 jsval_t weakmap_proto = js_mkobj(js); 16020 16030 set_proto(js, weakmap_proto, object_proto);
+1 -1
src/main.c
··· 187 187 if (gct->count > 0) js_setgct(js, gct->ival[0]); 188 188 ant_runtime_init(js, argc, argv); 189 189 190 + init_symbol_module(); 190 191 init_builtin_module(); 191 192 init_buffer_module(); 192 193 init_atomics_module(); ··· 202 203 init_uri_module(); 203 204 init_url_module(); 204 205 init_reflect_module(); 205 - init_symbol_module(); 206 206 207 207 ant_register_library(shell_library, "ant:shell", NULL); 208 208 ant_register_library(ffi_library, "ant:ffi", NULL);
+3 -1
src/modules/atomics.c
··· 8 8 9 9 #include "ant.h" 10 10 #include "runtime.h" 11 + 11 12 #include "modules/buffer.h" 12 13 #include "modules/atomics.h" 14 + #include "modules/symbol.h" 13 15 14 16 static WaitQueue global_wait_queue; 15 17 static pthread_once_t wait_queue_init_once = PTHREAD_ONCE_INIT; ··· 836 838 js_set(js, atomics, "waitAsync", js_mkfun(js_atomics_waitAsync)); 837 839 js_set(js, atomics, "xor", js_mkfun(js_atomics_xor)); 838 840 839 - js_set(js, atomics, "@@toStringTag", js_mkstr(js, "Atomics", 7)); 841 + js_set(js, atomics, get_toStringTag_sym_key(), js_mkstr(js, "Atomics", 7)); 840 842 js_set(js, glob, "Atomics", atomics); 841 843 }
+2 -1
src/modules/buffer.c
··· 5 5 6 6 #include "runtime.h" 7 7 #include "modules/buffer.h" 8 + #include "modules/symbol.h" 8 9 9 10 static jsval_t js_arraybuffer_slice(struct js *js, jsval_t *args, int nargs); 10 11 static jsval_t js_typedarray_slice(struct js *js, jsval_t *args, int nargs); ··· 815 816 js_set(js, buffer_obj, "from", js_mkfun(js_buffer_from)); 816 817 js_set(js, buffer_obj, "alloc", js_mkfun(js_buffer_alloc)); 817 818 js_set(js, buffer_obj, "allocUnsafe", js_mkfun(js_buffer_allocUnsafe)); 818 - js_set(js, buffer_obj, "@@toStringTag", js_mkstr(js, "Buffer", 6)); 819 + js_set(js, buffer_obj, get_toStringTag_sym_key(), js_mkstr(js, "Buffer", 6)); 819 820 js_set(js, glob, "Buffer", buffer_obj); 820 821 }
+3 -2
src/modules/crypto.c
··· 8 8 #include "runtime.h" 9 9 #include "modules/crypto.h" 10 10 #include "modules/buffer.h" 11 + #include "modules/symbol.h" 11 12 12 13 static int ensure_crypto_init(struct js *js) { 13 14 static int crypto_initialized = 0; ··· 171 172 js_set(js, crypto_obj, "randomUUIDv7", js_mkfun(js_crypto_random_uuidv7)); 172 173 js_set(js, crypto_obj, "getRandomValues", js_mkfun(js_crypto_get_random_values)); 173 174 174 - js_set(js, crypto_obj, "@@toStringTag", js_mkstr(js, "Crypto", 6)); 175 + js_set(js, crypto_obj, get_toStringTag_sym_key(), js_mkstr(js, "Crypto", 6)); 175 176 return crypto_obj; 176 177 } 177 178 ··· 189 190 js_set(js, lib, "randomBytes", js_mkfun(js_crypto_random_bytes)); 190 191 js_set(js, lib, "randomUUID", js_mkfun(js_crypto_random_uuid)); 191 192 js_set(js, lib, "getRandomValues", js_mkfun(js_crypto_get_random_values)); 192 - js_set(js, lib, "@@toStringTag", js_mkstr(js, "crypto", 6)); 193 + js_set(js, lib, get_toStringTag_sym_key(), js_mkstr(js, "crypto", 6)); 193 194 js_set(js, lib, "default", lib); 194 195 195 196 return lib;
+6 -5
src/modules/events.c
··· 6 6 #include "ant.h" 7 7 #include "runtime.h" 8 8 #include "modules/events.h" 9 + #include "modules/symbol.h" 9 10 #include "uthash.h" 10 11 11 12 #define MAX_LISTENERS_PER_EVENT 32 ··· 287 288 jsval_t event_obj = js_mkobj(js); 288 289 js_set(js, event_obj, "type", args[0]); 289 290 js_set(js, event_obj, "target", this_obj); 290 - js_set(js, event_obj, "@@toStringTag", js_mkstr(js, "Event", 5)); 291 + js_set(js, event_obj, get_toStringTag_sym_key(), js_mkstr(js, "Event", 5)); 291 292 292 293 if (nargs >= 2 && js_type(args[1]) != JS_UNDEF) { 293 294 js_set(js, event_obj, "detail", args[1]); ··· 336 337 337 338 jsval_t event_obj = js_mkobj(js); 338 339 js_set(js, event_obj, "type", args[0]); 339 - js_set(js, event_obj, "@@toStringTag", js_mkstr(js, "Event", 5)); 340 + js_set(js, event_obj, get_toStringTag_sym_key(), js_mkstr(js, "Event", 5)); 340 341 341 342 if (nargs >= 2 && js_type(args[1]) != JS_UNDEF) { 342 343 js_set(js, event_obj, "detail", args[1]); ··· 620 621 js_set(js, obj, "removeAllListeners", js_mkfun(js_eventemitter_removeAllListeners)); 621 622 js_set(js, obj, "listenerCount", js_mkfun(js_eventemitter_listenerCount)); 622 623 js_set(js, obj, "eventNames", js_mkfun(js_eventemitter_eventNames)); 623 - js_set(js, obj, "@@toStringTag", js_mkstr(js, "EventEmitter", 12)); 624 + js_set(js, obj, get_toStringTag_sym_key(), js_mkstr(js, "EventEmitter", 12)); 624 625 625 626 return obj; 626 627 } ··· 629 630 jsval_t lib = js_mkobj(js); 630 631 631 632 js_set(js, lib, "EventEmitter", js_mkfun(js_eventemitter_constructor)); 632 - js_set(js, lib, "@@toStringTag", js_mkstr(js, "events", 6)); 633 + js_set(js, lib, get_toStringTag_sym_key(), js_mkstr(js, "events", 6)); 633 634 634 635 return lib; 635 636 } ··· 647 648 js_set(js, event_target_proto, "addEventListener", js_mkfun(js_add_event_listener_method)); 648 649 js_set(js, event_target_proto, "removeEventListener", js_mkfun(js_remove_event_listener_method)); 649 650 js_set(js, event_target_proto, "dispatchEvent", js_mkfun(js_dispatch_event_method)); 650 - js_set(js, event_target_proto, "@@toStringTag", js_mkstr(js, "EventTarget", 11)); 651 + js_set(js, event_target_proto, get_toStringTag_sym_key(), js_mkstr(js, "EventTarget", 11)); 651 652 652 653 js_set(js, global, "EventTargetPrototype", event_target_proto); 653 654 }
+2 -1
src/modules/ffi.c
··· 7 7 #include <uthash.h> 8 8 9 9 #include "modules/ffi.h" 10 + #include "modules/symbol.h" 10 11 11 12 typedef struct ffi_lib { 12 13 char name[256]; ··· 125 126 js_set(js, ffi_types, "string", js_mkstr(js, "string", 6)); 126 127 js_set(js, ffi_types, "spread", js_mkstr(js, "...", 3)); 127 128 js_set(js, ffi_obj, "FFIType", ffi_types); 128 - js_set(js, ffi_obj, "@@toStringTag", js_mkstr(js, "FFI", 3)); 129 + js_set(js, ffi_obj, get_toStringTag_sym_key(), js_mkstr(js, "FFI", 3)); 129 130 js_set(js, ffi_obj, "default", ffi_obj); 130 131 131 132 return ffi_obj;
+2 -1
src/modules/fs.c
··· 9 9 #include <unistd.h> 10 10 #include <errno.h> 11 11 #include "modules/fs.h" 12 + #include "modules/symbol.h" 12 13 #include "ant.h" 13 14 #include "runtime.h" 14 15 ··· 1140 1141 js_set(js, lib, "existsSync", js_mkfun(builtin_fs_existsSync)); 1141 1142 js_set(js, lib, "readdir", js_mkfun(builtin_fs_readdir)); 1142 1143 js_set(js, lib, "readdirSync", js_mkfun(builtin_fs_readdirSync)); 1143 - js_set(js, lib, "@@toStringTag", js_mkstr(js, "fs", 2)); 1144 + js_set(js, lib, get_toStringTag_sym_key(), js_mkstr(js, "fs", 2)); 1144 1145 js_set(js, lib, "default", lib); 1145 1146 1146 1147 return lib;
+2 -1
src/modules/io.c
··· 8 8 9 9 #include "runtime.h" 10 10 #include "modules/io.h" 11 + #include "modules/symbol.h" 11 12 12 13 #define ANSI_RED "\x1b[31m" 13 14 #define ANSI_YELLOW "\x1b[33m" ··· 345 346 js_set(js, console_obj, "timeEnd", js_mkfun(js_console_timeEnd)); 346 347 js_set(js, console_obj, "clear", js_mkfun(js_console_clear)); 347 348 348 - js_set(js, console_obj, "@@toStringTag", js_mkstr(js, "console", 7)); 349 + js_set(js, console_obj, get_toStringTag_sym_key(), js_mkstr(js, "console", 7)); 349 350 js_set(js, js_glob(js), "console", console_obj); 350 351 }
+2 -1
src/modules/json.c
··· 5 5 #include "ant.h" 6 6 #include "runtime.h" 7 7 #include "modules/json.h" 8 + #include "modules/symbol.h" 8 9 9 10 static jsval_t yyjson_to_jsval(struct js *js, yyjson_val *val) { 10 11 if (!val) return js_mkundef(); ··· 218 219 js_set(js, json_obj, "parse", js_mkfun(js_json_parse)); 219 220 js_set(js, json_obj, "stringify", js_mkfun(js_json_stringify)); 220 221 221 - js_set(js, json_obj, "@@toStringTag", js_mkstr(js, "JSON", 4)); 222 + js_set(js, json_obj, get_toStringTag_sym_key(), js_mkstr(js, "JSON", 4)); 222 223 js_set(js, js_glob(js), "JSON", json_obj); 223 224 }
+2 -1
src/modules/path.c
··· 5 5 #include <unistd.h> 6 6 7 7 #include "ant.h" 8 + #include "modules/symbol.h" 8 9 9 10 #ifndef PATH_MAX 10 11 #define PATH_MAX 4096 ··· 474 475 js_set(js, lib, "sep", js_mkstr(js, PATH_SEP_STR, 1)); 475 476 char delimiter_str[2] = {PATH_DELIMITER, '\0'}; 476 477 js_set(js, lib, "delimiter", js_mkstr(js, delimiter_str, 1)); 477 - js_set(js, lib, "@@toStringTag", js_mkstr(js, "path", 4)); 478 + js_set(js, lib, get_toStringTag_sym_key(), js_mkstr(js, "path", 4)); 478 479 js_set(js, lib, "default", lib); 479 480 480 481 return lib;
+2 -1
src/modules/process.c
··· 6 6 #include "ant.h" 7 7 #include "runtime.h" 8 8 #include "modules/process.h" 9 + #include "modules/symbol.h" 9 10 10 11 extern char **environ; 11 12 ··· 174 175 js_set(js, process_obj, "argv", argv_arr); 175 176 js_set(js, process_obj, "cwd", js_mkfun(process_cwd)); 176 177 177 - js_set(js, process_obj, "@@toStringTag", js_mkstr(js, "process", 7)); 178 + js_set(js, process_obj, get_toStringTag_sym_key(), js_mkstr(js, "process", 7)); 178 179 js_set(js, js_glob(js), "process", process_obj); 179 180 }
+2 -1
src/modules/reflect.c
··· 4 4 #include "ant.h" 5 5 #include "runtime.h" 6 6 #include "modules/reflect.h" 7 + #include "modules/symbol.h" 7 8 8 9 static jsval_t reflect_get(struct js *js, jsval_t *args, int nargs) { 9 10 if (nargs < 2) return js_mkundef(); ··· 319 320 js_set(js, reflect_obj, "isExtensible", js_mkfun(reflect_is_extensible)); 320 321 js_set(js, reflect_obj, "preventExtensions", js_mkfun(reflect_prevent_extensions)); 321 322 322 - js_set(js, reflect_obj, "@@toStringTag", js_mkstr(js, "Reflect", 7)); 323 + js_set(js, reflect_obj, get_toStringTag_sym_key(), js_mkstr(js, "Reflect", 7)); 323 324 js_set(js, js_glob(js), "Reflect", reflect_obj); 324 325 }
+2 -1
src/modules/shell.c
··· 5 5 #include <sys/wait.h> 6 6 7 7 #include "ant.h" 8 + #include "modules/symbol.h" 8 9 9 10 static jsval_t builtin_shell_text(struct js *js, jsval_t *args, int nargs); 10 11 static jsval_t builtin_shell_lines(struct js *js, jsval_t *args, int nargs); ··· 217 218 jsval_t lib = js_mkobj(js); 218 219 219 220 js_set(js, lib, "$", js_mkfun(builtin_shell_dollar)); 220 - js_set(js, lib, "@@toStringTag", js_mkstr(js, "shell", 5)); 221 + js_set(js, lib, get_toStringTag_sym_key(), js_mkstr(js, "shell", 5)); 221 222 222 223 return lib; 223 224 }
+10 -9
src/modules/symbol.c
··· 16 16 static jsval_t g_iterator_sym = 0; 17 17 static jsval_t g_toStringTag_sym = 0; 18 18 static jsval_t g_hasInstance_sym = 0; 19 - static char g_iter_sym_key[32] = {0}; 20 19 21 - jsval_t get_iterator_symbol(void) { 22 - return g_iterator_sym; 23 - } 20 + static char g_iter_sym_key[32] = {0}; 21 + static char g_toStringTag_sym_key[32] = {0}; 24 22 25 - const char *get_iterator_sym_key(void) { 26 - return g_iter_sym_key; 27 - } 23 + jsval_t get_iterator_symbol(void) { return g_iterator_sym; } 24 + const char *get_iterator_sym_key(void) { return g_iter_sym_key; } 25 + const char *get_toStringTag_sym_key(void) { return g_toStringTag_sym_key; } 28 26 29 27 static jsval_t builtin_Symbol(struct js *js, jsval_t *args, int nargs) { 30 28 const char *desc = NULL; ··· 186 184 g_toStringTag_sym = js_mksym(js, "Symbol.toStringTag"); 187 185 g_hasInstance_sym = js_mksym(js, "Symbol.hasInstance"); 188 186 189 - jsval_t sym_id = js_get(js, g_iterator_sym, "__sym_id"); 190 - snprintf(g_iter_sym_key, sizeof(g_iter_sym_key), "__sym_%.0f__", js_getnum(sym_id)); 187 + jsval_t iter_sym_id = js_get(js, g_iterator_sym, "__sym_id"); 188 + snprintf(g_iter_sym_key, sizeof(g_iter_sym_key), "__sym_%.0f__", js_getnum(iter_sym_id)); 189 + 190 + jsval_t tag_sym_id = js_get(js, g_toStringTag_sym, "__sym_id"); 191 + snprintf(g_toStringTag_sym_key, sizeof(g_toStringTag_sym_key), "__sym_%.0f__", js_getnum(tag_sym_id)); 191 192 192 193 jsval_t symbol_ctor = js_mkobj(js); 193 194 js_set(js, symbol_ctor, "__native_func", js_mkfun(builtin_Symbol));
+1 -1
tests/test_all_modules.cjs
··· 1 1 // Test toStringTag for all modules 2 2 3 - console.log('Testing @@toStringTag for all modules:\n'); 3 + console.log('Testing Symbol.toStringTag for all modules:\n'); 4 4 5 5 // Built-in modules 6 6 console.log('Atomics:', Object.prototype.toString.call(Atomics));
+19 -16
tests/test_toString.cjs
··· 1 1 // Test Object.prototype.toString 2 2 3 - console.log("Testing Object.prototype.toString:"); 3 + console.log('Testing Object.prototype.toString:'); 4 4 5 - // Test with Atomics (has @@toStringTag) 6 - console.log("Object.prototype.toString.call(Atomics):", Object.prototype.toString.call(Atomics)); 5 + // Test with Atomics (has Symbol.toStringTag) 6 + console.log('Object.prototype.toString.call(Atomics):', Object.prototype.toString.call(Atomics)); 7 7 8 8 // Test with other built-ins 9 - console.log("\nOther types:"); 10 - console.log("Object.prototype.toString.call({}):", Object.prototype.toString.call({})); 11 - console.log("Object.prototype.toString.call([]):", Object.prototype.toString.call([])); 12 - console.log("Object.prototype.toString.call(function(){}):", Object.prototype.toString.call(function(){})); 13 - console.log("Object.prototype.toString.call(42):", Object.prototype.toString.call(42)); 14 - console.log("Object.prototype.toString.call('hello'):", Object.prototype.toString.call("hello")); 15 - console.log("Object.prototype.toString.call(true):", Object.prototype.toString.call(true)); 16 - console.log("Object.prototype.toString.call(null):", Object.prototype.toString.call(null)); 17 - console.log("Object.prototype.toString.call(undefined):", Object.prototype.toString.call(undefined)); 9 + console.log('\nOther types:'); 10 + console.log('Object.prototype.toString.call({}):', Object.prototype.toString.call({})); 11 + console.log('Object.prototype.toString.call([]):', Object.prototype.toString.call([])); 12 + console.log( 13 + 'Object.prototype.toString.call(function(){}):', 14 + Object.prototype.toString.call(function () {}) 15 + ); 16 + console.log('Object.prototype.toString.call(42):', Object.prototype.toString.call(42)); 17 + console.log("Object.prototype.toString.call('hello'):", Object.prototype.toString.call('hello')); 18 + console.log('Object.prototype.toString.call(true):', Object.prototype.toString.call(true)); 19 + console.log('Object.prototype.toString.call(null):', Object.prototype.toString.call(null)); 20 + console.log('Object.prototype.toString.call(undefined):', Object.prototype.toString.call(undefined)); 18 21 19 - // Test with custom @@toStringTag 20 - console.log("\nCustom @@toStringTag:"); 21 - const custom = { "@@toStringTag": "MyCustomType" }; 22 - console.log("Object.prototype.toString.call(custom):", Object.prototype.toString.call(custom)); 22 + // Test with custom Symbol.toStringTag 23 + console.log('\nCustom Symbol.toStringTag:'); 24 + const custom = { [Symbol.toStringTag]: 'MyCustomType' }; 25 + console.log('Object.prototype.toString.call(custom):', Object.prototype.toString.call(custom));
-23
tests/test_toString_simple.cjs
··· 1 - // Test Object.prototype.toString directly 2 - 3 - console.log("Testing toString:"); 4 - 5 - // Test on objects directly 6 - const obj = {}; 7 - console.log("obj.toString():", obj.toString()); 8 - 9 - const arr = []; 10 - console.log("arr.toString():", arr.toString()); 11 - 12 - const atomics = Atomics; 13 - console.log("Atomics object:", atomics); 14 - console.log("Atomics.toString:", atomics.toString); 15 - 16 - // If toString exists, call it 17 - if (atomics.toString) { 18 - console.log("Calling Atomics.toString():", atomics.toString()); 19 - } 20 - 21 - // Test custom object with @@toStringTag 22 - const custom = { "@@toStringTag": "MyCustomType" }; 23 - console.log("custom.toString():", custom.toString());