@@ -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
@@ -281,12 +281,14 @@ void MetadataNode::NullObjectAccessorGetterCallback(Local<String> property,const
281281 DEBUG_WRITE (" NullObjectAccessorGetterCallback" );
282282 auto isolate = info.GetIsolate ();
283283
284- // TODO: pete: Set .valueOf() callback to return null
285284 auto thiz = info.This ();
286- if (! (thiz->GetHiddenValue (V8StringConstants::GetNullNodeName ())).IsEmpty ())
285+ if ((thiz->GetHiddenValue (V8StringConstants::GetNullNodeName ())).IsEmpty ())
287286 {
288287 auto node = reinterpret_cast <MetadataNode*>(info.Data ().As <External>()->Value ());
289288 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 ());
290292 }
291293
292294 info.GetReturnValue ().Set (thiz);
@@ -307,6 +309,28 @@ void MetadataNode::NullObjectAccessorGetterCallback(Local<String> property,const
307309 }
308310}
309311
312+ void MetadataNode::NullValueOfCallback (const FunctionCallbackInfo<Value>& args) {
313+ try
314+ {
315+ auto isolate = Isolate::GetCurrent ();
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+
310334void MetadataNode::FieldAccessorGetterCallback (Local<String> property, const PropertyCallbackInfo<Value>& info)
311335{
312336 try
@@ -435,8 +459,8 @@ Local<Function> MetadataNode::SetMembers(Isolate *isolate, Local<FunctionTemplat
435459
436460 return hasCustomMetadata
437461 ? SetMembersFromRuntimeMetadata (isolate, ctorFuncTemplate, prototypeTemplate, instanceMethodsCallbackData, baseInstanceMethodsCallbackData, treeNode)
438- :
439- SetMembersFromStaticMetadata (isolate, ctorFuncTemplate, prototypeTemplate, instanceMethodsCallbackData, baseInstanceMethodsCallbackData, treeNode);
462+ :
463+ SetMembersFromStaticMetadata (isolate, ctorFuncTemplate, prototypeTemplate, instanceMethodsCallbackData, baseInstanceMethodsCallbackData, treeNode);
440464}
441465
442466Local<Function> MetadataNode::SetMembersFromStaticMetadata (Isolate *isolate, Local<FunctionTemplate>& ctorFuncTemplate, Local<ObjectTemplate>& prototypeTemplate, vector<MethodCallbackData*>& instanceMethodsCallbackData, const vector<MethodCallbackData*>& baseInstanceMethodsCallbackData, MetadataTreeNode *treeNode)
@@ -474,7 +498,7 @@ Local<Function> MetadataNode::SetMembersFromStaticMetadata(Isolate *isolate, Loc
474498 auto itBegin = baseInstanceMethodsCallbackData.begin ();
475499 auto itEnd = baseInstanceMethodsCallbackData.end ();
476500 auto itFound = find_if (itBegin, itEnd, [&entry] (MethodCallbackData *x)
477- { return x->candidates .front ().name == entry.name ;});
501+ { return x->candidates .front ().name == entry.name ;});
478502 if (itFound != itEnd)
479503 {
480504 callbackData->parent = *itFound;
@@ -599,7 +623,7 @@ Local<Function> MetadataNode::SetMembersFromRuntimeMetadata(Isolate *isolate, Lo
599623 auto itBegin = baseInstanceMethodsCallbackData.begin ();
600624 auto itEnd = baseInstanceMethodsCallbackData.end ();
601625 auto itFound = find_if (itBegin, itEnd, [&entry] (MethodCallbackData *x)
602- { return x->candidates .front ().name == entry.name ;});
626+ { return x->candidates .front ().name == entry.name ;});
603627 if (itFound != itEnd)
604628 {
605629 callbackData->parent = *itFound;
@@ -912,7 +936,7 @@ void MetadataNode::InterfaceConstructorCallback(const v8::FunctionCallbackInfo<v
912936 {
913937 if (!extendLocationFound)
914938 {
915- stringstream ss;
939+ stringstream ss;
916940 ss << " (InternalError): Invalid extend() call. No name specified for extend. Location: " << extendLocation.c_str ();
917941 throw NativeScriptException (ss.str ());
918942 }
@@ -1618,9 +1642,9 @@ MetadataEntry MetadataNode::GetChildMetadataForPackage(MetadataNode *node, const
16181642 bool isPrefix;
16191643 string declaringType = s_metadataReader.ReadInterfaceImplementationTypeName (treeNodeChild, isPrefix);
16201644 child.declaringType = isPrefix
1621- ? (declaringType + s_metadataReader.ReadTypeName (child.treeNode ))
1622- :
1623- declaringType;
1645+ ? (declaringType + s_metadataReader.ReadTypeName (child.treeNode ))
1646+ :
1647+ declaringType;
16241648 }
16251649 }
16261650 }
0 commit comments