Skip to content

Commit fb26861

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 40c8bbe commit fb26861

File tree

5 files changed

+24
-16
lines changed

5 files changed

+24
-16
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# Reset this number to 0 on major V8 upgrades.
2929
# Increment by one for each non-official patch applied to deps/v8.
30-
'v8_embedder_string': '-node.4',
30+
'v8_embedder_string': '-node.5',
3131

3232
# Enable disassembler for `--print-code` v8 options
3333
'v8_enable_disassembler': 1,

deps/v8/include/v8.h

+11
Original file line numberDiff line numberDiff line change
@@ -3549,6 +3549,17 @@ class V8_EXPORT Object : public Value {
35493549
*/
35503550
Isolate* GetIsolate();
35513551

3552+
/**
3553+
* If this object is a Set, Map, WeakSet or WeakMap, this returns a
3554+
* representation of the elements of this object as an array.
3555+
* If this object is a SetIterator or MapIterator, this returns all
3556+
* elements of the underlying collection, starting at the iterator's current
3557+
* position.
3558+
* For other types, this will return an empty MaybeLocal<Array> (without
3559+
* scheduling an exception).
3560+
*/
3561+
MaybeLocal<Array> PreviewEntries(bool* is_key_value);
3562+
35523563
static Local<Object> New(Isolate* isolate);
35533564

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

deps/v8/src/api.cc

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

9638-
v8::MaybeLocal<v8::Array> debug::EntriesPreview(Isolate* v8_isolate,
9639-
v8::Local<v8::Value> value,
9640-
bool* is_key_value) {
9641-
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
9642-
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
9643-
if (value->IsMap()) {
9638+
v8::MaybeLocal<v8::Array> v8::Object::PreviewEntries(bool* is_key_value) {
9639+
if (IsMap()) {
96449640
*is_key_value = true;
9645-
return value.As<Map>()->AsArray();
9641+
return Map::Cast(this)->AsArray();
96469642
}
9647-
if (value->IsSet()) {
9643+
if (IsSet()) {
96489644
*is_key_value = false;
9649-
return value.As<Set>()->AsArray();
9645+
return Set::Cast(this)->AsArray();
96509646
}
96519647

9652-
i::Handle<i::Object> object = Utils::OpenHandle(*value);
9648+
i::Handle<i::JSReceiver> object = Utils::OpenHandle(this);
9649+
i::Isolate* isolate = object->GetIsolate();
9650+
Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate);
9651+
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
96539652
if (object->IsJSWeakCollection()) {
96549653
*is_key_value = object->IsJSWeakMap();
96559654
return Utils::ToLocal(i::JSWeakCollection::GetEntries(

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

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

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

215-
v8::MaybeLocal<v8::Array> EntriesPreview(Isolate* isolate,
216-
v8::Local<v8::Value> value,
217-
bool* is_key_value);
218-
219215
enum Builtin {
220216
kObjectKeys,
221217
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)