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.

cleanup js_gc_update_roots

+71 -99
+1 -1
meson.build
··· 86 86 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 87 87 88 88 version_conf = configuration_data() 89 - version_conf.set('ANT_VERSION', '0.3.1.13') 89 + version_conf.set('ANT_VERSION', '0.3.1.14') 90 90 version_conf.set('ANT_GIT_HASH', git_hash) 91 91 version_conf.set('ANT_BUILD_DATE', build_date) 92 92
+70 -98
src/ant.c
··· 20731 20731 if (css) *css = js->css; 20732 20732 } 20733 20733 20734 + #define FWD_OFF(off) ((off) ? ((off) = fwd_off(ctx, off)) : 0) 20735 + #define FWD_VAL(val) ((val) = fwd_val(ctx, val)) 20736 + #define UTARRAY_EACH(arr, type, var) if (arr) for (type *var = (type *)utarray_front(arr), *_end = var + utarray_len(arr); var < _end; var++) 20737 + 20738 + #define REHASH_REGISTRY(registry, entry, tmp, new_reg, key_field, key_size, body) \ 20739 + for (typeof(registry) new_reg = NULL, *_once = NULL; !_once; _once = (void*)1, registry = new_reg) \ 20740 + HASH_ITER(hh, registry, entry, tmp) { \ 20741 + HASH_DEL(registry, entry); \ 20742 + body; \ 20743 + HASH_ADD(hh, new_reg, key_field, key_size, entry); \ 20744 + } 20745 + 20734 20746 void js_gc_update_roots(GC_UPDATE_ARGS) { 20735 - if (global_scope_stack) { 20736 - unsigned int len = utarray_len(global_scope_stack); 20737 - for (unsigned int i = 0; i < len; i++) { 20738 - jsoff_t *off = (jsoff_t *)utarray_eltptr(global_scope_stack, i); 20739 - if (off && *off != 0) *off = fwd_off(ctx, *off); 20740 - } 20741 - } 20742 - 20743 - for (int i = 0; i < global_this_stack.depth; i++) { 20744 - global_this_stack.stack[i] = fwd_val(ctx, global_this_stack.stack[i]); 20747 + UTARRAY_EACH(global_scope_stack, jsoff_t, off) FWD_OFF(*off); 20748 + 20749 + for (int i = 0; i < global_this_stack.depth; i++) 20750 + FWD_VAL(global_this_stack.stack[i]); 20751 + 20752 + UTARRAY_EACH(propref_stack, propref_data_t, pref) { 20753 + FWD_OFF(pref->obj_off); 20754 + FWD_OFF(pref->key_off); 20745 20755 } 20746 - 20747 - if (propref_stack) { 20748 - unsigned int len = utarray_len(propref_stack); 20749 - for (unsigned int i = 0; i < len; i++) { 20750 - propref_data_t *entry = (propref_data_t *)utarray_eltptr(propref_stack, i); 20751 - if (entry) { 20752 - if (entry->obj_off != 0) entry->obj_off = fwd_off(ctx, entry->obj_off); 20753 - if (entry->key_off != 0) entry->key_off = fwd_off(ctx, entry->key_off); 20754 - } 20755 - } 20756 - } 20757 - 20758 - if (prim_propref_stack) { 20759 - unsigned int len = utarray_len(prim_propref_stack); 20760 - for (unsigned int i = 0; i < len; i++) { 20761 - prim_propref_data_t *entry = (prim_propref_data_t *)utarray_eltptr(prim_propref_stack, i); 20762 - if (entry) { 20763 - entry->prim_val = fwd_val(ctx, entry->prim_val); 20764 - if (entry->key_off != 0) entry->key_off = fwd_off(ctx, entry->key_off); 20765 - } 20766 - } 20756 + 20757 + UTARRAY_EACH(prim_propref_stack, prim_propref_data_t, ppref) { 20758 + FWD_VAL(ppref->prim_val); 20759 + FWD_OFF(ppref->key_off); 20767 20760 } 20768 - 20761 + 20769 20762 promise_data_entry_t *pd, *pd_tmp; 20770 20763 HASH_ITER(hh, promise_registry, pd, pd_tmp) { 20771 - pd->value = fwd_val(ctx, pd->value); 20772 - if (pd->handlers) { 20773 - unsigned int len = utarray_len(pd->handlers); 20774 - for (unsigned int i = 0; i < len; i++) { 20775 - promise_handler_t *h = (promise_handler_t *)utarray_eltptr(pd->handlers, i); 20776 - if (h) { 20777 - h->onFulfilled = fwd_val(ctx, h->onFulfilled); 20778 - h->onRejected = fwd_val(ctx, h->onRejected); 20779 - h->nextPromise = fwd_val(ctx, h->nextPromise); 20780 - } 20781 - } 20764 + FWD_VAL(pd->value); 20765 + UTARRAY_EACH(pd->handlers, promise_handler_t, h) { 20766 + FWD_VAL(h->onFulfilled); 20767 + FWD_VAL(h->onRejected); 20768 + FWD_VAL(h->nextPromise); 20782 20769 } 20783 20770 } 20784 - 20785 - if (rt && rt->js == js) { 20786 - rt->ant_obj = fwd_val(ctx, rt->ant_obj); 20787 - } 20788 - 20771 + 20772 + if (rt && rt->js == js) FWD_VAL(rt->ant_obj); 20773 + 20789 20774 proxy_data_t *proxy, *proxy_tmp; 20790 - proxy_data_t *new_proxy_registry = NULL; 20791 - HASH_ITER(hh, proxy_registry, proxy, proxy_tmp) { 20792 - HASH_DEL(proxy_registry, proxy); 20793 - proxy->obj_offset = fwd_off(ctx, proxy->obj_offset); 20794 - proxy->target = fwd_val(ctx, proxy->target); 20795 - proxy->handler = fwd_val(ctx, proxy->handler); 20796 - HASH_ADD(hh, new_proxy_registry, obj_offset, sizeof(jsoff_t), proxy); 20797 - } 20798 - proxy_registry = new_proxy_registry; 20799 - 20775 + REHASH_REGISTRY(proxy_registry, proxy, proxy_tmp, new_proxy, obj_offset, sizeof(jsoff_t), { 20776 + FWD_OFF(proxy->obj_offset); 20777 + FWD_VAL(proxy->target); 20778 + FWD_VAL(proxy->handler); 20779 + }); 20780 + 20800 20781 dynamic_accessors_t *acc, *acc_tmp; 20801 - dynamic_accessors_t *new_accessor_registry = NULL; 20802 - HASH_ITER(hh, accessor_registry, acc, acc_tmp) { 20803 - HASH_DEL(accessor_registry, acc); 20804 - acc->obj_offset = fwd_off(ctx, acc->obj_offset); 20805 - HASH_ADD(hh, new_accessor_registry, obj_offset, sizeof(jsoff_t), acc); 20806 - } 20807 - accessor_registry = new_accessor_registry; 20808 - 20782 + REHASH_REGISTRY(accessor_registry, acc, acc_tmp, new_acc, obj_offset, sizeof(jsoff_t), { 20783 + FWD_OFF(acc->obj_offset); 20784 + }); 20785 + 20809 20786 descriptor_entry_t *desc, *desc_tmp; 20810 - descriptor_entry_t *new_desc_registry = NULL; 20811 - HASH_ITER(hh, desc_registry, desc, desc_tmp) { 20812 - HASH_DEL(desc_registry, desc); 20813 - 20814 - if (desc->has_getter) desc->getter = fwd_val(ctx, desc->getter); 20815 - if (desc->has_setter) desc->setter = fwd_val(ctx, desc->setter); 20816 - 20817 - jsoff_t old_obj_off = (jsoff_t)(desc->key >> 32); 20818 - uint32_t key_hash = (uint32_t)(desc->key & 0xFFFFFFFF); 20819 - jsoff_t new_obj_off = fwd_off(ctx, old_obj_off); 20820 - desc->key = ((uint64_t)new_obj_off << 32) | key_hash; 20821 - 20822 - HASH_ADD(hh, new_desc_registry, key, sizeof(uint64_t), desc); 20823 - } 20824 - desc_registry = new_desc_registry; 20825 - 20787 + REHASH_REGISTRY(desc_registry, desc, desc_tmp, new_desc, key, sizeof(uint64_t), { 20788 + if (desc->has_getter) FWD_VAL(desc->getter); 20789 + if (desc->has_setter) FWD_VAL(desc->setter); 20790 + jsoff_t obj_off = fwd_off(ctx, (jsoff_t)(desc->key >> 32)); 20791 + desc->key = ((uint64_t)obj_off << 32) | (uint32_t)(desc->key & 0xFFFFFFFF); 20792 + }); 20793 + 20826 20794 for (coroutine_t *coro = pending_coroutines.head; coro; coro = coro->next) { 20827 - coro->scope = fwd_val(ctx, coro->scope); 20828 - coro->this_val = fwd_val(ctx, coro->this_val); 20829 - coro->awaited_promise = fwd_val(ctx, coro->awaited_promise); 20830 - coro->result = fwd_val(ctx, coro->result); 20831 - coro->async_func = fwd_val(ctx, coro->async_func); 20832 - coro->yield_value = fwd_val(ctx, coro->yield_value); 20833 - 20795 + FWD_VAL(coro->scope); 20796 + FWD_VAL(coro->this_val); 20797 + FWD_VAL(coro->awaited_promise); 20798 + FWD_VAL(coro->result); 20799 + FWD_VAL(coro->async_func); 20800 + FWD_VAL(coro->yield_value); 20834 20801 if (coro->mco) { 20835 20802 async_exec_context_t *actx = (async_exec_context_t *)mco_get_user_data(coro->mco); 20836 20803 if (actx) { 20837 - actx->closure_scope = fwd_val(ctx, actx->closure_scope); 20838 - actx->result = fwd_val(ctx, actx->result); 20839 - actx->promise = fwd_val(ctx, actx->promise); 20804 + FWD_VAL(actx->closure_scope); 20805 + FWD_VAL(actx->result); 20806 + FWD_VAL(actx->promise); 20840 20807 } 20841 20808 } 20842 20809 } 20843 20810 20844 20811 esm_module_t *mod, *mod_tmp; 20845 20812 HASH_ITER(hh, global_module_cache.modules, mod, mod_tmp) { 20846 - mod->namespace_obj = fwd_val(ctx, mod->namespace_obj); 20847 - mod->default_export = fwd_val(ctx, mod->default_export); 20813 + FWD_VAL(mod->namespace_obj); 20814 + FWD_VAL(mod->default_export); 20848 20815 } 20849 20816 20850 20817 timer_gc_update_roots(fwd_val, ctx); ··· 20855 20822 map_registry_entry_t *map_reg, *map_reg_tmp; 20856 20823 HASH_ITER(hh, map_registry, map_reg, map_reg_tmp) { 20857 20824 if (map_reg->head && *map_reg->head) { 20858 - map_entry_t *entry, *entry_tmp; 20859 - HASH_ITER(hh, *map_reg->head, entry, entry_tmp) entry->value = fwd_val(ctx, entry->value); 20825 + map_entry_t *me, *me_tmp; 20826 + HASH_ITER(hh, *map_reg->head, me, me_tmp) FWD_VAL(me->value); 20860 20827 } 20861 20828 } 20862 20829 20863 20830 set_registry_entry_t *set_reg, *set_reg_tmp; 20864 20831 HASH_ITER(hh, set_registry, set_reg, set_reg_tmp) { 20865 20832 if (set_reg->head && *set_reg->head) { 20866 - set_entry_t *entry, *entry_tmp; 20867 - HASH_ITER(hh, *set_reg->head, entry, entry_tmp) entry->value = fwd_val(ctx, entry->value); 20833 + set_entry_t *se, *se_tmp; 20834 + HASH_ITER(hh, *set_reg->head, se, se_tmp) FWD_VAL(se->value); 20868 20835 } 20869 20836 } 20870 20837 20871 20838 memset(intern_prop_cache, 0, sizeof(intern_prop_cache)); 20872 20839 } 20840 + 20841 + #undef FWD_OFF 20842 + #undef FWD_VAL 20843 + #undef UTARRAY_EACH 20844 + #undef REHASH_REGISTRY 20873 20845 20874 20846 bool js_chkargs(jsval_t *args, int nargs, const char *spec) { 20875 20847 int i = 0, ok = 1;