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

Method PackageGetterCallback

test-app/runtime/src/main/cpp/MetadataNode.cpp:1412–1483  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1410}
1411
1412void MetadataNode::PackageGetterCallback(Local<Name> property, const PropertyCallbackInfo<Value>& info) {
1413 try {
1414 if (property.IsEmpty() || !property->IsString()) {
1415 return;
1416 }
1417
1418 auto strProperty = property.As<String>();
1419
1420 string propName = ArgConverter::ConvertToString(strProperty);
1421
1422 if (propName.empty()) {
1423 return;
1424 }
1425
1426 auto isolate = info.GetIsolate();
1427
1428 auto thiz = info.This();
1429
1430 Local<Value> hiddenVal;
1431 V8GetPrivateValue(isolate, thiz, strProperty, hiddenVal);
1432 auto cachedItem = hiddenVal;
1433
1434 if (cachedItem.IsEmpty()) {
1435 auto node = reinterpret_cast<MetadataNode*>(info.Data().As<External>()->Value());
1436
1437 uint8_t nodeType = s_metadataReader.GetNodeType(node->m_treeNode);
1438
1439 DEBUG_WRITE("MetadataNode::GetterCallback: prop '%s' for node '%s' called, nodeType=%d, hash=%d", propName.c_str(), node->m_treeNode->name.c_str(), nodeType, thiz.IsEmpty() ? -42 : thiz->GetIdentityHash());
1440
1441 auto child = GetChildMetadataForPackage(node, propName);
1442 auto foundChild = child.treeNode != nullptr;
1443
1444 if (foundChild) {
1445 auto childNode = MetadataNode::GetOrCreateInternal(child.treeNode);
1446 cachedItem = childNode->CreateWrapper(isolate);
1447
1448 uint8_t childNodeType = s_metadataReader.GetNodeType(child.treeNode);
1449 bool isInterface = s_metadataReader.IsNodeTypeInterface(childNodeType);
1450 if (isInterface) {
1451 // For all java interfaces we register the special Symbol.hasInstance property
1452 // which is invoked by the instanceof operator (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance).
1453 // For example:
1454 //
1455 // Object.defineProperty(android.view.animation.Interpolator, Symbol.hasInstance, {
1456 // value: function(obj) {
1457 // return true;
1458 // }
1459 // });
1460 RegisterSymbolHasInstanceCallback(isolate, child, cachedItem);
1461 }
1462
1463 V8SetPrivateValue(isolate, thiz, strProperty, cachedItem);
1464
1465 if (node->m_name == "org/json" && child.name == "JSONObject") {
1466 JSONObjectHelper::RegisterFromFunction(isolate, cachedItem);
1467 }
1468 }
1469 }

Callers

nothing calls this directly

Calls 14

IsStringMethod · 0.80
ThisMethod · 0.80
GetNodeTypeMethod · 0.80
CreateWrapperMethod · 0.80
GetReturnValueMethod · 0.80
ReThrowToV8Method · 0.80
IsEmptyMethod · 0.45
emptyMethod · 0.45
GetIsolateMethod · 0.45
ValueMethod · 0.45
DataMethod · 0.45
IsNodeTypeInterfaceMethod · 0.45

Tested by

no test coverage detected