Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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
    #20409
    (not relying on functionality behind `--allow-natives-syntax`)
    in Node.js.

Refs: v8/v8@ff0a979
  • Loading branch information
addaleax committed May 18, 2018
commit 0babe5ab6f08caa5bf25119bd475e2fe1d3b820a
11 changes: 11 additions & 0 deletions deps/v8/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -3503,6 +3503,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<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);
Expand Down
19 changes: 9 additions & 10 deletions deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9526,21 +9526,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(
Expand Down
4 changes: 0 additions & 4 deletions deps/v8/src/debug/debug-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,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,
Expand Down
4 changes: 3 additions & 1 deletion deps/v8/src/inspector/v8-debugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down