@@ -274,6 +274,41 @@ 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 node = reinterpret_cast <MetadataNode*>(info.Data ().As <External>()->Value ());
285+
286+ DEBUG_WRITE (" NullObjectAccessorGetterCallback node name: %s" , node->GetName ().c_str ());
287+
288+ Local<Object> value = Object::New (isolate);
289+ auto k = ConvertToV8String (" node" );
290+ value->SetHiddenValue (k, External::New (isolate, node));
291+ value->SetHiddenValue (ConvertToV8String (" isnull" ), Boolean::New (isolate, true ));
292+ // TODO: Pesho: Set .valueOf() callback to return null
293+
294+ info.GetReturnValue ().Set (value);
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+
277312void MetadataNode::FieldAccessorGetterCallback (Local<String> property, const PropertyCallbackInfo<Value>& info)
278313{
279314 try
@@ -510,6 +545,11 @@ Local<Function> MetadataNode::SetMembersFromStaticMetadata(Isolate *isolate, Loc
510545 ctorFunction->SetAccessor (fieldName, FieldAccessorGetterCallback, FieldAccessorSetterCallback, fieldData, AccessControl::DEFAULT, PropertyAttribute::DontDelete);
511546 }
512547
548+ auto nullObjectName = V8StringConstants::GetNullObject ();
549+
550+ Local<Value> nullObjectData = External::New (isolate, this );
551+ ctorFunction->SetAccessor (nullObjectName, NullObjectAccessorGetterCallback, nullptr , nullObjectData);
552+
513553 SetClassAccessor (ctorFunction);
514554
515555 return ctorFunction;
@@ -988,6 +1028,7 @@ void MetadataNode::MethodCallback(const v8::FunctionCallbackInfo<v8::Value>& inf
9881028
9891029 auto callbackData = reinterpret_cast <MethodCallbackData*>(e->Value ());
9901030
1031+ // Number of arguments the method is invoked with
9911032 int argLength = info.Length ();
9921033
9931034 MetadataEntry *entry = nullptr ;
@@ -1002,17 +1043,20 @@ void MetadataNode::MethodCallback(const v8::FunctionCallbackInfo<v8::Value>& inf
10021043
10031044 className = &callbackData->node ->m_name ;
10041045
1046+ // Iterates through all methods and finds the best match based on the number of arguments
10051047 auto found = false ;
10061048 for (auto & c : candidates)
10071049 {
10081050 found = c.paramCount == argLength;
10091051 if (found)
10101052 {
10111053 entry = &c;
1054+ DEBUG_WRITE (" MetaDataEntry Method %s's signature is: %s" , entry->name .c_str (), entry->sig .c_str ());
10121055 break ;
10131056 }
10141057 }
10151058
1059+ // Iterates through the parent class's methods to find a good match
10161060 if (!found)
10171061 {
10181062 callbackData = callbackData->parent ;
0 commit comments