diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-02-04 21:13:20 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-02-20 18:33:09 +0100 |
commit | e55764747094c8a8475a015ae4bee44f5de90858 (patch) | |
tree | 34a7c87008cc1b500947194570d31642cd78893c /deps/v8/src/api.cc | |
parent | 14c089b50e3163dc2fd13cec718d219183744709 (diff) | |
download | android-node-v8-e55764747094c8a8475a015ae4bee44f5de90858.tar.gz android-node-v8-e55764747094c8a8475a015ae4bee44f5de90858.tar.bz2 android-node-v8-e55764747094c8a8475a015ae4bee44f5de90858.zip |
deps: V8: backport 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/25941
Fixes: https://github.com/nodejs/node/issues/24629
Reviewed-By: Michaƫl Zasso <targos@protonmail.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 64676f06c1..09db471982 100644 --- a/deps/v8/src/api.cc +++ b/deps/v8/src/api.cc @@ -7028,6 +7028,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(); @@ -7137,13 +7142,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; @@ -7154,6 +7160,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); @@ -7169,7 +7176,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)); } @@ -9524,21 +9532,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>(); } |