28using protocol::Response;
29using protocol::Runtime::EntryPreview;
30using protocol::Runtime::ObjectPreview;
31using protocol::Runtime::PropertyPreview;
32using protocol::Runtime::RemoteObject;
34#if defined(V8_USE_ADDRESS_SANITIZER) && V8_OS_DARWIN
43 std::unique_ptr<protocol::Value>*
result);
47 std::unique_ptr<protocol::ListValue>*
result) {
48 std::unique_ptr<protocol::ListValue> inspectorArray =
49 protocol::ListValue::create();
50 uint32_t length = array->Length();
53 if (!array->Get(context,
i).ToLocal(&value))
54 return Response::InternalError();
55 std::unique_ptr<protocol::Value> element;
56 Response response =
toProtocolValue(context, value, maxDepth - 1, &element);
57 if (!response.IsSuccess())
return response;
58 inspectorArray->pushValue(std::move(element));
60 *
result = std::move(inspectorArray);
61 return Response::Success();
66 std::unique_ptr<protocol::DictionaryValue>*
result) {
67 std::unique_ptr<protocol::DictionaryValue> jsonObject =
68 protocol::DictionaryValue::create();
70 if (!object->GetOwnPropertyNames(context).ToLocal(&propertyNames))
71 return Response::InternalError();
72 uint32_t length = propertyNames->Length();
75 if (!propertyNames->Get(context,
i).ToLocal(&name))
76 return Response::InternalError();
77 if (name->IsString()) {
79 object->HasRealNamedProperty(context, name.As<
v8::String>());
85 if (!name->ToString(context).ToLocal(&propertyName))
continue;
87 if (!object->Get(context, name).ToLocal(&property))
88 return Response::InternalError();
89 if (property->IsUndefined())
continue;
90 std::unique_ptr<protocol::Value> propertyValue;
93 if (!response.IsSuccess())
return response;
95 std::move(propertyValue));
97 *
result = std::move(jsonObject);
98 return Response::Success();
102 double doubleValue) {
103 if (doubleValue >= std::numeric_limits<int>::min() &&
104 doubleValue <= std::numeric_limits<int>::max() &&
107 int intValue =
static_cast<int>(doubleValue);
108 if (intValue == doubleValue) {
109 return protocol::FundamentalValue::create(intValue);
112 return protocol::FundamentalValue::create(doubleValue);
117 std::unique_ptr<protocol::Value>*
result) {
119 return Response::ServerError(
"Object reference chain is too long");
121 if (value->IsNull() || value->IsUndefined()) {
122 *
result = protocol::Value::null();
123 return Response::Success();
125 if (value->IsBoolean()) {
128 return Response::Success();
130 if (value->IsNumber()) {
131 double doubleValue = value.As<
v8::Number>()->Value();
133 return Response::Success();
135 if (value->IsString()) {
136 *
result = protocol::StringValue::create(
138 return Response::Success();
140 if (value->IsArray()) {
142 std::unique_ptr<protocol::ListValue> list_result;
145 *
result = std::move(list_result);
148 if (value->IsObject()) {
150 std::unique_ptr<protocol::DictionaryValue> dict_result;
153 *
result = std::move(dict_result);
157 return Response::ServerError(
"Object couldn't be returned by value");
162 std::unique_ptr<protocol::Value>*
result) {
163 if (value->IsUndefined())
return Response::Success();
170const size_t kWasmPageSize = 64 * 1024;
173 return static_cast<V8InspectorImpl*
>(
181 V8InspectorImpl* inspector =
static_cast<V8InspectorImpl*
>(
184 InspectedContext* inspectedContext = inspector->getContext(contextId);
186 return inspectedContext->getInternalType(value.As<
v8::Object>());
189enum AbbreviateMode { kMiddle,
kEnd };
191String16 abbreviateString(
const String16& value, AbbreviateMode mode) {
192 const size_t maxLength = 100;
193 if (value.length() <= maxLength)
return value;
195 if (mode == kMiddle) {
197 value.substring(0, maxLength / 2), String16(&ellipsis, 1),
198 value.substring(value.length() - maxLength / 2 + 1));
222 if (value->IsUndefined())
return RemoteObject::TypeEnum::Undefined;
223 if (value->IsNull())
return RemoteObject::SubtypeEnum::Null;
224 if (value->IsBoolean()) {
225 return value.As<
v8::Boolean>()->Value() ?
"true" :
"false";
227 if (value->IsString()) {
235 String16Builder description;
236 description.append(
'/');
238 description.append(
'/');
249 return description.toString();
267 nameValue->IsString()) {
269 if (nameString->Length() > 0 &&
270 !nameString->StringEquals(
toV8String(isolate,
"Error"))) {
276 std::optional<String16>
stack;
279 if (object->Get(context,
toV8String(isolate,
"stack"))
281 stackValue->IsString()) {
282 String16 stackString =
284 size_t pos = stackString.find(
"\n at ");
286 stack = stackString.substring(
pos);
291 std::optional<String16> message;
294 if (object->Get(context,
toV8String(isolate,
"message"))
296 messageValue->IsString()) {
298 if (!msg.isEmpty()) message = msg;
302 String16 description =
name;
303 if (message.has_value() && message->length() > 0) {
304 description +=
": " + *message;
307 if (stack.has_value() && stack->length() > 0) {
308 description += *
stack;
320 if (target->IsObject()) {
322 "Proxy(", descriptionForObject(isolate, target.As<
v8::Object>()),
")");
324 return String16(
"Proxy");
344 if (!object->GetRealNamedProperty(context,
toV8String(isolate,
"description"))
351String16 descriptionForCollection(
v8::Isolate* isolate,
353 String16 className =
toProtocolString(isolate, object->GetConstructorName());
357#if V8_ENABLE_WEBASSEMBLY
358String16 descriptionForWasmValueObject(
371 if (object->GetRealNamedProperty(context,
toV8String(isolate,
"key"))
375 std::unique_ptr<ObjectPreview> preview;
377 wrapper->buildEntryPreview(context, &limit, &limit, &preview);
379 key = preview->getDescription(String16());
380 if (preview->getType() == RemoteObject::TypeEnum::String) {
388 if (object->GetRealNamedProperty(context,
toV8String(isolate,
"value"))
392 std::unique_ptr<ObjectPreview> preview;
394 wrapper->buildEntryPreview(context, &limit, &limit, &preview);
396 value = preview->getDescription(String16());
397 if (preview->getType() == RemoteObject::TypeEnum::String) {
404 return key.length() ? (
"{" +
key +
" => " + value +
"}") : value;
423 if (!object->GetRealNamedProperty(context,
toV8String(isolate,
"value"))
427 DCHECK(value->IsFunction());
428 return descriptionForFunction(value.As<
v8::Function>());
432 bool* unserializable) {
433 *unserializable =
true;
434 double rawValue = value->Value();
435 if (std::isnan(rawValue))
return "NaN";
436 if (rawValue == 0.0 && std::signbit(rawValue))
return "-0";
437 if (std::isinf(rawValue)) {
438 return std::signbit(rawValue) ?
"-Infinity" :
"Infinity";
440 *unserializable =
false;
444class ValueMirrorBase :
public ValueMirror {
457class PrimitiveValueMirror final :
public ValueMirrorBase {
460 const String16& type)
461 : ValueMirrorBase(isolate, value),
m_type(type) {}
463 Response buildRemoteObject(
465 std::unique_ptr<RemoteObject>*
result)
const override {
466 std::unique_ptr<protocol::Value> protocolValue;
469 *
result = RemoteObject::create()
471 .setValue(std::move(protocolValue))
473 if (value->IsNull()) (*result)->setSubtype(RemoteObject::SubtypeEnum::Null);
474 return Response::Success();
477 void buildEntryPreview(
479 std::unique_ptr<ObjectPreview>* preview)
const override {
482 ObjectPreview::create()
484 .setDescription(descriptionForPrimitiveType(context, value))
486 .setProperties(std::make_unique<protocol::Array<PropertyPreview>>())
489 (*preview)->setSubtype(RemoteObject::SubtypeEnum::Null);
492 void buildPropertyPreview(
494 std::unique_ptr<PropertyPreview>* preview)
const override {
496 *preview = PropertyPreview::create()
498 .setValue(abbreviateString(
499 descriptionForPrimitiveType(context, value), kMiddle))
503 (*preview)->setSubtype(RemoteObject::SubtypeEnum::Null);
506 Response buildDeepSerializedValue(
509 V8SerializationDuplicateTracker& duplicateTracker,
510 std::unique_ptr<protocol::DictionaryValue>*
result)
const override {
512 if (value->IsUndefined()) {
513 *
result = protocol::DictionaryValue::create();
514 (*result)->setString(
515 "type", protocol::Runtime::DeepSerializedValue::TypeEnum::Undefined);
516 return Response::Success();
518 if (value->IsNull()) {
519 *
result = protocol::DictionaryValue::create();
520 (*result)->setString(
521 "type", protocol::Runtime::DeepSerializedValue::TypeEnum::Null);
522 return Response::Success();
524 if (value->IsString()) {
525 *
result = protocol::DictionaryValue::create();
526 (*result)->setString(
527 "type", protocol::Runtime::DeepSerializedValue::TypeEnum::String);
530 return Response::Success();
532 if (value->IsBoolean()) {
533 *
result = protocol::DictionaryValue::create();
534 (*result)->setString(
535 "type", protocol::Runtime::DeepSerializedValue::TypeEnum::Boolean);
537 return Response::Success();
542 *
result = duplicateTracker.LinkExistingOrCreate(value, &isKnown);
544 return Response::Success();
547 (*result)->setString(
548 "type", protocol::Runtime::DeepSerializedValue::TypeEnum::Object);
549 return Response::Success();
557class NumberMirror final :
public ValueMirrorBase {
560 : ValueMirrorBase(isolate, value) {}
562 Response buildRemoteObject(
564 std::unique_ptr<RemoteObject>*
result)
const override {
567 bool unserializable =
false;
568 String16 descriptionValue = descriptionForNumber(value, &unserializable);
569 *
result = RemoteObject::create()
570 .setType(RemoteObject::TypeEnum::Number)
571 .setDescription(descriptionValue)
573 if (unserializable) {
574 (*result)->setUnserializableValue(descriptionValue);
576 (*result)->setValue(protocol::FundamentalValue::create(value->Value()));
578 return Response::Success();
580 void buildPropertyPreview(
582 std::unique_ptr<PropertyPreview>*
result)
const override {
585 bool unserializable =
false;
586 *
result = PropertyPreview::create()
588 .setType(RemoteObject::TypeEnum::Number)
589 .setValue(descriptionForNumber(value, &unserializable))
592 void buildEntryPreview(
594 std::unique_ptr<ObjectPreview>* preview)
const override {
597 bool unserializable =
false;
599 ObjectPreview::create()
600 .setType(RemoteObject::TypeEnum::Number)
601 .setDescription(descriptionForNumber(value, &unserializable))
603 .setProperties(std::make_unique<protocol::Array<PropertyPreview>>())
607 Response buildDeepSerializedValue(
610 V8SerializationDuplicateTracker& duplicateTracker,
611 std::unique_ptr<protocol::DictionaryValue>*
result)
const override {
612 *
result = protocol::DictionaryValue::create();
613 (*result)->setString(
614 "type", protocol::Runtime::DeepSerializedValue::TypeEnum::Number);
618 bool unserializable =
false;
619 String16 descriptionValue = descriptionForNumber(value, &unserializable);
620 if (unserializable) {
621 (*result)->setValue(
"value",
622 protocol::StringValue::create(descriptionValue));
626 return Response::Success();
630class BigIntMirror final :
public ValueMirrorBase {
633 : ValueMirrorBase(isolate, value) {}
635 Response buildRemoteObject(
637 std::unique_ptr<RemoteObject>*
result)
const override {
640 String16 description = descriptionForBigInt(context, value);
641 *
result = RemoteObject::create()
642 .setType(RemoteObject::TypeEnum::Bigint)
643 .setUnserializableValue(description)
644 .setDescription(abbreviateString(description, kMiddle))
646 return Response::Success();
650 const String16& name,
651 std::unique_ptr<protocol::Runtime::PropertyPreview>*
652 preview)
const override {
655 *preview = PropertyPreview::create()
657 .setType(RemoteObject::TypeEnum::Bigint)
658 .setValue(abbreviateString(
659 descriptionForBigInt(context, value), kMiddle))
665 std::unique_ptr<protocol::Runtime::ObjectPreview>*
666 preview)
const override {
670 ObjectPreview::create()
671 .setType(RemoteObject::TypeEnum::Bigint)
673 abbreviateString(descriptionForBigInt(context, value), kMiddle))
675 .setProperties(std::make_unique<protocol::Array<PropertyPreview>>())
679 Response buildDeepSerializedValue(
682 V8SerializationDuplicateTracker& duplicateTracker,
683 std::unique_ptr<protocol::DictionaryValue>*
result)
const override {
689 *
result = protocol::DictionaryValue::create();
690 (*result)->setString(
691 "type", protocol::Runtime::DeepSerializedValue::TypeEnum::Bigint);
693 (*result)->setValue(
"value", protocol::StringValue::create(
toProtocolString(
694 context->GetIsolate(), stringValue)));
695 return Response::Success();
699class SymbolMirror final :
public ValueMirrorBase {
702 : ValueMirrorBase(isolate, value) {}
704 Response buildRemoteObject(
706 std::unique_ptr<RemoteObject>*
result)
const override {
708 return Response::ServerError(
"Object couldn't be returned by value");
712 *
result = RemoteObject::create()
713 .setType(RemoteObject::TypeEnum::Symbol)
714 .setDescription(descriptionForSymbol(context, value))
716 return Response::Success();
720 const String16& name,
721 std::unique_ptr<protocol::Runtime::PropertyPreview>*
722 preview)
const override {
725 *preview = PropertyPreview::create()
727 .setType(RemoteObject::TypeEnum::Symbol)
728 .setValue(abbreviateString(
729 descriptionForSymbol(context, value), kEnd))
733 void buildEntryPreview(
735 std::unique_ptr<ObjectPreview>* preview)
const override {
739 ObjectPreview::create()
740 .setType(RemoteObject::TypeEnum::Symbol)
741 .setDescription(descriptionForSymbol(context, value))
743 .setProperties(std::make_unique<protocol::Array<PropertyPreview>>())
747 Response buildDeepSerializedValue(
750 V8SerializationDuplicateTracker& duplicateTracker,
751 std::unique_ptr<protocol::DictionaryValue>*
result)
const override {
754 *
result = duplicateTracker.LinkExistingOrCreate(value, &isKnown);
756 return Response::Success();
759 (*result)->setString(
760 "type", protocol::Runtime::DeepSerializedValue::TypeEnum::Symbol);
761 return Response::Success();
765class LocationMirror final :
public ValueMirrorBase {
767 static std::unique_ptr<LocationMirror> create(
769 return create(function, function->ScriptId(),
770 function->GetScriptLineNumber(),
771 function->GetScriptColumnNumber());
773 static std::unique_ptr<LocationMirror> createForGenerator(
777 if (!generatorObject->IsSuspended()) {
778 return create(generatorObject->Function());
781 if (!generatorObject->Script().ToLocal(&script))
return nullptr;
783 generatorObject->SuspendedLocation();
784 return create(value, script->Id(), suspendedLocation.
GetLineNumber(),
788 Response buildRemoteObject(
790 std::unique_ptr<RemoteObject>*
result)
const override {
791 auto location = protocol::DictionaryValue::create();
793 location->setInteger(
"lineNumber", m_lineNumber);
794 location->setInteger(
"columnNumber", m_columnNumber);
795 *
result = RemoteObject::create()
796 .setType(RemoteObject::TypeEnum::Object)
797 .setSubtype(
"internal#location")
798 .setDescription(
"Object")
799 .setValue(std::move(location))
801 return Response::Success();
804 Response buildDeepSerializedValue(
807 V8SerializationDuplicateTracker& duplicateTracker,
808 std::unique_ptr<protocol::DictionaryValue>*
result)
const override {
811 *
result = duplicateTracker.LinkExistingOrCreate(value, &isKnown);
813 return Response::Success();
816 (*result)->setString(
817 "type", protocol::Runtime::DeepSerializedValue::TypeEnum::Object);
818 return Response::Success();
823 int scriptId,
int lineNumber,
830 return std::unique_ptr<LocationMirror>(
831 new LocationMirror(value, scriptId, lineNumber, columnNumber));
836 : ValueMirrorBase(value->GetIsolate(), value),
846class FunctionMirror final :
public ValueMirrorBase {
849 : ValueMirrorBase(value->GetIsolate(), value) {}
851 Response buildRemoteObject(
853 std::unique_ptr<RemoteObject>*
result)
const override {
858 std::unique_ptr<protocol::Value> protocolValue;
860 if (!response.IsSuccess())
return response;
861 *
result = RemoteObject::create()
862 .setType(RemoteObject::TypeEnum::Function)
863 .setValue(std::move(protocolValue))
866 *
result = RemoteObject::create()
867 .setType(RemoteObject::TypeEnum::Function)
869 context->GetIsolate(), value->GetConstructorName()))
870 .setDescription(descriptionForFunction(value))
873 return Response::Success();
876 void buildPropertyPreview(
878 std::unique_ptr<PropertyPreview>*
result)
const override {
879 *
result = PropertyPreview::create()
881 .setType(RemoteObject::TypeEnum::Function)
882 .setValue(String16())
885 void buildEntryPreview(
887 std::unique_ptr<ObjectPreview>* preview)
const override {
891 ObjectPreview::create()
892 .setType(RemoteObject::TypeEnum::Function)
893 .setDescription(descriptionForFunction(value))
895 .setProperties(std::make_unique<protocol::Array<PropertyPreview>>())
899 Response buildDeepSerializedValue(
902 V8SerializationDuplicateTracker& duplicateTracker,
903 std::unique_ptr<protocol::DictionaryValue>*
result)
const override {
906 *
result = duplicateTracker.LinkExistingOrCreate(value, &isKnown);
908 return Response::Success();
911 (*result)->setString(
912 "type", protocol::Runtime::DeepSerializedValue::TypeEnum::Function);
913 return Response::Success();
919 if (object->IsArray()) {
920 *length =
object.As<
v8::Array>()->Length();
923 if (object->IsArgumentsObject()) {
930 ->GetOwnPropertyDescriptor(context,
toV8String(isolate,
"length"))
935 if (!lengthDescriptor->IsObject() ||
939 !lengthValue->IsUint32()) {
949 std::unique_ptr<ValueMirror> key;
950 std::unique_ptr<ValueMirror> value;
954 bool* overflow, std::vector<EntryMirror>* mirrors) {
955 bool isKeyValue =
false;
957 if (!object->PreviewEntries(&isKeyValue).ToLocal(&
entries))
return false;
958 for (uint32_t
i = 0;
i <
entries->Length();
i += isKeyValue ? 2 : 1) {
961 std::unique_ptr<ValueMirror> keyMirror;
962 if (isKeyValue &&
entries->Get(context,
i).ToLocal(&tmp)) {
965 std::unique_ptr<ValueMirror> valueMirror;
966 if (
entries->Get(context, isKeyValue ?
i + 1 :
i).ToLocal(&tmp)) {
971 if (mirrors->size() == limit) {
975 mirrors->emplace_back(
976 EntryMirror{std::move(keyMirror), std::move(valueMirror)});
978 return !mirrors->empty();
982class PreviewPropertyAccumulator :
public ValueMirror::PropertyAccumulator {
985 const std::vector<String16>& blocklist,
986 int skipIndex,
int* nameLimit,
int* indexLimit,
988 std::vector<PropertyMirror>* mirrors)
997 bool Add(PropertyMirror mirror)
override {
998 if (mirror.exception)
return true;
999 if ((!mirror.getter || !mirror.getter->v8Value(m_isolate)->IsFunction()) &&
1003 if (!mirror.isOwn && !mirror.isSynthetic)
return true;
1008 if (mirror.isIndex && m_skipIndex > 0) {
1010 if (m_skipIndex > 0)
return true;
1018 m_mirrors->push_back(std::move(mirror));
1034 int* indexLimit,
bool* overflow,
1035 std::vector<PropertyMirror>* properties) {
1036 std::vector<String16> blocklist;
1038 if (isArrayLike(context,
object, &length) || object->IsStringObject()) {
1039 blocklist.push_back(
"length");
1040#if V8_ENABLE_WEBASSEMBLY
1041 }
else if (v8::debug::WasmValueObject::IsWasmValueObject(
object)) {
1042 blocklist.push_back(
"type");
1045 auto clientSubtype = clientFor(context)->valueSubtype(
object);
1046 if (clientSubtype &&
toString16(clientSubtype->string()) ==
"array") {
1047 blocklist.push_back(
"length");
1050 if (object->IsArrayBuffer() || object->IsSharedArrayBuffer()) {
1051 blocklist.push_back(
"[[Int8Array]]");
1052 blocklist.push_back(
"[[Uint8Array]]");
1053 blocklist.push_back(
"[[Int16Array]]");
1054 blocklist.push_back(
"[[Int32Array]]");
1056 blocklist.push_back(
"constructor");
1057 int skipIndex =
object->IsStringObject()
1060 PreviewPropertyAccumulator accumulator(context->GetIsolate(), blocklist,
1061 skipIndex, nameLimit, indexLimit,
1062 overflow, properties);
1067void getInternalPropertiesForPreview(
1069 int* nameLimit,
bool* overflow,
1070 std::vector<InternalPropertyMirror>* properties) {
1071 std::vector<InternalPropertyMirror> mirrors;
1073 std::vector<String16> allowlist;
1074 if (object->IsBooleanObject() || object->IsNumberObject() ||
1075 object->IsStringObject() || object->IsSymbolObject() ||
1076 object->IsBigIntObject()) {
1077 allowlist.emplace_back(
"[[PrimitiveValue]]");
1078 }
else if (object->IsPromise()) {
1079 allowlist.emplace_back(
"[[PromiseState]]");
1080 allowlist.emplace_back(
"[[PromiseResult]]");
1081 }
else if (object->IsGeneratorObject()) {
1082 allowlist.emplace_back(
"[[GeneratorState]]");
1083 }
else if (object->IsWeakRef()) {
1084 allowlist.emplace_back(
"[[WeakRefTarget]]");
1086 for (
auto& mirror : mirrors) {
1087 if (std::find(allowlist.begin(), allowlist.end(), mirror.name) ==
1096 properties->push_back(std::move(mirror));
1100void getPrivatePropertiesForPreview(
1102 int* nameLimit,
bool* overflow,
1103 protocol::Array<PropertyPreview>* privateProperties) {
1104 std::vector<PrivatePropertyMirror> mirrors =
1107 for (
auto& mirror : mirrors) {
1108 std::unique_ptr<PropertyPreview> propertyPreview;
1110 mirror.value->buildPropertyPreview(context, mirror.name,
1113 propertyPreview = PropertyPreview::create()
1114 .setName(mirror.name)
1115 .setType(PropertyPreview::TypeEnum::Accessor)
1118 if (!propertyPreview)
continue;
1124 privateProperties->emplace_back(std::move(propertyPreview));
1128class ObjectMirror final :
public ValueMirrorBase {
1131 : ValueMirrorBase(value->GetIsolate(), value),
1135 const String16& description)
1136 : ValueMirrorBase(value->GetIsolate(), value),
1141 Response buildRemoteObject(
1143 std::unique_ptr<RemoteObject>*
result)
const override {
1147 std::unique_ptr<protocol::Value> protocolValue;
1149 if (!response.IsSuccess())
return response;
1150 *
result = RemoteObject::create()
1151 .setType(RemoteObject::TypeEnum::Object)
1152 .setValue(std::move(protocolValue))
1155 *
result = RemoteObject::create()
1156 .setType(RemoteObject::TypeEnum::Object)
1159 .setDescription(m_description)
1161 if (m_hasSubtype) (*result)->setSubtype(m_subtype);
1163 std::unique_ptr<ObjectPreview> previewValue;
1165 int indexLimit = 100;
1166 buildObjectPreview(context,
false, &nameLimit, &indexLimit,
1168 (*result)->setPreview(std::move(previewValue));
1171 return Response::Success();
1174 void buildObjectPreview(
1176 int* nameLimit,
int* indexLimit,
1177 std::unique_ptr<ObjectPreview>*
result)
const override {
1178 buildObjectPreviewInternal(context,
false ,
1179 generatePreviewForTable, nameLimit, indexLimit,
1183 void buildEntryPreview(
1185 std::unique_ptr<ObjectPreview>*
result)
const override {
1186 buildObjectPreviewInternal(context,
true ,
1191 void buildPropertyPreview(
1193 std::unique_ptr<PropertyPreview>*
result)
const override {
1194 *
result = PropertyPreview::create()
1196 .setType(RemoteObject::TypeEnum::Object)
1197 .setValue(abbreviateString(
1199 m_subtype == RemoteObject::SubtypeEnum::Regexp ? kMiddle
1202 if (m_hasSubtype) (*result)->setSubtype(m_subtype);
1205 Response buildDeepSerializedValue(
1208 V8SerializationDuplicateTracker& duplicateTracker,
1209 std::unique_ptr<protocol::DictionaryValue>*
result)
const override {
1214 *
result = duplicateTracker.LinkExistingOrCreate(value, &isKnown);
1216 return Response::Success();
1220 std::unique_ptr<v8_inspector::DeepSerializationResult>
1221 embedderDeepSerializedResult = clientFor(context)->deepSerialize(
1222 value, maxDepth, additionalParameters);
1223 if (embedderDeepSerializedResult) {
1226 if (!embedderDeepSerializedResult->isSuccess)
1227 return Response::ServerError(
1228 toString16(embedderDeepSerializedResult->errorMessage->string())
1231 (*result)->setString(
1234 embedderDeepSerializedResult->serializedValue->type->string()));
1236 if (embedderDeepSerializedResult->serializedValue->value.ToLocal(
1239 std::unique_ptr<protocol::Value> protocolValue;
1240 Response response =
toProtocolValue(context, v8Value, &protocolValue);
1241 if (!response.IsSuccess())
return response;
1242 (*result)->setValue(
"value", std::move(protocolValue));
1244 return Response::Success();
1249 additionalParameters,
1250 duplicateTracker, *(*
result));
1254 void buildObjectPreviewInternal(
1256 bool generatePreviewForTable,
int* nameLimit,
int* indexLimit,
1257 std::unique_ptr<ObjectPreview>*
result)
const {
1258 auto properties = std::make_unique<protocol::Array<PropertyPreview>>();
1259 std::unique_ptr<protocol::Array<EntryPreview>> entriesPreview;
1260 bool overflow =
false;
1263 while (value->IsProxy()) value = value.As<
v8::Proxy>()->GetTarget();
1265 if (value->IsObject() && !value->IsProxy()) {
1267 std::vector<InternalPropertyMirror> internalProperties;
1268 getInternalPropertiesForPreview(context, objectForPreview, nameLimit,
1269 &overflow, &internalProperties);
1270 for (
size_t i = 0;
i < internalProperties.
size(); ++
i) {
1271 std::unique_ptr<PropertyPreview> propertyPreview;
1272 internalProperties[
i].value->buildPropertyPreview(
1273 context, internalProperties[
i].name, &propertyPreview);
1274 if (propertyPreview) {
1275 properties->emplace_back(std::move(propertyPreview));
1279 getPrivatePropertiesForPreview(context, objectForPreview, nameLimit,
1280 &overflow, properties.get());
1282 std::vector<PropertyMirror> mirrors;
1283 if (getPropertiesForPreview(context, objectForPreview, nameLimit,
1284 indexLimit, &overflow, &mirrors)) {
1285 for (
size_t i = 0;
i < mirrors.size(); ++
i) {
1286 std::unique_ptr<PropertyPreview> preview;
1287 std::unique_ptr<ObjectPreview> valuePreview;
1288 if (mirrors[
i].value) {
1289 mirrors[
i].value->buildPropertyPreview(context, mirrors[
i].name,
1291 if (generatePreviewForTable) {
1292 int tableLimit = 1000;
1293 mirrors[
i].value->buildObjectPreview(context,
false, &tableLimit,
1294 &tableLimit, &valuePreview);
1297 preview = PropertyPreview::create()
1298 .setName(mirrors[
i].name)
1299 .setType(PropertyPreview::TypeEnum::Accessor)
1303 preview->setValuePreview(std::move(valuePreview));
1305 properties->emplace_back(std::move(preview));
1309 std::vector<EntryMirror>
entries;
1310 if (EntryMirror::getEntries(context, objectForPreview, 5, &overflow,
1315 entriesPreview = std::make_unique<protocol::Array<EntryPreview>>();
1316 for (
const auto& entry :
entries) {
1317 std::unique_ptr<ObjectPreview> valuePreview;
1318 entry.value->buildEntryPreview(context, nameLimit, indexLimit,
1320 if (!valuePreview)
continue;
1321 std::unique_ptr<ObjectPreview> keyPreview;
1323 entry.key->buildEntryPreview(context, nameLimit, indexLimit,
1325 if (!keyPreview)
continue;
1327 std::unique_ptr<EntryPreview> entryPreview =
1328 EntryPreview::create()
1329 .setValue(std::move(valuePreview))
1331 if (keyPreview) entryPreview->setKey(std::move(keyPreview));
1332 entriesPreview->emplace_back(std::move(entryPreview));
1337 *
result = ObjectPreview::create()
1338 .setType(RemoteObject::TypeEnum::Object)
1339 .setDescription(m_description)
1340 .setOverflow(overflow)
1341 .setProperties(std::move(properties))
1343 if (m_hasSubtype) (*result)->setSubtype(m_subtype);
1344 if (entriesPreview) (*result)->setEntries(std::move(entriesPreview));
1357 if (!data->GetRealNamedProperty(context,
toV8String(isolate,
"name"))
1362 if (!data->GetRealNamedProperty(context,
toV8String(isolate,
"object"))
1364 !object->IsObject()) {
1368 if (!
object.As<v8::Object>()->
Get(context, name).
ToLocal(&value))
return;
1369 info.GetReturnValue().Set(value);
1379 if (data->Set(context,
toV8String(isolate,
"name"), name).IsNothing()) {
1382 if (data->Set(context,
toV8String(isolate,
"object"),
object).IsNothing()) {
1396 if (info.Length() < 1)
return;
1401 if (!data->GetRealNamedProperty(context,
toV8String(isolate,
"name"))
1406 if (!data->GetRealNamedProperty(context,
toV8String(isolate,
"object"))
1408 !object->IsObject()) {
1411 if (!
object.As<v8::Object>()->Set(context, name, info[0]).IsNothing())
return;
1421 if (data->Set(context,
toV8String(isolate,
"name"), name).IsNothing()) {
1424 if (data->Set(context,
toV8String(isolate,
"object"),
object).IsNothing()) {
1442 if (!name->IsString())
return false;
1450 if (context->Global()
1451 ->GetRealNamedProperty(context,
toV8String(isolate,
"Request"))
1453 if (request->IsObject() &&
1455 .FromMaybe(
false)) {
1459 if (tryCatch.HasCaught()) tryCatch.Reset();
1462 if (context->Global()
1463 ->GetRealNamedProperty(context,
toV8String(isolate,
"Response"))
1465 if (response->IsObject() &&
1467 .FromMaybe(
false)) {
1481 bool ownProperties,
bool accessorPropertiesOnly,
1482 bool nonIndexedPropertiesOnly,
1493 if (!object->Get(context,
toV8String(isolate,
"object")).ToLocal(&value) ||
1494 !value->IsObject()) {
1502 if (!set->Add(context,
toV8String(isolate,
"length")).ToLocal(&set)) {
1508 nonIndexedPropertiesOnly);
1513 while (!iterator->Done()) {
1514 bool isOwn = iterator->is_own();
1515 if (!isOwn && ownProperties)
break;
1518 if (
result.IsNothing())
return false;
1520 if (!iterator->Advance().FromMaybe(
false)) {
1526 if (!set->Add(context, v8Name).ToLocal(&set))
return false;
1529 std::unique_ptr<ValueMirror> symbolMirror;
1530 if (v8Name->IsString()) {
1534 name = descriptionForSymbol(context, symbol);
1539 std::unique_ptr<ValueMirror> valueMirror;
1540 std::unique_ptr<ValueMirror> getterMirror;
1541 std::unique_ptr<ValueMirror> setterMirror;
1542 std::unique_ptr<ValueMirror> exceptionMirror;
1543 bool writable =
false;
1544 bool enumerable =
false;
1545 bool configurable =
false;
1547 bool isAccessorProperty =
false;
1549 if (!iterator->attributes().To(&attributes)) {
1553 if (iterator->is_native_accessor()) {
1554 if (iterator->has_native_getter()) {
1555 getterMirror = createNativeGetter(context,
object, v8Name);
1557 if (iterator->has_native_setter()) {
1558 setterMirror = createNativeSetter(context,
object, v8Name);
1563 isAccessorProperty = getterMirror || setterMirror;
1567 if (!iterator->descriptor().To(&descriptor)) {
1588 isAccessorProperty = getterMirror || setterMirror;
1589 if (name !=
"__proto__" && !getterFunction.
IsEmpty() &&
1591 !doesAttributeHaveObservableSideEffectOnGet(context,
object,
1595 if (object->Get(context, v8Name).ToLocal(&value)) {
1596 if (value->IsPromise() &&
1601 setterMirror =
nullptr;
1602 getterMirror =
nullptr;
1609 if (accessorPropertiesOnly && !isAccessorProperty)
continue;
1615 iterator->is_array_index(),
1616 isAccessorProperty && valueMirror,
1617 std::move(valueMirror),
1618 std::move(getterMirror),
1619 std::move(setterMirror),
1620 std::move(symbolMirror),
1621 std::move(exceptionMirror)};
1622 if (!accumulator->
Add(std::move(mirror)))
return true;
1624 if (!iterator->Advance().FromMaybe(
false)) {
1635 std::vector<InternalPropertyMirror>* mirrors) {
1640 if (object->IsFunction()) {
1642 auto location = LocationMirror::create(function);
1645 String16(
"[[FunctionLocation]]"), std::move(location)});
1647 if (function->IsGeneratorFunction()) {
1653 if (object->IsGeneratorObject()) {
1654 auto location = LocationMirror::createForGenerator(
object);
1657 String16(
"[[GeneratorLocation]]"), std::move(location)});
1665 for (uint32_t
i = 0;
i < properties->Length();
i += 2) {
1667 if (!properties->Get(context,
i).ToLocal(&name) || !name->IsString()) {
1672 if (!properties->Get(context,
i + 1).ToLocal(&value)) {
1680 std::move(wrapper)});
1689 bool accessorPropertiesOnly) {
1690 std::vector<PrivatePropertyMirror> mirrors;
1704 size_t len = values.size();
1705 for (
size_t i = 0;
i < len;
i++) {
1707 DCHECK(name->IsString());
1710 std::unique_ptr<ValueMirror> valueMirror;
1711 std::unique_ptr<ValueMirror> getterMirror;
1712 std::unique_ptr<ValueMirror> setterMirror;
1724 }
else if (accessorPropertiesOnly) {
1732 std::move(valueMirror), std::move(getterMirror),
1733 std::move(setterMirror)});
1741 auto descriptionForValueSubtype =
1742 clientFor(context)->descriptionForValueSubtype(context, value);
1743 if (descriptionForValueSubtype) {
1744 return std::make_unique<ObjectMirror>(
1745 value, subtype,
toString16(descriptionForValueSubtype->string()));
1747 if (subtype ==
"error") {
1748 return std::make_unique<ObjectMirror>(value,
1749 RemoteObject::SubtypeEnum::Error,
1750 descriptionForError(context, value));
1752 if (subtype ==
"array" && value->IsObject()) {
1756 if (value->Get(context,
toV8String(isolate,
"length"))
1757 .ToLocal(&lengthValue)) {
1758 if (lengthValue->IsInt32()) {
1759 return std::make_unique<ObjectMirror>(
1760 value, RemoteObject::SubtypeEnum::Array,
1761 descriptionForCollection(isolate, value,
1766 return std::make_unique<ObjectMirror>(
1767 value, descriptionForObject(context->GetIsolate(), value));
1773 if (value->IsNull()) {
1774 return std::make_unique<PrimitiveValueMirror>(
1775 isolate, value.As<
v8::Primitive>(), RemoteObject::TypeEnum::Object);
1777 if (value->IsBoolean()) {
1778 return std::make_unique<PrimitiveValueMirror>(
1779 isolate, value.As<
v8::Primitive>(), RemoteObject::TypeEnum::Boolean);
1781 if (value->IsNumber()) {
1782 return std::make_unique<NumberMirror>(isolate, value.As<
v8::Number>());
1784 if (value->IsString()) {
1785 return std::make_unique<PrimitiveValueMirror>(
1786 isolate, value.As<
v8::Primitive>(), RemoteObject::TypeEnum::String);
1788 if (value->IsBigInt()) {
1789 return std::make_unique<BigIntMirror>(isolate, value.As<
v8::BigInt>());
1791 if (value->IsSymbol()) {
1792 return std::make_unique<SymbolMirror>(isolate, value.As<
v8::Symbol>());
1794 if (value->IsUndefined()) {
1795 return std::make_unique<PrimitiveValueMirror>(
1796 isolate, value.As<
v8::Primitive>(), RemoteObject::TypeEnum::Undefined);
1798 if (!value->IsObject()) {
1802 auto clientSubtype = clientFor(context)->valueSubtype(
object);
1803 if (clientSubtype) {
1807 if (object->IsRegExp()) {
1809 return std::make_unique<ObjectMirror>(
1810 regexp, RemoteObject::SubtypeEnum::Regexp,
1811 descriptionForRegExp(isolate, regexp));
1813 if (object->IsProxy()) {
1815 return std::make_unique<ObjectMirror>(proxy,
1816 RemoteObject::SubtypeEnum::Proxy,
1817 descriptionForProxy(isolate, proxy));
1819 if (object->IsFunction()) {
1821 return std::make_unique<FunctionMirror>(function);
1823 if (object->IsDate()) {
1825 return std::make_unique<ObjectMirror>(
date, RemoteObject::SubtypeEnum::Date,
1826 descriptionForDate(context,
date));
1828 if (object->IsPromise()) {
1830 return std::make_unique<ObjectMirror>(
1831 promise, RemoteObject::SubtypeEnum::Promise,
1832 descriptionForObject(isolate, promise));
1834 if (object->IsNativeError()) {
1835 return std::make_unique<ObjectMirror>(
object,
1836 RemoteObject::SubtypeEnum::Error,
1837 descriptionForError(context,
object));
1839 if (object->IsMap()) {
1841 return std::make_unique<ObjectMirror>(
1842 map, RemoteObject::SubtypeEnum::Map,
1843 descriptionForCollection(isolate, map, map->Size()));
1845 if (object->IsSet()) {
1847 return std::make_unique<ObjectMirror>(
1848 set, RemoteObject::SubtypeEnum::Set,
1849 descriptionForCollection(isolate, set, set->Size()));
1851 if (object->IsWeakMap()) {
1852 return std::make_unique<ObjectMirror>(
1853 object, RemoteObject::SubtypeEnum::Weakmap,
1854 descriptionForObject(isolate,
object));
1856 if (object->IsWeakSet()) {
1857 return std::make_unique<ObjectMirror>(
1858 object, RemoteObject::SubtypeEnum::Weakset,
1859 descriptionForObject(isolate,
object));
1861 if (object->IsMapIterator() || object->IsSetIterator()) {
1862 return std::make_unique<ObjectMirror>(
1863 object, RemoteObject::SubtypeEnum::Iterator,
1864 descriptionForObject(isolate,
object));
1866 if (object->IsGeneratorObject()) {
1867 return std::make_unique<ObjectMirror>(
1868 object, RemoteObject::SubtypeEnum::Generator,
1869 descriptionForObject(isolate,
object));
1871 if (object->IsTypedArray()) {
1873 return std::make_unique<ObjectMirror>(
1874 array, RemoteObject::SubtypeEnum::Typedarray,
1875 descriptionForCollection(isolate, array, array->Length()));
1877 if (object->IsArrayBuffer()) {
1879 return std::make_unique<ObjectMirror>(
1880 buffer, RemoteObject::SubtypeEnum::Arraybuffer,
1881 descriptionForCollection(isolate, buffer, buffer->ByteLength()));
1883 if (object->IsSharedArrayBuffer()) {
1886 return std::make_unique<ObjectMirror>(
1887 buffer, RemoteObject::SubtypeEnum::Arraybuffer,
1888 descriptionForCollection(isolate, buffer, buffer->ByteLength()));
1890 if (object->IsDataView()) {
1892 return std::make_unique<ObjectMirror>(
1893 view, RemoteObject::SubtypeEnum::Dataview,
1894 descriptionForCollection(isolate, view, view->ByteLength()));
1896 if (object->IsWasmMemoryObject()) {
1898 return std::make_unique<ObjectMirror>(
1899 memory, RemoteObject::SubtypeEnum::Webassemblymemory,
1900 descriptionForCollection(
1901 isolate, memory, memory->Buffer()->ByteLength() / kWasmPageSize));
1903#if V8_ENABLE_WEBASSEMBLY
1904 if (v8::debug::WasmValueObject::IsWasmValueObject(
object)) {
1906 object.
As<v8::debug::WasmValueObject>();
1907 return std::make_unique<ObjectMirror>(
1908 value_object, RemoteObject::SubtypeEnum::Wasmvalue,
1909 descriptionForWasmValueObject(context, value_object));
1912 if (!value->IsObject()) {
1918 return std::make_unique<ObjectMirror>(array,
"internal#scopeList",
1919 descriptionForScopeList(array));
1923 return std::make_unique<ObjectMirror>(
1924 array,
"internal#privateMethodList",
1925 descriptionForPrivateMethodList(array));
1928 return std::make_unique<ObjectMirror>(
object,
"internal#entry",
1929 descriptionForEntry(context,
object));
1932 return std::make_unique<ObjectMirror>(
object,
"internal#scope",
1933 descriptionForScope(context,
object));
1936 return std::make_unique<ObjectMirror>(
1937 object,
"internal#privateMethod",
1938 descriptionForPrivateMethod(context,
object));
1941 if (isArrayLike(context,
object, &length)) {
1942 return std::make_unique<ObjectMirror>(
1943 object, RemoteObject::SubtypeEnum::Array,
1944 descriptionForCollection(isolate,
object, length));
1946 return std::make_unique<ObjectMirror>(
object,
1947 descriptionForObject(isolate,
object));
static MaybeLocal< Function > New(Local< Context > context, FunctionCallback callback, Local< Value > data=Local< Value >(), int length=0, ConstructorBehavior behavior=ConstructorBehavior::kAllow, SideEffectType side_effect_type=SideEffectType::kHasSideEffect)
static const int kLineOffsetNotFound
V8_INLINE Local< S > As() const
V8_INLINE T FromJust() const &
V8_INLINE bool IsNothing() const
static Local< Object > New(Isolate *isolate)
V8_WARN_UNUSED_RESULT MaybeLocal< Value > Get(Local< Context > context, Local< Value > key)
V8_INLINE Local< T > Get(Isolate *isolate) const
static Local< Set > New(Isolate *isolate)
bool StringEquals(Local< String > str) const
Local< Value > Exception() const
static const int kNoScriptId
V8_INLINE bool IsEmpty() const
static bool IsAccessorPair(v8::Local< v8::Value > obj)
static v8::Local< debug::GeneratorObject > Cast(v8::Local< v8::Value > value)
int GetColumnNumber() const
int GetLineNumber() const
static V8_WARN_UNUSED_RESULT std::unique_ptr< PropertyIterator > Create(v8::Local< v8::Context > context, v8::Local< v8::Object > object, bool skip_indices=false)
static String16 fromInteger(int)
static String16 concat(T... args)
static String16 fromDouble(double)
V8_EXPORT std::string utf8() const
static const size_t kNotFound
v8::MaybeLocal< v8::Array > internalProperties(v8::Local< v8::Context >, v8::Local< v8::Value >)
static protocol::Response serializeV8Value(v8::Local< v8::Object > value, v8::Local< v8::Context > context, int maxDepth, v8::Local< v8::Object > additionalParameters, V8SerializationDuplicateTracker &duplicateTracker, protocol::DictionaryValue &result)
virtual bool Add(PropertyMirror mirror)=0
static std::unique_ptr< ValueMirror > create(v8::Local< v8::Context > context, v8::Local< v8::Value > value)
static bool getProperties(v8::Local< v8::Context > context, v8::Local< v8::Object > object, bool ownProperties, bool accessorPropertiesOnly, bool nonIndexedPropertiesOnly, PropertyAccumulator *accumulator)
static void getInternalProperties(v8::Local< v8::Context > context, v8::Local< v8::Object > object, std::vector< InternalPropertyMirror > *mirrors)
static std::vector< PrivatePropertyMirror > getPrivateProperties(v8::Local< v8::Context > context, v8::Local< v8::Object > object, bool accessorPropertiesOnly)
std::vector< PropertyMirror > * m_mirrors
ZoneVector< RpoNumber > & result
ZoneStack< RpoNumber > & stack
ZoneVector< Entry > entries
V8_INLINE Dest bit_cast(Source const &source)
void Add(RWDigits Z, Digits X, Digits Y)
bool GetPrivateMembers(Local< Context > context, Local< Object > object, int filter, LocalVector< Value > *names_out, LocalVector< Value > *values_out)
Local< String > GetDateDescription(Local< Date > date)
Local< String > GetFunctionDescription(Local< Function > function)
Local< String > GetBigIntStringValue(Isolate *isolate, Local< BigInt > bigint)
v8_inspector::V8Inspector * GetInspector(Isolate *isolate)
Local< String > GetBigIntDescription(Isolate *isolate, Local< BigInt > bigint)
V8_INLINE const Operation & Get(const Graph &graph, OpIndex index)
Response toProtocolValue(v8::Local< v8::Context > context, v8::Local< v8::Value > value, int maxDepth, std::unique_ptr< protocol::Value > *result)
String16 toProtocolString(v8::Isolate *isolate, v8::Local< v8::String > value)
Response objectToProtocolValue(v8::Local< v8::Context > context, v8::Local< v8::Object > object, int maxDepth, std::unique_ptr< protocol::DictionaryValue > *result)
std::unique_ptr< ValueMirror > clientMirror(v8::Local< v8::Context > context, v8::Local< v8::Object > value, const String16 &subtype)
v8::Local< v8::String > toV8String(v8::Isolate *isolate, const String16 &string)
String16 toProtocolStringWithTypeCheck(v8::Isolate *isolate, v8::Local< v8::Value > value)
String16 toString16(const StringView &string)
static const int kMaxProtocolDepth
Response arrayToProtocolValue(v8::Local< v8::Context > context, v8::Local< v8::Array > array, int maxDepth, std::unique_ptr< protocol::ListValue > *result)
V8_INLINE Local< Boolean > True(Isolate *isolate)
bool ToLocal(v8::internal::MaybeDirectHandle< v8::internal::Object > maybe, Local< T > *local)
#define DCHECK(condition)
v8::Local< v8::Value > value
v8::Local< v8::Value > set
v8::Local< v8::Value > get
v8::Global< v8::Value > m_value
std::unique_ptr< ValueMirror > value
std::vector< String16 > m_blocklist
std::unique_ptr< ValueMirror > key