Skip to content

Commit 71a86fa

Browse files
authored
Merge pull request #77 from hkbinbin/setprop-bug-fix
Fix setprop bug
2 parents a9bb856 + a128ee2 commit 71a86fa

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

elk.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,11 @@ static jsval_t setprop(struct js *js, jsval_t obj, jsval_t k, jsval_t v) {
320320
memcpy(buf, &koff, sizeof(koff)); // Initialize prop data: copy key
321321
memcpy(buf + sizeof(koff), &v, sizeof(v)); // Copy value
322322
jsoff_t brk = js->brk | T_OBJ; // New prop offset
323-
memcpy(&js->mem[head], &brk, sizeof(brk)); // Repoint head to the new prop
324323
// printf("PROP: %u -> %u\n", b, brk);
325-
return mkentity(js, (b & ~3U) | T_PROP, buf, sizeof(buf)); // Create new prop
324+
jsval_t res = mkentity(js, (b & ~3U) | T_PROP, buf, sizeof(buf));
325+
if (!is_err(res))
326+
memcpy(&js->mem[head], &brk, sizeof(brk)); // Repoint head to the new prop
327+
return res;
326328
}
327329

328330
// Return T_OBJ/T_PROP/T_STR entity size based on the first word in memory

0 commit comments

Comments
 (0)