@@ -72,6 +72,21 @@ void Console::sendToDevToolsFrontEnd(v8::Isolate* isolate, const std::string& me
72
72
v8_inspector::V8LogAgentImpl::EntryAdded (message, logLevel, ArgConverter::ConvertToString (frame->GetScriptNameOrSourceURL ()), frame->GetLineNumber ());
73
73
}
74
74
75
+ const v8::Local<v8::String> transformJSObject (v8::Isolate* isolate, v8::Local<v8::Object> object) {
76
+ auto objToString = object->ToString (isolate);
77
+ v8::Local<v8::String> resultString;
78
+
79
+ auto hasCustomToStringImplementation = !objToString->SameValue (ArgConverter::ConvertToV8String (isolate, " [object Object]" ));
80
+
81
+ if (hasCustomToStringImplementation) {
82
+ resultString = objToString;
83
+ } else {
84
+ resultString = JsonStringifyObject (isolate, object);
85
+ }
86
+
87
+ return resultString;
88
+ }
89
+
75
90
const std::string buildLogString (const v8::FunctionCallbackInfo<v8::Value>& info, int startingIndex = 0 ) {
76
91
auto isolate = info.GetIsolate ();
77
92
@@ -87,7 +102,8 @@ const std::string buildLogString(const v8::FunctionCallbackInfo<v8::Value>& info
87
102
info[i]->ToDetailString (isolate->GetCurrentContext ()).ToLocal (&argString);
88
103
} else if (info[i]->IsObject ()) {
89
104
v8::Local<v8::Object> obj = info[i].As <v8::Object>();
90
- argString = JsonStringifyObject (isolate, obj);
105
+
106
+ argString = transformJSObject (isolate, obj);
91
107
} else {
92
108
info[i]->ToDetailString (isolate->GetCurrentContext ()).ToLocal (&argString);
93
109
}
@@ -188,7 +204,9 @@ void Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
188
204
if (propIsFunction) {
189
205
ss << " ()" ;
190
206
} else if (propertyValue->IsObject ()) {
191
- std::string jsonStringifiedObject = ArgConverter::ConvertToString (JsonStringifyObject (isolate, propertyValue));
207
+ auto obj = propertyValue->ToObject (isolate);
208
+ auto objString = transformJSObject (isolate, obj);
209
+ std::string jsonStringifiedObject = ArgConverter::ConvertToString (objString);
192
210
// if object prints out as the error string for circular references, replace with #CR instead for brevity
193
211
if (jsonStringifiedObject.find (" circular structure" ) != std::string::npos) {
194
212
jsonStringifiedObject = " #CR" ;
0 commit comments