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); |