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.

hide tests from lang bar

+52 -3
+2
.gitattributes
··· 1 + # hide all tests 2 + tests/** linguist-generated=true
+1 -1
meson.build
··· 43 43 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 44 44 45 45 version_conf = configuration_data() 46 - version_conf.set('ANT_VERSION', '0.0.6.12') 46 + version_conf.set('ANT_VERSION', '0.0.6.13') 47 47 version_conf.set('ANT_GIT_HASH', git_hash) 48 48 version_conf.set('ANT_BUILD_DATE', build_date) 49 49
+36 -2
src/ant.c
··· 560 560 return i; 561 561 } 562 562 563 + // Circular reference tracking for stringification 564 + #define MAX_STRINGIFY_DEPTH 64 565 + static jsval_t stringify_stack[MAX_STRINGIFY_DEPTH]; 566 + static int stringify_depth = 0; 567 + 568 + static bool is_circular(jsval_t obj) { 569 + for (int i = 0; i < stringify_depth; i++) { 570 + if (stringify_stack[i] == obj) return true; 571 + } 572 + return false; 573 + } 574 + 575 + static void push_stringify(jsval_t obj) { 576 + if (stringify_depth < MAX_STRINGIFY_DEPTH) { 577 + stringify_stack[stringify_depth++] = obj; 578 + } 579 + } 580 + 581 + static void pop_stringify(void) { 582 + if (stringify_depth > 0) stringify_depth--; 583 + } 584 + 563 585 static size_t strarr(struct js *js, jsval_t obj, char *buf, size_t len) { 586 + if (is_circular(obj)) return cpy(buf, len, "[Circular]", 10); 587 + 588 + push_stringify(obj); 564 589 size_t n = cpy(buf, len, "[", 1); 565 590 jsoff_t next = loadoff(js, (jsoff_t) vdata(obj)) & ~(3U | CONSTMASK); 566 591 jsoff_t length = 0; ··· 609 634 } 610 635 } 611 636 612 - return n + cpy(buf + n, len - n, "]", 1); 637 + n += cpy(buf + n, len - n, "]", 1); 638 + pop_stringify(); 639 + return n; 613 640 } 614 641 615 642 static size_t strdate(struct js *js, jsval_t obj, char *buf, size_t len) { ··· 647 674 jsoff_t time_off = lkp(js, obj, "__time", 6); 648 675 if (time_off != 0) return strdate(js, obj, buf, len); 649 676 677 + if (is_circular(obj)) return cpy(buf, len, "[Circular]", 10); 678 + 679 + push_stringify(obj); 650 680 size_t n = cpy(buf, len, "{", 1); 651 681 jsoff_t next = loadoff(js, (jsoff_t) vdata(obj)) & ~(3U | CONSTMASK); 652 682 ··· 660 690 next = loadoff(js, next) & ~(3U | CONSTMASK); 661 691 } 662 692 663 - return n + cpy(buf + n, len - n, "}", 1); 693 + n += cpy(buf + n, len - n, "}", 1); 694 + pop_stringify(); 695 + return n; 664 696 } 665 697 666 698 static size_t strnum(jsval_t value, char *buf, size_t len) { ··· 879 911 if (is_err(value)) return js->errmsg; 880 912 if (js->brk + sizeof(jsoff_t) >= js->size) return ""; 881 913 914 + // Reset stringify depth for each new stringification 915 + stringify_depth = 0; 882 916 len = tostr(js, value, buf, available); 883 917 js_mkstr(js, NULL, len); 884 918 return buf;
+11
tests/test_circular.js
··· 1 + const obj = {}; 2 + obj.self = obj; 3 + console.log('Simple circular:', obj); 4 + const a = { name: 'a' }; 5 + const b = { name: 'b' }; 6 + a.b = b; 7 + b.a = a; 8 + console.log('Mutual circular:', a); 9 + const arr = [1, 2, 3]; 10 + arr.push(arr); 11 + console.log('Array circular:', arr);
+2
tests/window.cjs
··· 1 + const window = this; 2 + console.log(window);