Skip to content

Commit ff0a979

Browse files
addaleaxCommit Bot
authored andcommitted
[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: nodejs/node#20409 Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel Change-Id: I7021e5846012a55a82c488408ded6591f6b139e7 Reviewed-on: https://chromium-review.googlesource.com/1057467 Reviewed-by: Yang Guo <[email protected]> Commit-Queue: Yang Guo <[email protected]> Cr-Commit-Position: refs/heads/master@{#53226}
1 parent 1e8d963 commit ff0a979

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

include/v8.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3672,6 +3672,17 @@ class V8_EXPORT Object : public Value {
36723672
*/
36733673
Isolate* GetIsolate();
36743674

3675+
/**
3676+
* If this object is a Set, Map, WeakSet or WeakMap, this returns a
3677+
* representation of the elements of this object as an array.
3678+
* If this object is a SetIterator or MapIterator, this returns all
3679+
* elements of the underlying collection, starting at the iterator's current
3680+
* position.
3681+
* For other types, this will return an empty MaybeLocal<Array> (without
3682+
* scheduling an exception).
3683+
*/
3684+
MaybeLocal<Array> PreviewEntries(bool* is_key_value);
3685+
36753686
static Local<Object> New(Isolate* isolate);
36763687

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

src/api.cc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9543,21 +9543,20 @@ int debug::EstimatedValueSize(Isolate* v8_isolate, v8::Local<v8::Value> value) {
95439543
return i::Handle<i::HeapObject>::cast(object)->Size();
95449544
}
95459545

9546-
v8::MaybeLocal<v8::Array> debug::EntriesPreview(Isolate* v8_isolate,
9547-
v8::Local<v8::Value> value,
9548-
bool* is_key_value) {
9549-
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
9550-
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
9551-
if (value->IsMap()) {
9546+
v8::MaybeLocal<v8::Array> v8::Object::PreviewEntries(bool* is_key_value) {
9547+
if (IsMap()) {
95529548
*is_key_value = true;
9553-
return value.As<Map>()->AsArray();
9549+
return Map::Cast(this)->AsArray();
95549550
}
9555-
if (value->IsSet()) {
9551+
if (IsSet()) {
95569552
*is_key_value = false;
9557-
return value.As<Set>()->AsArray();
9553+
return Set::Cast(this)->AsArray();
95589554
}
95599555

9560-
i::Handle<i::Object> object = Utils::OpenHandle(*value);
9556+
i::Handle<i::JSReceiver> object = Utils::OpenHandle(this);
9557+
i::Isolate* isolate = object->GetIsolate();
9558+
Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate);
9559+
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
95619560
if (object->IsJSWeakCollection()) {
95629561
*is_key_value = object->IsJSWeakMap();
95639562
return Utils::ToLocal(i::JSWeakCollection::GetEntries(

src/debug/debug-interface.h

Lines changed: 0 additions & 4 deletions
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,

src/inspector/v8-debugger.cc

Lines changed: 3 additions & 1 deletion
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)