MCPcopy Create free account
hub / github.com/NativeScript/android / dirCallback

Method dirCallback

test-app/runtime/src/main/cpp/console/Console.cpp:289–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

287}
288
289void 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();

Callers

nothing calls this directly

Calls 12

buildStringFromArgFunction · 0.85
transformJSObjectFunction · 0.85
buildLogStringFunction · 0.85
ToLocalMethod · 0.80
ToLocalCheckedMethod · 0.80
ReThrowToV8Method · 0.80
GetIsolateMethod · 0.45
LengthMethod · 0.45
GetMethod · 0.45
ToStringMethod · 0.45
findMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected