From f2952070f39d6bfdeb0d39592dfed3b55a8c3f02 Mon Sep 17 00:00:00 2001 From: Oguz Bastemur Date: Fri, 17 Nov 2017 04:03:18 +0100 Subject: [PATCH] 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: https://github.com/nodejs/node-chakracore/pull/472 Refs: https://github.com/nodejs/node-chakracore/pull/429 Reviewed-By: Taylor Woll Reviewed-By: Oguz Bastemur --- deps/chakrashim/src/v8objecttemplate.cc | 28 ++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/deps/chakrashim/src/v8objecttemplate.cc b/deps/chakrashim/src/v8objecttemplate.cc index ab435502e28..8e1324711fb 100755 --- a/deps/chakrashim/src/v8objecttemplate.cc +++ b/deps/chakrashim/src/v8objecttemplate.cc @@ -860,35 +860,35 @@ Local ObjectTemplate::NewInstance(Handle constructor) { return Local(); } - ObjectData *objectData = new ObjectData(this, objectTemplateData); - JsValueRef newInstanceRef = JS_INVALID_REFERENCE; - if (JsCreateExternalObject(objectData, - ObjectData::FinalizeCallback, - &newInstanceRef) != JsNoError) { - delete objectData; - return Local(); - } - 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(); - } + &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(); + } + // 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