Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions NativeScript/runtime/ArgConverter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -928,19 +928,31 @@
tns::Assert(false, isolate);
}
} else {
Class knownClass = objc_getClass(meta->name());
KnownUnknownClassPair pair(knownClass, klass);
Local<FunctionTemplate> ctorFuncTemplate = cache->ObjectCtorInitializer(
context, static_cast<const BaseClassMeta*>(meta), pair, additionalProtocols);
Local<v8::Function> ctorFunc;
bool success = ctorFuncTemplate->GetFunction(context).ToLocal(&ctorFunc);
tns::Assert(success, isolate);

Local<Value> prototypeValue;
success =
ctorFunc->Get(context, tns::ToV8String(isolate, "prototype")).ToLocal(&prototypeValue);
tns::Assert(success, isolate);
Local<Object> prototype = prototypeValue.As<Object>();
auto cached = additionalProtocols.empty() ? cache->MetaInstancePrototypes.find(meta)
: cache->MetaInstancePrototypes.end();
Local<Object> prototype;
bool success;
if (cached != cache->MetaInstancePrototypes.end()) {
prototype = cached->second->Get(isolate);
} else {
Class knownClass = objc_getClass(meta->name());
KnownUnknownClassPair pair(knownClass, klass);
Local<FunctionTemplate> ctorFuncTemplate = cache->ObjectCtorInitializer(
context, static_cast<const BaseClassMeta*>(meta), pair, additionalProtocols);
Local<v8::Function> ctorFunc;
success = ctorFuncTemplate->GetFunction(context).ToLocal(&ctorFunc);
tns::Assert(success, isolate);

Local<Value> prototypeValue;
success =
ctorFunc->Get(context, tns::ToV8String(isolate, "prototype")).ToLocal(&prototypeValue);
tns::Assert(success, isolate);
prototype = prototypeValue.As<Object>();
if (additionalProtocols.empty()) {
cache->MetaInstancePrototypes.emplace(
meta, std::make_unique<Persistent<Object>>(isolate, prototype));
}
}

if (!receiver->SetPrototype(context, prototype).To(&success) || !success) {
tns::Assert(false, isolate);
Expand Down
1 change: 1 addition & 0 deletions NativeScript/runtime/Caches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Caches::~Caches() {

this->Prototypes.clear();
this->ClassPrototypes.clear();
this->MetaInstancePrototypes.clear();
this->CtorFuncTemplates.clear();
this->CtorFuncs.clear();
this->ProtocolCtorFuncs.clear();
Expand Down
3 changes: 3 additions & 0 deletions NativeScript/runtime/Caches.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ class Caches {
std::unique_ptr<v8::Persistent<v8::Object>>,
TransparentStringHash, TransparentStringEqual>
ClassPrototypes;
robin_hood::unordered_map<const Meta*,
std::unique_ptr<v8::Persistent<v8::Object>>>
MetaInstancePrototypes;
robin_hood::unordered_map<
const BaseClassMeta*,
std::unique_ptr<v8::Persistent<v8::FunctionTemplate>>>
Expand Down
Loading