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

Unified Diff: src/runtime/runtime-array.cc

Issue 1817443003: Remove oob elements collected from the prototype chain by trimming in GetArrayKeys (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: addressed comment Created 4 years, 9 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 | « src/js/array.js ('k') | test/mjsunit/regress/get-array-keys-oob.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-array.cc
diff --git a/src/runtime/runtime-array.cc b/src/runtime/runtime-array.cc
index a0b3080a092a4a1fa910338cfb18914038e601e6..e4519cbb535b937081479f6ada2f94b6c33117b9 100644
--- a/src/runtime/runtime-array.cc
+++ b/src/runtime/runtime-array.cc
@@ -211,12 +211,19 @@ RUNTIME_FUNCTION(Runtime_GetArrayKeys) {
JSObject::CollectOwnElementKeys(current, &accumulator, ALL_PROPERTIES);
}
// Erase any keys >= length.
- // TODO(adamk): Remove this step when the contract of %GetArrayKeys
- // is changed to let this happen on the JS side.
Handle<FixedArray> keys = accumulator.GetKeys(KEEP_NUMBERS);
+ int j = 0;
for (int i = 0; i < keys->length(); i++) {
- if (NumberToUint32(keys->get(i)) >= length) keys->set_undefined(i);
+ if (NumberToUint32(keys->get(i)) >= length) continue;
+ if (i != j) keys->set(j, keys->get(i));
+ j++;
}
+
+ if (j != keys->length()) {
+ isolate->heap()->RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>(
+ *keys, keys->length() - j);
+ }
+
return *isolate->factory()->NewJSArrayWithElements(keys);
}
« no previous file with comments | « src/js/array.js ('k') | test/mjsunit/regress/get-array-keys-oob.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698