@@ -72,105 +72,89 @@ void Console::sendToDevToolsFrontEnd(v8::Isolate* isolate, const std::string& me
72
72
}
73
73
}
74
74
75
- const v8::Local<v8::String> transformJSObject (v8::Isolate* isolate, v8::Local<v8::Object> object) {
75
+ std::string transformJSObject (v8::Isolate* isolate, v8::Local<v8::Object> object) {
76
76
auto context = isolate->GetCurrentContext ();
77
77
auto objToString = object->ToString (context).ToLocalChecked ();
78
- v8::Local<v8::String> resultString ;
78
+ auto objToCppString = ArgConverter::ConvertToString (objToString) ;
79
79
80
- auto hasCustomToStringImplementation = ArgConverter::ConvertToString (objToString) .find (" [object Object]" ) == std::string::npos;
80
+ auto hasCustomToStringImplementation = objToCppString .find (" [object Object]" ) == std::string::npos;
81
81
82
82
if (hasCustomToStringImplementation) {
83
- resultString = objToString ;
83
+ return objToCppString ;
84
84
} else {
85
- v8::HandleScope scope (isolate);
86
- resultString = JsonStringifyObject (isolate, object);
85
+ return JsonStringifyObject (isolate, object);
87
86
}
88
-
89
- return resultString;
90
87
}
91
88
92
- const v8::Local<v8::String> buildStringFromArg (v8::Isolate* isolate, const v8::Local<v8::Value>& val) {
93
- v8::Local<v8::String> argString;
89
+ std::string buildStringFromArg (v8::Isolate* isolate, const v8::Local<v8::Value>& val) {
94
90
if (val->IsFunction ()) {
95
- val->ToDetailString (isolate->GetCurrentContext ()).ToLocal (&argString);
91
+ auto v8FunctionString = val->ToDetailString (isolate->GetCurrentContext ()).ToLocalChecked ();
92
+ return ArgConverter::ConvertToString (v8FunctionString);
96
93
} else if (val->IsArray ()) {
97
94
auto context = isolate->GetCurrentContext ();
98
95
auto cachedSelf = val;
99
96
auto array = val->ToObject (context).ToLocalChecked ();
100
97
auto arrayEntryKeys = array->GetPropertyNames (isolate->GetCurrentContext ()).ToLocalChecked ();
101
98
102
99
auto arrayLength = arrayEntryKeys->Length ();
103
-
104
- argString = ArgConverter::ConvertToV8String (isolate, " [" );
100
+ std::string argString = " [" ;
105
101
106
102
for (int i = 0 ; i < arrayLength; i++) {
107
103
auto propertyName = arrayEntryKeys->Get (context, i).ToLocalChecked ();
108
-
109
104
auto propertyValue = array->Get (context, propertyName).ToLocalChecked ();
110
105
111
106
// avoid bottomless recursion with cyclic reference to the same array
112
107
if (propertyValue->StrictEquals (cachedSelf)) {
113
- argString = v8::String::Concat (isolate, argString, ArgConverter::ConvertToV8String (isolate, " [Circular]" ) );
108
+ argString. append ( " [Circular]" );
114
109
continue ;
115
110
}
116
111
117
112
auto objectString = buildStringFromArg (isolate, propertyValue);
118
-
119
- argString = v8::String::Concat (isolate, argString, objectString);
113
+ argString.append (objectString);
120
114
121
115
if (i != arrayLength - 1 ) {
122
- argString = v8::String::Concat (isolate, argString, ArgConverter::ConvertToV8String (isolate, " , " ) );
116
+ argString. append ( " , " );
123
117
}
124
118
}
125
119
126
- argString = v8::String::Concat (isolate, argString, ArgConverter::ConvertToV8String (isolate, " ]" ) );
120
+ return argString. append ( " ]" );
127
121
} else if (val->IsObject ()) {
128
122
v8::Local<v8::Object> obj = val.As <v8::Object>();
129
-
130
- argString = transformJSObject (isolate, obj);
123
+ return transformJSObject (isolate, obj);
131
124
} else {
132
- val->ToDetailString (isolate->GetCurrentContext ()).ToLocal (&argString);
125
+ auto v8DefaultToString = val->ToDetailString (isolate->GetCurrentContext ()).ToLocalChecked ();
126
+ return ArgConverter::ConvertToString (v8DefaultToString);
133
127
}
134
-
135
- return argString;
136
128
}
137
129
138
- const std::string buildLogString (const v8::FunctionCallbackInfo<v8::Value>& info, int startingIndex = 0 ) {
130
+ std::string buildLogString (const v8::FunctionCallbackInfo<v8::Value>& info, int startingIndex = 0 ) {
139
131
auto isolate = info.GetIsolate ();
140
-
141
132
v8::HandleScope scope (isolate);
142
-
143
133
std::stringstream ss;
144
134
145
135
auto argLen = info.Length ();
146
136
if (argLen) {
147
137
for (int i = startingIndex; i < argLen; i++) {
148
- v8::Local<v8::String> argString;
149
-
150
- argString = buildStringFromArg (isolate, info[i]);
151
-
152
138
// separate args with a space
153
139
if (i != 0 ) {
154
140
ss << " " ;
155
141
}
156
-
157
- ss << ArgConverter::ConvertToString (argString);
142
+
143
+ std::string argString = buildStringFromArg (isolate, info[i]);
144
+ ss << argString;
158
145
}
159
146
} else {
160
147
ss << std::endl;
161
148
}
162
149
163
- std::string stringResult = ss.str ();
164
-
165
- return stringResult;
150
+ return ss.str ();
166
151
}
167
152
168
153
void Console::assertCallback (const v8::FunctionCallbackInfo<v8::Value>& info) {
169
154
try {
170
155
auto isolate = info.GetIsolate ();
171
156
172
157
auto argLen = info.Length ();
173
- auto context = isolate->GetCurrentContext ();
174
158
auto expressionPasses = argLen && info[0 ]->BooleanValue (isolate);
175
159
176
160
if (!expressionPasses) {
@@ -307,13 +291,11 @@ void Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
307
291
if (propIsFunction) {
308
292
ss << " ()" ;
309
293
} else if (propertyValue->IsArray ()) {
310
- auto stringResult = buildStringFromArg (isolate, propertyValue);
311
- std::string jsonStringifiedArray = ArgConverter::ConvertToString (stringResult);
294
+ std::string jsonStringifiedArray = buildStringFromArg (isolate, propertyValue);
312
295
ss << " : " << jsonStringifiedArray;
313
296
} else if (propertyValue->IsObject ()) {
314
297
auto obj = propertyValue->ToObject (context).ToLocalChecked ();
315
- auto objString = transformJSObject (isolate, obj);
316
- std::string jsonStringifiedObject = ArgConverter::ConvertToString (objString);
298
+ auto jsonStringifiedObject = transformJSObject (isolate, obj);
317
299
// if object prints out as the error string for circular references, replace with #CR instead for brevity
318
300
if (jsonStringifiedObject.find (" circular structure" ) != std::string::npos) {
319
301
jsonStringifiedObject = " #CR" ;
0 commit comments