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

Commit

Permalink
chakrashim: external object creation improvements
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
obastemur authored and kfarnung committed Feb 22, 2018
1 parent bedeb29 commit f295207
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions deps/chakrashim/src/v8objecttemplate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -860,35 +860,35 @@ Local<Object> ObjectTemplate::NewInstance(Handle<Function> constructor) {
return Local<Object>();
}

ObjectData *objectData = new ObjectData(this, objectTemplateData);
JsValueRef newInstanceRef = JS_INVALID_REFERENCE;
if (JsCreateExternalObject(objectData,
ObjectData::FinalizeCallback,
&newInstanceRef) != JsNoError) {
delete objectData;
return Local<Object>();
}

if (constructor.IsEmpty()) {
if (!objectTemplateData->constructor.IsEmpty()) {
constructor = objectTemplateData->constructor->GetFunction();
}
}

JsValueRef prototype = nullptr;

if (!constructor.IsEmpty()) {
jsrt::IsolateShim* iso = jsrt::IsolateShim::GetCurrent();
JsValueRef prototypeValue = nullptr;

if (JsGetProperty(*constructor,
iso->GetCachedPropertyIdRef(
jsrt::CachedPropertyIdRef::prototype),
&prototypeValue) == JsNoError) {
if (JsSetPrototype(newInstanceRef, prototypeValue) != JsNoError) {
return Local<Object>();
}
&prototype) != JsNoError) {
prototype = nullptr;
}
}

ObjectData *objectData = new ObjectData(this, objectTemplateData);
JsValueRef newInstanceRef = JS_INVALID_REFERENCE;
if (JsCreateExternalObjectWithPrototype(objectData,
ObjectData::FinalizeCallback,
prototype,
&newInstanceRef) != JsNoError) {
delete objectData;
return Local<Object>();
}

// In case the object should support index or named properties interceptors,
// we will use Proxies We will also support in case there is an overrdien
// toString method on the intercepted object (like Buffer), by returning an
Expand Down

0 comments on commit f295207

Please sign in to comment.