@@ -25,7 +25,7 @@ void MetadataNode::Init()
2525}
2626
2727MetadataNode::MetadataNode (MetadataTreeNode *treeNode) :
28- m_treeNode(treeNode)
28+ m_treeNode(treeNode)
2929{
3030 uint8_t nodeType = s_metadataReader.GetNodeType (treeNode);
3131
@@ -42,9 +42,9 @@ MetadataNode::MetadataNode(MetadataTreeNode *treeNode) :
4242 bool isPrefix;
4343 auto impTypeName = s_metadataReader.ReadInterfaceImplementationTypeName (m_treeNode, isPrefix);
4444 m_implType = isPrefix
45- ? (impTypeName + m_name)
46- :
47- impTypeName;
45+ ? (impTypeName + m_name)
46+ :
47+ impTypeName;
4848 }
4949}
5050
@@ -274,6 +274,63 @@ void MetadataNode::ClassAccessorGetterCallback(Local<String> property, const Pro
274274 }
275275}
276276
277+ void MetadataNode::NullObjectAccessorGetterCallback (Local<String> property,const PropertyCallbackInfo<Value>& info)
278+ {
279+ try
280+ {
281+ DEBUG_WRITE (" NullObjectAccessorGetterCallback" );
282+ auto isolate = info.GetIsolate ();
283+
284+ auto thiz = info.This ();
285+ if ((thiz->GetHiddenValue (V8StringConstants::GetNullNodeName ())).IsEmpty ())
286+ {
287+ auto node = reinterpret_cast <MetadataNode*>(info.Data ().As <External>()->Value ());
288+ thiz->SetHiddenValue (V8StringConstants::GetNullNodeName (), External::New (isolate, node));
289+ auto funcTemplate = FunctionTemplate::New (isolate, MetadataNode::NullValueOfCallback);
290+ thiz->Delete (V8StringConstants::GetValueOf ());
291+ thiz->Set (V8StringConstants::GetValueOf (), funcTemplate->GetFunction ());
292+ }
293+
294+ info.GetReturnValue ().Set (thiz);
295+ }
296+ catch (NativeScriptException& e)
297+ {
298+ e.ReThrowToV8 ();
299+ }
300+ catch (std::exception e) {
301+ stringstream ss;
302+ ss << " Error: c++ exception: " << e.what () << endl;
303+ NativeScriptException nsEx (ss.str ());
304+ nsEx.ReThrowToV8 ();
305+ }
306+ catch (...) {
307+ NativeScriptException nsEx (std::string (" Error: c++ exception!" ));
308+ nsEx.ReThrowToV8 ();
309+ }
310+ }
311+
312+ void MetadataNode::NullValueOfCallback (const FunctionCallbackInfo<Value>& args) {
313+ try
314+ {
315+ auto isolate = args.GetIsolate ();
316+ args.GetReturnValue ().Set (Null (isolate));
317+ }
318+ catch (NativeScriptException& e)
319+ {
320+ e.ReThrowToV8 ();
321+ }
322+ catch (std::exception e) {
323+ stringstream ss;
324+ ss << " Error: c++ exception: " << e.what () << endl;
325+ NativeScriptException nsEx (ss.str ());
326+ nsEx.ReThrowToV8 ();
327+ }
328+ catch (...) {
329+ NativeScriptException nsEx (std::string (" Error: c++ exception!" ));
330+ nsEx.ReThrowToV8 ();
331+ }
332+ }
333+
277334void MetadataNode::FieldAccessorGetterCallback (Local<String> property, const PropertyCallbackInfo<Value>& info)
278335{
279336 try
@@ -356,28 +413,26 @@ void MetadataNode::SuperAccessorGetterCallback(Local<String> property, const Pro
356413 {
357414 auto thiz = info.This ();
358415 auto isolate = info.GetIsolate ();
359- auto k = ConvertToV8String (" supervalue" );
360- auto superValue = thiz->GetHiddenValue (k ).As <Object>();
416+ auto key = ConvertToV8String (" supervalue" );
417+ auto superValue = thiz->GetHiddenValue (key ).As <Object>();
361418 if (superValue.IsEmpty ())
362419 {
363420 auto runtime = Runtime::GetRuntime (isolate);
364421 auto objectManager = runtime->GetObjectManager ();
365422
366423 superValue = objectManager->GetEmptyObject (isolate);
367- bool d = superValue->Delete (ConvertToV8String ( " toString " ));
368- d = superValue->Delete (ConvertToV8String ( " valueOf " ));
424+ bool d = superValue->Delete (V8StringConstants::GetToString ( ));
425+ d = superValue->Delete (V8StringConstants::GetValueOf ( ));
369426 superValue->SetInternalField (static_cast <int >(ObjectManager::MetadataNodeKeys::CallSuper), True (isolate));
370427
371428 superValue->SetPrototype (thiz->GetPrototype ().As <Object>()->GetPrototype ().As <Object>()->GetPrototype ());
372- thiz->SetHiddenValue (k , superValue);
429+ thiz->SetHiddenValue (key , superValue);
373430 objectManager->CloneLink (thiz, superValue);
374431
375432 DEBUG_WRITE (" superValue.GetPrototype=%d" , superValue->GetPrototype ().As <Object>()->GetIdentityHash ());
376433
377434 auto node = GetInstanceMetadata (isolate, thiz);
378435 SetInstanceMetadata (isolate, superValue, node);
379-
380- thiz->SetHiddenValue (k, superValue);
381436 }
382437
383438 info.GetReturnValue ().Set (superValue);
@@ -404,8 +459,8 @@ Local<Function> MetadataNode::SetMembers(Isolate *isolate, Local<FunctionTemplat
404459
405460 return hasCustomMetadata
406461 ? SetMembersFromRuntimeMetadata (isolate, ctorFuncTemplate, prototypeTemplate, instanceMethodsCallbackData, baseInstanceMethodsCallbackData, treeNode)
407- :
408- SetMembersFromStaticMetadata (isolate, ctorFuncTemplate, prototypeTemplate, instanceMethodsCallbackData, baseInstanceMethodsCallbackData, treeNode);
462+ :
463+ SetMembersFromStaticMetadata (isolate, ctorFuncTemplate, prototypeTemplate, instanceMethodsCallbackData, baseInstanceMethodsCallbackData, treeNode);
409464}
410465
411466Local<Function> MetadataNode::SetMembersFromStaticMetadata (Isolate *isolate, Local<FunctionTemplate>& ctorFuncTemplate, Local<ObjectTemplate>& prototypeTemplate, vector<MethodCallbackData*>& instanceMethodsCallbackData, const vector<MethodCallbackData*>& baseInstanceMethodsCallbackData, MetadataTreeNode *treeNode)
@@ -443,7 +498,7 @@ Local<Function> MetadataNode::SetMembersFromStaticMetadata(Isolate *isolate, Loc
443498 auto itBegin = baseInstanceMethodsCallbackData.begin ();
444499 auto itEnd = baseInstanceMethodsCallbackData.end ();
445500 auto itFound = find_if (itBegin, itEnd, [&entry] (MethodCallbackData *x)
446- { return x->candidates .front ().name == entry.name ;});
501+ { return x->candidates .front ().name == entry.name ;});
447502 if (itFound != itEnd)
448503 {
449504 callbackData->parent = *itFound;
@@ -510,6 +565,11 @@ Local<Function> MetadataNode::SetMembersFromStaticMetadata(Isolate *isolate, Loc
510565 ctorFunction->SetAccessor (fieldName, FieldAccessorGetterCallback, FieldAccessorSetterCallback, fieldData, AccessControl::DEFAULT, PropertyAttribute::DontDelete);
511566 }
512567
568+ auto nullObjectName = V8StringConstants::GetNullObject ();
569+
570+ Local<Value> nullObjectData = External::New (isolate, this );
571+ ctorFunction->SetAccessor (nullObjectName, NullObjectAccessorGetterCallback, nullptr , nullObjectData);
572+
513573 SetClassAccessor (ctorFunction);
514574
515575 return ctorFunction;
@@ -563,7 +623,7 @@ Local<Function> MetadataNode::SetMembersFromRuntimeMetadata(Isolate *isolate, Lo
563623 auto itBegin = baseInstanceMethodsCallbackData.begin ();
564624 auto itEnd = baseInstanceMethodsCallbackData.end ();
565625 auto itFound = find_if (itBegin, itEnd, [&entry] (MethodCallbackData *x)
566- { return x->candidates .front ().name == entry.name ;});
626+ { return x->candidates .front ().name == entry.name ;});
567627 if (itFound != itEnd)
568628 {
569629 callbackData->parent = *itFound;
@@ -876,7 +936,7 @@ void MetadataNode::InterfaceConstructorCallback(const v8::FunctionCallbackInfo<v
876936 {
877937 if (!extendLocationFound)
878938 {
879- stringstream ss;
939+ stringstream ss;
880940 ss << " (InternalError): Invalid extend() call. No name specified for extend. Location: " << extendLocation.c_str ();
881941 throw NativeScriptException (ss.str ());
882942 }
@@ -988,6 +1048,7 @@ void MetadataNode::MethodCallback(const v8::FunctionCallbackInfo<v8::Value>& inf
9881048
9891049 auto callbackData = reinterpret_cast <MethodCallbackData*>(e->Value ());
9901050
1051+ // Number of arguments the method is invoked with
9911052 int argLength = info.Length ();
9921053
9931054 MetadataEntry *entry = nullptr ;
@@ -1002,17 +1063,20 @@ void MetadataNode::MethodCallback(const v8::FunctionCallbackInfo<v8::Value>& inf
10021063
10031064 className = &callbackData->node ->m_name ;
10041065
1066+ // Iterates through all methods and finds the best match based on the number of arguments
10051067 auto found = false ;
10061068 for (auto & c : candidates)
10071069 {
10081070 found = c.paramCount == argLength;
10091071 if (found)
10101072 {
10111073 entry = &c;
1074+ DEBUG_WRITE (" MetaDataEntry Method %s's signature is: %s" , entry->name .c_str (), entry->sig .c_str ());
10121075 break ;
10131076 }
10141077 }
10151078
1079+ // Iterates through the parent class's methods to find a good match
10161080 if (!found)
10171081 {
10181082 callbackData = callbackData->parent ;
@@ -1578,9 +1642,9 @@ MetadataEntry MetadataNode::GetChildMetadataForPackage(MetadataNode *node, const
15781642 bool isPrefix;
15791643 string declaringType = s_metadataReader.ReadInterfaceImplementationTypeName (treeNodeChild, isPrefix);
15801644 child.declaringType = isPrefix
1581- ? (declaringType + s_metadataReader.ReadTypeName (child.treeNode ))
1582- :
1583- declaringType;
1645+ ? (declaringType + s_metadataReader.ReadTypeName (child.treeNode ))
1646+ :
1647+ declaringType;
15841648 }
15851649 }
15861650 }
0 commit comments