Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Backport ff0a97933 from V8
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeykuzmin committed May 24, 2018
1 parent 55087cf commit b2863b2
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
4 changes: 4 additions & 0 deletions patches/common/v8/.patches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ patches:
owners: alexeykuzmin
file: backport_39d546a.patch
description: Node 10.0.0 needs it.
-
owners: alexeykuzmin
file: backport_ff0a97933.patch
description: Node 10.2.0 needs it.
89 changes: 89 additions & 0 deletions patches/common/v8/backport_ff0a97933.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
ff0a979333408f544f081489411814b84df6e2d9
diff --git a/include/v8.h b/include/v8.h
index 07ee083695..a09932383f 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -3493,6 +3498,17 @@ class V8_EXPORT Object : public Value {
*/
V8_DEPRECATE_SOON("Keep track of isolate correctly", 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<Array> (without
+ * scheduling an exception).
+ */
+ MaybeLocal<Array> PreviewEntries(bool* is_key_value);
+
static Local<Object> New(Isolate* isolate);

V8_INLINE static Object* Cast(Value* obj);
diff --git a/src/api.cc b/src/api.cc
index e65f114edb..4302b6c604 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -9543,21 +9543,20 @@ int debug::EstimatedValueSize(Isolate* v8_isolate, v8::Local<v8::Value> value) {
return i::Handle<i::HeapObject>::cast(object)->Size();
}

-v8::MaybeLocal<v8::Array> debug::EntriesPreview(Isolate* v8_isolate,
- v8::Local<v8::Value> value,
- bool* is_key_value) {
- i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
- ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
- if (value->IsMap()) {
+v8::MaybeLocal<v8::Array> v8::Object::PreviewEntries(bool* is_key_value) {
+ if (IsMap()) {
*is_key_value = true;
- return value.As<Map>()->AsArray();
+ return Map::Cast(this)->AsArray();
}
- if (value->IsSet()) {
+ if (IsSet()) {
*is_key_value = false;
- return value.As<Set>()->AsArray();
+ return Set::Cast(this)->AsArray();
}

- i::Handle<i::Object> object = Utils::OpenHandle(*value);
+ i::Handle<i::JSReceiver> object = Utils::OpenHandle(this);
+ i::Isolate* isolate = object->GetIsolate();
+ Isolate* v8_isolate = reinterpret_cast<Isolate*>(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/src/debug/debug-interface.h b/src/debug/debug-interface.h
index 01124bf7fc..2210b4e87f 100644
--- a/src/debug/debug-interface.h
+++ b/src/debug/debug-interface.h
@@ -212,10 +212,6 @@ void ResetBlackboxedStateCache(Isolate* isolate,

int EstimatedValueSize(Isolate* isolate, v8::Local<v8::Value> value);

-v8::MaybeLocal<v8::Array> EntriesPreview(Isolate* isolate,
- v8::Local<v8::Value> value,
- bool* is_key_value);
-
enum Builtin {
kObjectKeys,
kObjectGetPrototypeOf,
diff --git a/src/inspector/v8-debugger.cc b/src/inspector/v8-debugger.cc
index 5dee98853b..28212a1993 100644
--- a/src/inspector/v8-debugger.cc
+++ b/src/inspector/v8-debugger.cc
@@ -29,8 +29,10 @@ v8::MaybeLocal<v8::Array> collectionsEntries(v8::Local<v8::Context> context,
v8::Isolate* isolate = context->GetIsolate();
v8::Local<v8::Array> entries;
bool isKeyValue = false;
- if (!v8::debug::EntriesPreview(isolate, value, &isKeyValue).ToLocal(&entries))
+ if (!value->IsObject() ||
+ !value.As<v8::Object>()->PreviewEntries(&isKeyValue).ToLocal(&entries)) {
return v8::MaybeLocal<v8::Array>();
+ }

v8::Local<v8::Array> wrappedEntries = v8::Array::New(isolate);
CHECK(!isKeyValue || wrappedEntries->Length() % 2 == 0);

0 comments on commit b2863b2

Please sign in to comment.