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.

proper async pushback

+57 -28
+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.0.7.21') 77 + version_conf.set('ANT_VERSION', '0.0.7.22') 78 78 version_conf.set('ANT_GIT_HASH', git_hash) 79 79 version_conf.set('ANT_BUILD_DATE', build_date) 80 80
+31 -27
src/ant.c
··· 1549 1549 if ((cleaned & 3) != T_OBJ && (cleaned & 3) != T_PROP) continue; 1550 1550 jsoff_t adjusted = cleaned > start ? cleaned - size : cleaned; 1551 1551 if (cleaned != adjusted) saveoff(js, off, adjusted | flags); 1552 + 1552 1553 if ((cleaned & 3) == T_OBJ) { 1553 1554 jsoff_t u = loadoff(js, (jsoff_t) (off + sizeof(jsoff_t))); 1554 1555 if (u > start) saveoff(js, (jsoff_t) (off + sizeof(jsoff_t)), u - size); 1555 1556 } 1557 + 1558 + #define FIXUP_JSVAL(val) do { \ 1559 + if (is_mem_entity(vtype(val)) && vdata(val) > start) \ 1560 + (val) = mkval(vtype(val), vdata(val) - size); \ 1561 + } while (0) 1562 + 1563 + #define FIXUP_JSVAL_AT(mem_off) do { \ 1564 + jsval_t _v = loadval(js, mem_off); \ 1565 + if (is_mem_entity(vtype(_v)) && vdata(_v) > start) \ 1566 + saveval(js, mem_off, mkval(vtype(_v), vdata(_v) - size)); \ 1567 + } while (0) 1568 + 1569 + #define FIXUP_OFF(off_var) do { if ((off_var) > start) (off_var) -= size; } while (0) 1570 + 1556 1571 if ((cleaned & 3) == T_PROP) { 1557 1572 jsoff_t koff = loadoff(js, (jsoff_t) (off + sizeof(off))); 1558 1573 if (koff > start) saveoff(js, (jsoff_t) (off + sizeof(off)), koff - size); 1559 - jsval_t val = loadval(js, (jsoff_t) (off + sizeof(off) + sizeof(off))); 1560 - if (is_mem_entity(vtype(val)) && vdata(val) > start) { 1561 - saveval(js, (jsoff_t) (off + sizeof(off) + sizeof(off)), mkval(vtype(val), (unsigned long) (vdata(val) - size))); 1562 - } 1574 + FIXUP_JSVAL_AT((jsoff_t) (off + sizeof(off) + sizeof(off))); 1563 1575 } 1564 1576 } 1565 1577 1566 - jsoff_t off = (jsoff_t) vdata(js->scope); 1567 - if (off > start) js->scope = mkval(T_OBJ, off - size); 1568 - if (js->nogc >= start) js->nogc -= size; 1578 + FIXUP_JSVAL(js->scope); 1579 + FIXUP_OFF(js->nogc); 1569 1580 if (js->code > (char *) js->mem && js->code - (char *) js->mem < js->size && js->code - (char *) js->mem > start) { 1570 1581 js->code -= size; 1571 1582 } 1572 1583 1573 1584 if (global_scope_stack) { 1574 1585 jsoff_t *p = NULL; 1575 - while ((p = (jsoff_t *)utarray_next(global_scope_stack, p)) != NULL) { 1576 - if (*p > start) *p -= size; 1577 - } 1586 + while ((p = (jsoff_t *)utarray_next(global_scope_stack, p)) != NULL) FIXUP_OFF(*p); 1578 1587 } 1579 - 1588 + 1580 1589 for (coroutine_t *coro = pending_coroutines.head; coro != NULL; coro = coro->next) { 1581 - if (is_mem_entity(vtype(coro->scope)) && vdata(coro->scope) > start) 1582 - coro->scope = mkval(vtype(coro->scope), vdata(coro->scope) - size); 1583 - if (is_mem_entity(vtype(coro->this_val)) && vdata(coro->this_val) > start) 1584 - coro->this_val = mkval(vtype(coro->this_val), vdata(coro->this_val) - size); 1585 - if (is_mem_entity(vtype(coro->awaited_promise)) && vdata(coro->awaited_promise) > start) 1586 - coro->awaited_promise = mkval(vtype(coro->awaited_promise), vdata(coro->awaited_promise) - size); 1587 - if (is_mem_entity(vtype(coro->result)) && vdata(coro->result) > start) 1588 - coro->result = mkval(vtype(coro->result), vdata(coro->result) - size); 1589 - if (is_mem_entity(vtype(coro->async_func)) && vdata(coro->async_func) > start) 1590 - coro->async_func = mkval(vtype(coro->async_func), vdata(coro->async_func) - size); 1591 - if (is_mem_entity(vtype(coro->yield_value)) && vdata(coro->yield_value) > start) 1592 - coro->yield_value = mkval(vtype(coro->yield_value), vdata(coro->yield_value) - size); 1593 - for (int i = 0; i < coro->nargs; i++) { 1594 - if (is_mem_entity(vtype(coro->args[i])) && vdata(coro->args[i]) > start) 1595 - coro->args[i] = mkval(vtype(coro->args[i]), vdata(coro->args[i]) - size); 1596 - } 1590 + FIXUP_JSVAL(coro->scope); 1591 + FIXUP_JSVAL(coro->this_val); 1592 + FIXUP_JSVAL(coro->awaited_promise); 1593 + FIXUP_JSVAL(coro->result); 1594 + FIXUP_JSVAL(coro->async_func); 1595 + FIXUP_JSVAL(coro->yield_value); 1596 + for (int i = 0; i < coro->nargs; i++) FIXUP_JSVAL(coro->args[i]); 1597 1597 } 1598 + 1599 + #undef FIXUP_JSVAL 1600 + #undef FIXUP_JSVAL_AT 1601 + #undef FIXUP_OFF 1598 1602 } 1599 1603 1600 1604 static void js_compact_from_end(struct js *js) {
+25
tests/test_async_gc.js
··· 1 + async function allocateAndWait() { 2 + let data = []; 3 + for (let i = 0; i < 100; i = i + 1) { 4 + data.push({ value: 'test ' + i }); 5 + } 6 + console.log('Before await, data length:', data.length); 7 + 8 + await new Promise(resolve => setTimeout(resolve, 10)); 9 + Ant.gc(); 10 + 11 + console.log('After await+GC, data length:', data.length); 12 + return data.length; 13 + } 14 + 15 + async function main() { 16 + for (let i = 0; i < 3; i = i + 1) { 17 + console.log('Cycle', i + 1); 18 + let result = await allocateAndWait(); 19 + console.log('Result:', result); 20 + Ant.gc(); 21 + } 22 + console.log('Done'); 23 + } 24 + 25 + main();