Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Unified Diff: src/js/array.js

Issue 2664173002: Throw when a holey property is set in Array.sort (Closed)
Patch Set: Use preventExtensions for test Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/array-sort.js » ('j') | test/mjsunit/array-sort.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/array.js
diff --git a/src/js/array.js b/src/js/array.js
index fca75a3f65f85f32e3300f3669f056793fbf7973..2390cafd5350025b0ce7ada18babbd15a47edf0a 100644
--- a/src/js/array.js
+++ b/src/js/array.js
@@ -971,6 +971,22 @@ function InnerArraySort(array, length, comparefn) {
max_prototype_element = CopyFromPrototype(array, length);
}
+ if (!%object_is_extensible(array)) {
+ // If the array have holes in the middle of the array,
+ // hole indices can be defined while removing array holes.
+ var last_hole = -1;
+ var first_hole = -1;
+ for (var i = 0; i < length; i++) {
+ if (!HAS_OWN_PROPERTY(array, i)) {
+ if (first_hole == -1) first_hole = i;
+ last_hole = i;
+ }
+ }
+ if (last_hole != -1 && last_hole < length - 1) {
+ throw %make_type_error(kObjectNotExtensible, first_hole);
+ }
+ }
+
// %RemoveArrayHoles returns -1 if fast removal is not supported.
var num_non_undefined = %RemoveArrayHoles(array, length);
« no previous file with comments | « no previous file | test/mjsunit/array-sort.js » ('j') | test/mjsunit/array-sort.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698