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

Unified Diff: src/api.cc

Issue 1952093002: fix Set::AsArray to not leave undefined holes in output array (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 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 | src/objects.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 1203b01f33dfb8d46b2c1a974d589c4d8eaccf99..3a82d4539322d3984456b6aee0f09ef8735d4f9a 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -6493,14 +6493,18 @@ Local<Array> Set::AsArray() const {
LOG_API(isolate, "Set::AsArray");
ENTER_V8(isolate);
i::Handle<i::OrderedHashSet> table(i::OrderedHashSet::cast(obj->table()));
+ int capacity = table->UsedCapacity();
int length = table->NumberOfElements();
i::Handle<i::FixedArray> result = factory->NewFixedArray(length);
- for (int i = 0; i < length; ++i) {
+ int result_index = 0;
+ for (int i = 0; i < capacity; ++i) {
i::Object* key = table->KeyAt(i);
if (!key->IsTheHole()) {
- result->set(i, key);
+ result->set(result_index++, key);
}
}
+ DCHECK_EQ(result_index, result->length());
+ DCHECK_EQ(result_index, length);
i::Handle<i::JSArray> result_array =
factory->NewJSArrayWithElements(result, i::FAST_ELEMENTS, length);
return Utils::ToLocal(result_array);
« no previous file with comments | « no previous file | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698