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.

feat: support propref delete and update class ctor defaults

+76 -18
+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.22') 77 + version_conf.set('ANT_VERSION', '0.1.0.23') 78 78 version_conf.set('ANT_GIT_HASH', git_hash) 79 79 version_conf.set('ANT_BUILD_DATE', build_date) 80 80
+75 -17
src/ant.c
··· 5511 5511 uint8_t save_tok = js->tok; 5512 5512 jsval_t operand = js_postfix(js); 5513 5513 if (js->flags & F_NOEXEC) return js_mktrue(); 5514 + 5515 + if (vtype(operand) == T_PROPREF) { 5516 + jsoff_t obj_off = propref_obj(operand); 5517 + jsoff_t key_off = propref_key(operand); 5518 + jsval_t obj = mkval(T_OBJ, obj_off); 5519 + jsval_t key = mkval(T_STR, key_off); 5520 + jsoff_t len; 5521 + const char *key_str = (const char *)&js->mem[vstr(js, key, &len)]; 5522 + jsoff_t prop_off = lkp(js, obj, key_str, len); 5523 + if (prop_off == 0) return js_mktrue(); 5524 + if (is_const_prop(js, prop_off)) { 5525 + return js_mkerr(js, "cannot delete constant property"); 5526 + } 5527 + jsoff_t first_prop = loadoff(js, obj_off) & ~(3U | CONSTMASK | GCMASK); 5528 + if (first_prop == prop_off) { 5529 + jsoff_t deleted_next = loadoff(js, prop_off) & ~(GCMASK | CONSTMASK); 5530 + jsoff_t current = loadoff(js, obj_off); 5531 + saveoff(js, obj_off, (deleted_next & ~3U) | (current & (GCMASK | CONSTMASK | 3U))); 5532 + saveoff(js, prop_off, loadoff(js, prop_off) | GCMASK); 5533 + invalidate_obj_cache(obj_off); 5534 + js_gc(js); 5535 + return js_mktrue(); 5536 + } 5537 + jsoff_t prev = first_prop; 5538 + while (prev != 0) { 5539 + jsoff_t next_prop = loadoff(js, prev) & ~(3U | CONSTMASK | GCMASK); 5540 + if (next_prop == prop_off) { 5541 + jsoff_t deleted_next = loadoff(js, prop_off) & ~(GCMASK | CONSTMASK); 5542 + jsoff_t current = loadoff(js, prev); 5543 + saveoff(js, prev, (deleted_next & ~3U) | (current & (GCMASK | CONSTMASK | 3U))); 5544 + saveoff(js, prop_off, loadoff(js, prop_off) | GCMASK); 5545 + invalidate_obj_cache(obj_off); 5546 + js_gc(js); 5547 + return js_mktrue(); 5548 + } 5549 + prev = next_prop; 5550 + } 5551 + return js_mktrue(); 5552 + } 5553 + 5514 5554 if (vtype(operand) != T_PROP) { 5515 5555 return js_mktrue(); 5516 5556 } ··· 5518 5558 if (is_const_prop(js, prop_off)) { 5519 5559 return js_mkerr(js, "cannot delete constant property"); 5520 5560 } 5521 - jsval_t owner_obj = js_mkundef(); 5561 + 5562 + jsoff_t owner_obj_off = 0; 5563 + jsoff_t prev_prop_off = 0; 5564 + bool is_first_prop = false; 5565 + 5522 5566 for (jsoff_t off = 0; off < js->brk;) { 5523 5567 jsoff_t v = loadoff(js, off); 5524 5568 jsoff_t cleaned = v & ~(GCMASK | CONSTMASK); ··· 5526 5570 if ((cleaned & 3) == T_OBJ) { 5527 5571 jsoff_t first_prop = cleaned & ~3U; 5528 5572 if (first_prop == prop_off) { 5529 - owner_obj = mkval(T_OBJ, off); 5573 + owner_obj_off = off; 5574 + is_first_prop = true; 5530 5575 break; 5531 5576 } 5532 - } else if ((cleaned & 3) == T_PROP) { 5533 - jsoff_t next_prop = cleaned & ~3U; 5534 - if (next_prop == prop_off) { 5535 - jsoff_t deleted_next = loadoff(js, prop_off) & ~(GCMASK | CONSTMASK); 5536 - jsoff_t current = loadoff(js, off); 5537 - saveoff(js, off, (deleted_next & ~3U) | (current & (GCMASK | CONSTMASK | 3U))); 5538 - saveoff(js, prop_off, loadoff(js, prop_off) | GCMASK); 5539 - js_gc(js); 5540 - return js_mktrue(); 5577 + jsoff_t cur_prop = first_prop; 5578 + while (cur_prop != 0 && cur_prop < js->brk) { 5579 + jsoff_t next = loadoff(js, cur_prop) & ~(GCMASK | CONSTMASK | 3U); 5580 + if (next == prop_off) { 5581 + owner_obj_off = off; 5582 + prev_prop_off = cur_prop; 5583 + break; 5584 + } 5585 + cur_prop = next; 5541 5586 } 5587 + if (owner_obj_off != 0) break; 5542 5588 } 5543 5589 off += n; 5544 5590 } 5545 - if (vtype(owner_obj) == T_OBJ) { 5546 - jsoff_t obj_off = (jsoff_t) vdata(owner_obj); 5547 - jsoff_t deleted_next = loadoff(js, prop_off) & ~(GCMASK | CONSTMASK); 5548 - jsoff_t current = loadoff(js, obj_off); 5549 - saveoff(js, obj_off, (deleted_next & ~3U) | (current & (GCMASK | CONSTMASK | 3U))); 5591 + 5592 + if (owner_obj_off != 0) { 5593 + if (is_first_prop) { 5594 + jsoff_t deleted_next = loadoff(js, prop_off) & ~(GCMASK | CONSTMASK); 5595 + jsoff_t current = loadoff(js, owner_obj_off); 5596 + saveoff(js, owner_obj_off, (deleted_next & ~3U) | (current & (GCMASK | CONSTMASK | 3U))); 5597 + } else { 5598 + jsoff_t deleted_next = loadoff(js, prop_off) & ~(GCMASK | CONSTMASK); 5599 + jsoff_t current = loadoff(js, prev_prop_off); 5600 + saveoff(js, prev_prop_off, (deleted_next & ~3U) | (current & (GCMASK | CONSTMASK | 3U))); 5601 + } 5550 5602 saveoff(js, prop_off, loadoff(js, prop_off) | GCMASK); 5603 + invalidate_obj_cache(owner_obj_off); 5551 5604 js_gc(js); 5552 5605 } 5553 5606 (void) save_pos; ··· 7494 7547 } else { 7495 7548 jsval_t code_key = js_mkstr(js, "__code", 6); 7496 7549 if (is_err(code_key)) return code_key; 7497 - jsval_t default_ctor = js_mkstr(js, "(){}", 4); 7550 + jsval_t default_ctor; 7551 + if (super_len > 0) { 7552 + default_ctor = js_mkstr(js, "(...args){super(...args);}", 26); 7553 + } else { 7554 + default_ctor = js_mkstr(js, "(){}", 4); 7555 + } 7498 7556 if (is_err(default_ctor)) return default_ctor; 7499 7557 jsval_t res2 = setprop(js, func_obj, code_key, default_ctor); 7500 7558 if (is_err(res2)) return res2;