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

Method MethodCallback

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

Source from the content-addressed store, hash-verified

1211}
1212
1213void MetadataNode::MethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
1214 try {
1215 SET_PROFILER_FRAME();
1216
1217 auto e = info.Data().As<External>();
1218
1219 auto callbackData = reinterpret_cast<MethodCallbackData*>(e->Value());
1220 auto initialCallbackData = reinterpret_cast<MethodCallbackData*>(e->Value());
1221
1222 // Number of arguments the method is invoked with
1223 int argLength = info.Length();
1224
1225 MetadataEntry* entry = nullptr;
1226
1227 string* className;
1228 const auto& first = callbackData->candidates.front();
1229 const auto& methodName = first.name;
1230
1231 while ((callbackData != nullptr) && (entry == nullptr)) {
1232 auto& candidates = callbackData->candidates;
1233
1234 className = &callbackData->node->m_name;
1235
1236 // Iterates through all methods and finds the best match based on the number of arguments
1237 auto found = false;
1238 for (auto& c : candidates) {
1239 found = (!c.isExtensionFunction && c.getParamCount() == argLength) || (
1240 c.isExtensionFunction && c.getParamCount() == argLength + 1);
1241 if (found) {
1242 if(c.isExtensionFunction){
1243 className = &c.getDeclaringType();
1244 }
1245 entry = &c;
1246 DEBUG_WRITE("MetaDataEntry Method %s's signature is: %s", entry->name.c_str(), entry->getSig().c_str());
1247 break;
1248 }
1249 }
1250
1251 // Iterates through the parent class's methods to find a good match
1252 if (!found) {
1253 callbackData = callbackData->parent;
1254 }
1255 }
1256
1257 auto thiz = info.This();
1258
1259 auto isSuper = false;
1260 if (!first.isStatic) {
1261 auto superValue = thiz->GetInternalField(static_cast<int>(ObjectManager::MetadataNodeKeys::CallSuper));
1262 isSuper = !superValue.IsEmpty() && superValue->IsTrue();
1263 }
1264
1265 if ((argLength == 0) && (methodName == V8StringConstants::VALUE_OF)) {
1266 info.GetReturnValue().Set(thiz);
1267 } else {
1268 bool isFromInterface = initialCallbackData->node->IsNodeTypeInterface();
1269 CallbackHandlers::CallJavaMethod(thiz, *className, methodName, entry, isFromInterface, first.isStatic, isSuper, info);
1270 }

Callers

nothing calls this directly

Calls 13

frontMethod · 0.80
getParamCountMethod · 0.80
ThisMethod · 0.80
GetReturnValueMethod · 0.80
ReThrowToV8Method · 0.80
DataMethod · 0.45
ValueMethod · 0.45
LengthMethod · 0.45
GetInternalFieldMethod · 0.45
IsEmptyMethod · 0.45
SetMethod · 0.45
IsNodeTypeInterfaceMethod · 0.45

Tested by

no test coverage detected