Skip to content

Commit

Permalink
Merge pull request #2322 from svaarala/fix-enum-assert-gh2315
Browse files Browse the repository at this point in the history
Fix hash part handling in enum sorting
  • Loading branch information
svaarala authored Jun 14, 2020
2 parents aa81a68 + 26706e2 commit 798d3a2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions releases/releases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1365,3 +1365,4 @@ duktape_releases:
- "Fix nested error handling bug for out-of-memory during error creation (GH-2278, GH-2290)"
- "Fix failing assert for CBOR.encode() when argument is a zero-size dynamic plain array (GH-2316, GH-2318)"
- "Fix pointer overflow in String.prototype.startsWith/endsWith() with certain arguments (GH-2320)"
- "Fix assertion failure and incorrect behavior in some enumeration cases involving inherited duplicate keys (GH-2322)"
7 changes: 7 additions & 0 deletions src-input/duk_hobject_enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ DUK_LOCAL void duk__sort_enum_keys_es6(duk_hthread *thr, duk_hobject *h_obj, duk
keys[idx_insert] = h_curr;
}
}

/* Entry part has been reordered now with no side effects.
* If the object has a hash part, it will now be incorrect
* and we need to rehash. Do that by forcing a resize to
* the current size.
*/
duk_hobject_resize_entrypart(thr, h_obj, DUK_HOBJECT_GET_ESIZE(h_obj));
}

/*
Expand Down
18 changes: 18 additions & 0 deletions tests/ecmascript/test-bug-assert-property-add-gh2315.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// https://github.com/svaarala/duktape/issues/2315

/*===
done
===*/

function main() {
var v1 = [13.37,13.37,13.37];
var v2 = [13.37];
var v3 = {a:v2,length:v2};
var v4 = v3;
v4.__proto__ = v1;
var v5 = v4.sort();
for (var v6 in v5) {
}
}
main();
print('done');

0 comments on commit 798d3a2

Please sign in to comment.