Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit f295207

Browse files
obastemurkfarnung
authored andcommitted
chakrashim: external object creation improvements
Previously, Chakrashim was calling both JsCreateExternalObject and JsSetPrototype. JsSetPrototype is expensive to lazy call. Use combined JsCreateExternalObjectWithPrototype instead. PR-URL: #472 Refs: #429 Reviewed-By: Taylor Woll <tawoll@ntdev.microsoft.com> Reviewed-By: Oguz Bastemur <ogbastem@microsoft.com>
1 parent bedeb29 commit f295207

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

deps/chakrashim/src/v8objecttemplate.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -860,35 +860,35 @@ Local<Object> ObjectTemplate::NewInstance(Handle<Function> constructor) {
860860
return Local<Object>();
861861
}
862862

863-
ObjectData *objectData = new ObjectData(this, objectTemplateData);
864-
JsValueRef newInstanceRef = JS_INVALID_REFERENCE;
865-
if (JsCreateExternalObject(objectData,
866-
ObjectData::FinalizeCallback,
867-
&newInstanceRef) != JsNoError) {
868-
delete objectData;
869-
return Local<Object>();
870-
}
871-
872863
if (constructor.IsEmpty()) {
873864
if (!objectTemplateData->constructor.IsEmpty()) {
874865
constructor = objectTemplateData->constructor->GetFunction();
875866
}
876867
}
877868

869+
JsValueRef prototype = nullptr;
870+
878871
if (!constructor.IsEmpty()) {
879872
jsrt::IsolateShim* iso = jsrt::IsolateShim::GetCurrent();
880-
JsValueRef prototypeValue = nullptr;
881873

882874
if (JsGetProperty(*constructor,
883875
iso->GetCachedPropertyIdRef(
884876
jsrt::CachedPropertyIdRef::prototype),
885-
&prototypeValue) == JsNoError) {
886-
if (JsSetPrototype(newInstanceRef, prototypeValue) != JsNoError) {
887-
return Local<Object>();
888-
}
877+
&prototype) != JsNoError) {
878+
prototype = nullptr;
889879
}
890880
}
891881

882+
ObjectData *objectData = new ObjectData(this, objectTemplateData);
883+
JsValueRef newInstanceRef = JS_INVALID_REFERENCE;
884+
if (JsCreateExternalObjectWithPrototype(objectData,
885+
ObjectData::FinalizeCallback,
886+
prototype,
887+
&newInstanceRef) != JsNoError) {
888+
delete objectData;
889+
return Local<Object>();
890+
}
891+
892892
// In case the object should support index or named properties interceptors,
893893
// we will use Proxies We will also support in case there is an overrdien
894894
// toString method on the intercepted object (like Buffer), by returning an

0 commit comments

Comments
 (0)