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.

fix circular prints

+25 -7
-2
examples/spec/run.js
··· 9 9 const DIM = '\x1b[2m'; 10 10 const RESET = '\x1b[0m'; 11 11 12 - console.log(path); 13 - 14 12 const specDir = path.dirname(import.meta.url.replace('file://', '')); 15 13 const files = fs 16 14 .readdirSync(specDir)
+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.0.18') 77 + version_conf.set('ANT_VERSION', '0.1.0.19') 78 78 version_conf.set('ANT_GIT_HASH', git_hash) 79 79 version_conf.set('ANT_BUILD_DATE', build_date) 80 80
+24 -4
src/ant.c
··· 804 804 next = loadoff(js, next) & ~(3U | CONSTMASK); 805 805 } 806 806 807 + jsoff_t proto_off = lkp(js, obj, "__proto__", 9); 808 + if (proto_off != 0) { 809 + jsval_t proto_val = resolveprop(js, mkval(T_PROP, proto_off)); 810 + if (vtype(proto_val) == T_OBJ) scan_refs(js, proto_val); 811 + } 812 + 807 813 stringify_depth--; 808 814 } 809 815 ··· 860 866 861 867 static int get_circular_ref(jsval_t obj) { 862 868 if (is_on_stack(obj)) { 863 - return find_multiref(obj); 869 + int ref = find_multiref(obj); 870 + return ref ? ref : -1; 864 871 } 865 872 return 0; 866 873 } ··· 895 902 896 903 static size_t strarr(struct js *js, jsval_t obj, char *buf, size_t len) { 897 904 int ref = get_circular_ref(obj); 898 - if (ref) return (size_t) snprintf(buf, len, "[Circular *%d]", ref); 905 + if (ref) return ref > 0 ? (size_t) snprintf(buf, len, "[Circular *%d]", ref) : cpy(buf, len, "[Circular]", 10); 899 906 900 907 push_stringify(obj); 901 908 size_t n = cpy(buf, len, "[ ", 2); ··· 1064 1071 1065 1072 static size_t print_prototype(struct js *js, jsval_t proto_val, char *buf, size_t len, bool *first) { 1066 1073 size_t n = 0; 1074 + 1075 + int ref = get_circular_ref(proto_val); 1076 + if (ref) { 1077 + if (!*first) n += cpy(buf + n, len - n, ",\n", 2); 1078 + *first = false; 1079 + n += add_indent(buf + n, len - n, stringify_indent); 1080 + n += ref > 0 ? (size_t) snprintf(buf + n, len - n, "[Prototype]: [Circular *%d]", ref) : cpy(buf + n, len - n, "[Prototype]: [Circular]", 23); 1081 + return n; 1082 + } 1083 + 1084 + push_stringify(proto_val); 1085 + 1067 1086 bool has_proto_props = false; 1068 1087 jsoff_t proto_next = loadoff(js, (jsoff_t) vdata(proto_val)) & ~(3U | CONSTMASK); 1069 1088 ··· 1115 1134 n += cpy(buf + n, len - n, "[Prototype]: {}", 15); 1116 1135 } 1117 1136 1137 + pop_stringify(); 1118 1138 return n; 1119 1139 } 1120 1140 ··· 1123 1143 if (time_off != 0) return strdate(js, obj, buf, len); 1124 1144 1125 1145 int ref = get_circular_ref(obj); 1126 - if (ref) return (size_t) snprintf(buf, len, "[Circular *%d]", ref); 1146 + if (ref) return ref > 0 ? (size_t) snprintf(buf, len, "[Circular *%d]", ref) : cpy(buf, len, "[Circular]", 10); 1127 1147 1128 1148 push_stringify(obj); 1129 1149 ··· 1351 1371 1352 1372 static size_t strfunc_ctor(struct js *js, jsval_t func_obj, char *buf, size_t len) { 1353 1373 int ref = get_circular_ref(func_obj); 1354 - if (ref) return (size_t) snprintf(buf, len, "[Circular *%d]", ref); 1374 + if (ref) return ref > 0 ? (size_t) snprintf(buf, len, "[Circular *%d]", ref) : cpy(buf, len, "[Circular]", 10); 1355 1375 push_stringify(func_obj); 1356 1376 1357 1377 size_t n = cpy(buf, len, "{\n", 2);