From 82368b32facec9639c02dc43f21d8194de64744c Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 18 May 2018 18:49:41 +0200 Subject: [PATCH] deps: cherry-pick ff0a9793334 from upstream V8 Original commit message: [api] Expose PreviewEntries as public API Turn `debug::EntriesPreview` into a public API. This is a straightforward approach to addressing nodejs/node#20409 (not relying on functionality behind `--allow-natives-syntax`) in Node.js. Refs: https://github.com/v8/v8/commit/ff0a979333408f544f081489411814b84df6e2d9 PR-URL: https://github.com/nodejs/node/pull/20719 Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Gus Caplan Reviewed-By: James M Snell Reviewed-By: Matteo Collina Reviewed-By: Ruben Bridgewater --- common.gypi | 2 +- deps/v8/include/v8.h | 11 +++++++++++ deps/v8/src/api.cc | 19 +++++++++---------- deps/v8/src/debug/debug-interface.h | 4 ---- deps/v8/src/inspector/v8-debugger.cc | 4 +++- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/common.gypi b/common.gypi index dff0f092ebe451..abad5d003c85f4 100644 --- a/common.gypi +++ b/common.gypi @@ -27,7 +27,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.4', + 'v8_embedder_string': '-node.5', # Enable disassembler for `--print-code` v8 options 'v8_enable_disassembler': 1, diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index c6e9250e4e938b..ed1a6d4af1ac02 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -3549,6 +3549,17 @@ class V8_EXPORT Object : public Value { */ Isolate* GetIsolate(); + /** + * If this object is a Set, Map, WeakSet or WeakMap, this returns a + * representation of the elements of this object as an array. + * If this object is a SetIterator or MapIterator, this returns all + * elements of the underlying collection, starting at the iterator's current + * position. + * For other types, this will return an empty MaybeLocal (without + * scheduling an exception). + */ + MaybeLocal PreviewEntries(bool* is_key_value); + static Local New(Isolate* isolate); V8_INLINE static Object* Cast(Value* obj); diff --git a/deps/v8/src/api.cc b/deps/v8/src/api.cc index 6dd669ee1133bf..25506d3930868d 100644 --- a/deps/v8/src/api.cc +++ b/deps/v8/src/api.cc @@ -9635,21 +9635,20 @@ int debug::EstimatedValueSize(Isolate* v8_isolate, v8::Local value) { return i::Handle::cast(object)->Size(); } -v8::MaybeLocal debug::EntriesPreview(Isolate* v8_isolate, - v8::Local value, - bool* is_key_value) { - i::Isolate* isolate = reinterpret_cast(v8_isolate); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); - if (value->IsMap()) { +v8::MaybeLocal v8::Object::PreviewEntries(bool* is_key_value) { + if (IsMap()) { *is_key_value = true; - return value.As()->AsArray(); + return Map::Cast(this)->AsArray(); } - if (value->IsSet()) { + if (IsSet()) { *is_key_value = false; - return value.As()->AsArray(); + return Set::Cast(this)->AsArray(); } - i::Handle object = Utils::OpenHandle(*value); + i::Handle object = Utils::OpenHandle(this); + i::Isolate* isolate = object->GetIsolate(); + Isolate* v8_isolate = reinterpret_cast(isolate); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); if (object->IsJSWeakCollection()) { *is_key_value = object->IsJSWeakMap(); return Utils::ToLocal(i::JSWeakCollection::GetEntries( diff --git a/deps/v8/src/debug/debug-interface.h b/deps/v8/src/debug/debug-interface.h index b3f3ad917c16f6..ec1a693550237a 100644 --- a/deps/v8/src/debug/debug-interface.h +++ b/deps/v8/src/debug/debug-interface.h @@ -212,10 +212,6 @@ void ResetBlackboxedStateCache(Isolate* isolate, int EstimatedValueSize(Isolate* isolate, v8::Local value); -v8::MaybeLocal EntriesPreview(Isolate* isolate, - v8::Local value, - bool* is_key_value); - enum Builtin { kObjectKeys, kObjectGetPrototypeOf, diff --git a/deps/v8/src/inspector/v8-debugger.cc b/deps/v8/src/inspector/v8-debugger.cc index 1cdbce27e63e0e..01e9acd9c9e6bd 100644 --- a/deps/v8/src/inspector/v8-debugger.cc +++ b/deps/v8/src/inspector/v8-debugger.cc @@ -29,8 +29,10 @@ v8::MaybeLocal collectionsEntries(v8::Local context, v8::Isolate* isolate = context->GetIsolate(); v8::Local entries; bool isKeyValue = false; - if (!v8::debug::EntriesPreview(isolate, value, &isKeyValue).ToLocal(&entries)) + if (!value->IsObject() || + !value.As()->PreviewEntries(&isKeyValue).ToLocal(&entries)) { return v8::MaybeLocal(); + } v8::Local wrappedEntries = v8::Array::New(isolate); CHECK(!isKeyValue || wrappedEntries->Length() % 2 == 0);