| 287 | } |
| 288 | |
| 289 | void Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 290 | try { |
| 291 | auto isolate = info.GetIsolate(); |
| 292 | auto context = isolate->GetCurrentContext(); |
| 293 | |
| 294 | v8::HandleScope scope(isolate); |
| 295 | |
| 296 | std::stringstream ss; |
| 297 | |
| 298 | auto argLen = info.Length(); |
| 299 | if (argLen) { |
| 300 | if (info[0]->IsObject()) { |
| 301 | ss << "==== object dump start ====" << std::endl; |
| 302 | v8::Local<v8::Object> argObject = info[0].As<v8::Object>(); |
| 303 | |
| 304 | v8::Local<v8::Array> propNames; |
| 305 | argObject->GetPropertyNames(context).ToLocal(&propNames); |
| 306 | |
| 307 | auto propertiesLen = propNames->Length(); |
| 308 | for (int i = 0; i < propertiesLen; i++) { |
| 309 | auto propertyName = propNames->Get(context, i).ToLocalChecked(); |
| 310 | auto propertyValue = argObject->Get(context, propertyName).ToLocalChecked(); |
| 311 | |
| 312 | auto propIsFunction = propertyValue->IsFunction(); |
| 313 | |
| 314 | ss << ArgConverter::ConvertToString(propertyName->ToString(context).ToLocalChecked()); |
| 315 | |
| 316 | if (propIsFunction) { |
| 317 | ss << "()"; |
| 318 | } else if (propertyValue->IsArray()) { |
| 319 | std::string jsonStringifiedArray = buildStringFromArg(isolate, propertyValue); |
| 320 | ss << ": " << jsonStringifiedArray; |
| 321 | } else if (propertyValue->IsObject()) { |
| 322 | auto obj = propertyValue->ToObject(context).ToLocalChecked(); |
| 323 | auto jsonStringifiedObject = transformJSObject(isolate, obj); |
| 324 | // if object prints out as the error string for circular references, replace with #CR instead for brevity |
| 325 | if (jsonStringifiedObject.find("circular structure") != std::string::npos) { |
| 326 | jsonStringifiedObject = "#CR"; |
| 327 | } |
| 328 | ss << ": " << jsonStringifiedObject; |
| 329 | } else { |
| 330 | ss << ": \"" << ArgConverter::ConvertToString(propertyValue->ToDetailString(context).ToLocalChecked()) << "\""; |
| 331 | } |
| 332 | |
| 333 | ss << std::endl; |
| 334 | } |
| 335 | |
| 336 | ss << "==== object dump end ====" << std::endl; |
| 337 | } else { |
| 338 | std::string logString = buildLogString(info); |
| 339 | |
| 340 | ss << logString; |
| 341 | } |
| 342 | } else { |
| 343 | ss << std::endl; |
| 344 | } |
| 345 | |
| 346 | std::string log = ss.str(); |
nothing calls this directly
no test coverage detected