diff options
author | Michaël Zasso <targos@protonmail.com> | 2019-03-04 13:27:08 +0100 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2019-03-14 18:50:10 +0100 |
commit | cf649c9b0243612d4a75ad99c328c0feaed4c3b9 (patch) | |
tree | a3e6024b24f9c865b3f2bb513e55cead671f4281 /deps/v8/src/api.cc | |
parent | 44d5401b8d64161fb9d057c8ec47bbc917e87247 (diff) | |
download | android-node-v8-cf649c9b0243612d4a75ad99c328c0feaed4c3b9.tar.gz android-node-v8-cf649c9b0243612d4a75ad99c328c0feaed4c3b9.tar.bz2 android-node-v8-cf649c9b0243612d4a75ad99c328c0feaed4c3b9.zip |
deps: V8: cherry-pick 74571c8
Original commit message:
Fix preview of set entries
Set entries return an array with the value as first and second entry.
As such these are considered key value pairs to align with maps
entries iterator.
So far the return value was identical to the values iterator and that
is misleading.
This also adds tests to verify the results and improves the coverage
a tiny bit by testing different iterators.
Refs: https://github.com/nodejs/node/issues/24629
R=yangguo@chromium.org
Change-Id: I669a724bb4afaf5a713e468b1f51691d22c25253
Reviewed-on: https://chromium-review.googlesource.com/c/1350790
Commit-Queue: Yang Guo <yangguo@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59311}
Refs: https://github.com/v8/v8/commit/74571c80a945f2bdf4094a090410ae02b9a69af6
PR-URL: https://github.com/nodejs/node/pull/25852
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Diffstat (limited to 'deps/v8/src/api.cc')
-rw-r--r-- | deps/v8/src/api.cc | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/deps/v8/src/api.cc b/deps/v8/src/api.cc index b1f9c99860..77e7db3e3f 100644 --- a/deps/v8/src/api.cc +++ b/deps/v8/src/api.cc @@ -6958,6 +6958,11 @@ enum class MapAsArrayKind { kValues = i::JS_MAP_VALUE_ITERATOR_TYPE }; +enum class SetAsArrayKind { + kEntries = i::JS_SET_KEY_VALUE_ITERATOR_TYPE, + kValues = i::JS_SET_VALUE_ITERATOR_TYPE +}; + i::Handle<i::JSArray> MapAsArray(i::Isolate* isolate, i::Object table_obj, int offset, MapAsArrayKind kind) { i::Factory* factory = isolate->factory(); @@ -7067,13 +7072,14 @@ Maybe<bool> Set::Delete(Local<Context> context, Local<Value> key) { namespace { i::Handle<i::JSArray> SetAsArray(i::Isolate* isolate, i::Object table_obj, - int offset) { + int offset, SetAsArrayKind kind) { i::Factory* factory = isolate->factory(); i::Handle<i::OrderedHashSet> table(i::OrderedHashSet::cast(table_obj), isolate); // Elements skipped by |offset| may already be deleted. int capacity = table->UsedCapacity(); - int max_length = capacity - offset; + const bool collect_key_values = kind == SetAsArrayKind::kEntries; + int max_length = (capacity - offset) * (collect_key_values ? 2 : 1); if (max_length == 0) return factory->NewJSArray(0); i::Handle<i::FixedArray> result = factory->NewFixedArray(max_length); int result_index = 0; @@ -7084,6 +7090,7 @@ i::Handle<i::JSArray> SetAsArray(i::Isolate* isolate, i::Object table_obj, i::Object key = table->KeyAt(i); if (key == the_hole) continue; result->set(result_index++, key); + if (collect_key_values) result->set(result_index++, key); } } DCHECK_GE(max_length, result_index); @@ -7099,7 +7106,8 @@ Local<Array> Set::AsArray() const { i::Isolate* isolate = obj->GetIsolate(); LOG_API(isolate, Set, AsArray); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); - return Utils::ToLocal(SetAsArray(isolate, obj->table(), 0)); + return Utils::ToLocal( + SetAsArray(isolate, obj->table(), 0, SetAsArrayKind::kValues)); } @@ -9516,21 +9524,22 @@ v8::MaybeLocal<v8::Array> v8::Object::PreviewEntries(bool* is_key_value) { i::Handle<i::JSWeakCollection>::cast(object), 0)); } if (object->IsJSMapIterator()) { - i::Handle<i::JSMapIterator> iterator = - i::Handle<i::JSMapIterator>::cast(object); + i::Handle<i::JSMapIterator> it = i::Handle<i::JSMapIterator>::cast(object); MapAsArrayKind const kind = - static_cast<MapAsArrayKind>(iterator->map()->instance_type()); + static_cast<MapAsArrayKind>(it->map()->instance_type()); *is_key_value = kind == MapAsArrayKind::kEntries; - if (!iterator->HasMore()) return v8::Array::New(v8_isolate); - return Utils::ToLocal(MapAsArray(isolate, iterator->table(), - i::Smi::ToInt(iterator->index()), kind)); + if (!it->HasMore()) return v8::Array::New(v8_isolate); + return Utils::ToLocal( + MapAsArray(isolate, it->table(), i::Smi::ToInt(it->index()), kind)); } if (object->IsJSSetIterator()) { i::Handle<i::JSSetIterator> it = i::Handle<i::JSSetIterator>::cast(object); - *is_key_value = false; + SetAsArrayKind const kind = + static_cast<SetAsArrayKind>(it->map()->instance_type()); + *is_key_value = kind == SetAsArrayKind::kEntries; if (!it->HasMore()) return v8::Array::New(v8_isolate); return Utils::ToLocal( - SetAsArray(isolate, it->table(), i::Smi::ToInt(it->index()))); + SetAsArray(isolate, it->table(), i::Smi::ToInt(it->index()), kind)); } return v8::MaybeLocal<v8::Array>(); } |