Skip to content

Commit e56716e

Browse files
addaleaxMylesBorins
authored andcommitted
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 PR-URL: #20719 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 4b64c84 commit e56716e

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

deps/v8/include/v8.h

+11
Original file line numberDiff line numberDiff line change
@@ -3503,6 +3503,17 @@ class V8_EXPORT Object : public Value {
35033503
*/
35043504
Isolate* GetIsolate();
35053505

3506+
/**
3507+
* If this object is a Set, Map, WeakSet or WeakMap, this returns a
3508+
* representation of the elements of this object as an array.
3509+
* If this object is a SetIterator or MapIterator, this returns all
3510+
* elements of the underlying collection, starting at the iterator's current
3511+
* position.
3512+
* For other types, this will return an empty MaybeLocal<Array> (without
3513+
* scheduling an exception).
3514+
*/
3515+
MaybeLocal<Array> PreviewEntries(bool* is_key_value);
3516+
35063517
static Local<Object> New(Isolate* isolate);
35073518

35083519
V8_INLINE static Object* Cast(Value* obj);

deps/v8/src/api.cc

+9-10
Original file line numberDiff line numberDiff line change
@@ -9526,21 +9526,20 @@ int debug::EstimatedValueSize(Isolate* v8_isolate, v8::Local<v8::Value> value) {
95269526
return i::Handle<i::HeapObject>::cast(object)->Size();
95279527
}
95289528

9529-
v8::MaybeLocal<v8::Array> debug::EntriesPreview(Isolate* v8_isolate,
9530-
v8::Local<v8::Value> value,
9531-
bool* is_key_value) {
9532-
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
9533-
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
9534-
if (value->IsMap()) {
9529+
v8::MaybeLocal<v8::Array> v8::Object::PreviewEntries(bool* is_key_value) {
9530+
if (IsMap()) {
95359531
*is_key_value = true;
9536-
return value.As<Map>()->AsArray();
9532+
return Map::Cast(this)->AsArray();
95379533
}
9538-
if (value->IsSet()) {
9534+
if (IsSet()) {
95399535
*is_key_value = false;
9540-
return value.As<Set>()->AsArray();
9536+
return Set::Cast(this)->AsArray();
95419537
}
95429538

9543-
i::Handle<i::Object> object = Utils::OpenHandle(*value);
9539+
i::Handle<i::JSReceiver> object = Utils::OpenHandle(this);
9540+
i::Isolate* isolate = object->GetIsolate();
9541+
Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate);
9542+
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
95449543
if (object->IsJSWeakCollection()) {
95459544
*is_key_value = object->IsJSWeakMap();
95469545
return Utils::ToLocal(i::JSWeakCollection::GetEntries(

deps/v8/src/debug/debug-interface.h

-4
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,6 @@ void ResetBlackboxedStateCache(Isolate* isolate,
204204

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

207-
v8::MaybeLocal<v8::Array> EntriesPreview(Isolate* isolate,
208-
v8::Local<v8::Value> value,
209-
bool* is_key_value);
210-
211207
enum Builtin {
212208
kObjectKeys,
213209
kObjectGetPrototypeOf,

deps/v8/src/inspector/v8-debugger.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ v8::MaybeLocal<v8::Array> collectionsEntries(v8::Local<v8::Context> context,
2929
v8::Isolate* isolate = context->GetIsolate();
3030
v8::Local<v8::Array> entries;
3131
bool isKeyValue = false;
32-
if (!v8::debug::EntriesPreview(isolate, value, &isKeyValue).ToLocal(&entries))
32+
if (!value->IsObject() ||
33+
!value.As<v8::Object>()->PreviewEntries(&isKeyValue).ToLocal(&entries)) {
3334
return v8::MaybeLocal<v8::Array>();
35+
}
3436

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

0 commit comments

Comments
 (0)