From 5fed2d619da91a9d612155a256a6cad1586d2d4e Mon Sep 17 00:00:00 2001 From: Jimmy Thomson Date: Fri, 27 Oct 2017 11:36:23 -0700 Subject: [PATCH] chakrashim: Updating shim to fix build break --- deps/chakrashim/include/v8.h | 97 +++++++++++-- deps/chakrashim/src/inspector/v8-console.cc | 2 +- deps/chakrashim/src/jsrtutils.cc | 75 ++++++++++ deps/chakrashim/src/jsrtutils.h | 3 + deps/chakrashim/src/v8chakra.h | 10 ++ deps/chakrashim/src/v8object.cc | 4 +- deps/chakrashim/src/v8objecttemplate.cc | 153 ++++++++++++++++++-- deps/chakrashim/src/v8propertydescriptor.cc | 10 ++ 8 files changed, 326 insertions(+), 28 deletions(-) diff --git a/deps/chakrashim/include/v8.h b/deps/chakrashim/include/v8.h index fafcb420916..713b8344ba7 100644 --- a/deps/chakrashim/include/v8.h +++ b/deps/chakrashim/include/v8.h @@ -94,6 +94,15 @@ namespace uvimpl { class Work; }; +namespace v8 { +class PropertyDescriptor; +} + +namespace jsrt { + JsErrorCode CreateV8PropertyDescriptor(JsValueRef descriptor, + v8::PropertyDescriptor* result); +} + namespace v8 { class AccessorSignature; @@ -216,6 +225,11 @@ typedef void (*NamedPropertyDeleterCallback)( Local property, const PropertyCallbackInfo& info); typedef void (*NamedPropertyEnumeratorCallback)( const PropertyCallbackInfo& info); +typedef void (*NamedPropertyDescriptorCallback)( + Local property, const PropertyCallbackInfo& info); +typedef void (*NamedPropertyDefinerCallback)( + Local property, const PropertyDescriptor& desc, + const PropertyCallbackInfo& info); typedef void (*GenericNamedPropertyGetterCallback)( Local property, const PropertyCallbackInfo& info); @@ -228,6 +242,11 @@ typedef void (*GenericNamedPropertyDeleterCallback)( Local property, const PropertyCallbackInfo& info); typedef void (*GenericNamedPropertyEnumeratorCallback)( const PropertyCallbackInfo& info); +typedef void (*GenericNamedPropertyDescriptorCallback)( + Local property, const PropertyCallbackInfo& info); +typedef void (*GenericNamedPropertyDefinerCallback)( + Local property, const PropertyDescriptor& desc, + const PropertyCallbackInfo& info); typedef void (*IndexedPropertyGetterCallback)( uint32_t index, const PropertyCallbackInfo& info); @@ -239,6 +258,11 @@ typedef void (*IndexedPropertyDeleterCallback)( uint32_t index, const PropertyCallbackInfo& info); typedef void (*IndexedPropertyEnumeratorCallback)( const PropertyCallbackInfo& info); +typedef void (*IndexedPropertyDefinerCallback)( + uint32_t index, const PropertyDescriptor& desc, + const PropertyCallbackInfo& info); +typedef void (*IndexedPropertyDescriptorCallback)( + uint32_t index, const PropertyCallbackInfo& info); typedef bool (*EntropySource)(unsigned char* buffer, size_t length); typedef void (*FatalErrorCallback)(const char *location, const char *message); @@ -337,6 +361,9 @@ class Local { friend class Value; friend class JSON; friend class uvimpl::Work; + friend JsErrorCode jsrt::CreateV8PropertyDescriptor( + JsValueRef descriptor, + v8::PropertyDescriptor* result); template friend class FunctionCallbackInfo; template friend class MaybeLocal; template friend class PersistentBase; @@ -1406,9 +1433,9 @@ class V8_EXPORT Object : public Value { Local context, Local key); V8_DEPRECATE_SOON("Use maybe version", - Local GetOwnPropertyDescriptor(Local key)); + Local GetOwnPropertyDescriptor(Local key)); V8_WARN_UNUSED_RESULT MaybeLocal GetOwnPropertyDescriptor( - Local context, Local key); + Local context, Local key); V8_DEPRECATE_SOON("Use maybe version", bool Has(Handle key)); V8_WARN_UNUSED_RESULT Maybe Has(Local context, @@ -1916,6 +1943,8 @@ class V8_EXPORT PropertyDescriptor { struct PrivateData; PrivateData* get_private() const { return private_; } + PropertyDescriptor & operator=(PropertyDescriptor &&); + PropertyDescriptor(const PropertyDescriptor&) = delete; void operator=(const PropertyDescriptor&) = delete; @@ -2251,16 +2280,39 @@ struct NamedPropertyHandlerConfiguration { query(query), deleter(deleter), enumerator(enumerator), + definer(0), + descriptor(0), data(data), flags(flags) {} - GenericNamedPropertyGetterCallback getter; - GenericNamedPropertySetterCallback setter; - GenericNamedPropertyQueryCallback query; - GenericNamedPropertyDeleterCallback deleter; - GenericNamedPropertyEnumeratorCallback enumerator; - Handle data; - PropertyHandlerFlags flags; + NamedPropertyHandlerConfiguration( + GenericNamedPropertyGetterCallback getter, + GenericNamedPropertySetterCallback setter, + GenericNamedPropertyDescriptorCallback descriptor, + GenericNamedPropertyDeleterCallback deleter, + GenericNamedPropertyEnumeratorCallback enumerator, + GenericNamedPropertyDefinerCallback definer, + Local data = Local(), + PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) + : getter(getter), + setter(setter), + query(0), + deleter(deleter), + enumerator(enumerator), + definer(definer), + descriptor(descriptor), + data(data), + flags(flags) {} + + GenericNamedPropertyGetterCallback getter; + GenericNamedPropertySetterCallback setter; + GenericNamedPropertyQueryCallback query; + GenericNamedPropertyDeleterCallback deleter; + GenericNamedPropertyEnumeratorCallback enumerator; + GenericNamedPropertyDefinerCallback definer; + GenericNamedPropertyDescriptorCallback descriptor; + Local data; + PropertyHandlerFlags flags; }; struct IndexedPropertyHandlerConfiguration { @@ -2277,6 +2329,27 @@ struct IndexedPropertyHandlerConfiguration { query(query), deleter(deleter), enumerator(enumerator), + definer(0), + descriptor(0), + data(data), + flags(flags) {} + + IndexedPropertyHandlerConfiguration( + IndexedPropertyGetterCallback getter = 0, + IndexedPropertySetterCallback setter = 0, + IndexedPropertyDescriptorCallback descriptor = 0, + IndexedPropertyDeleterCallback deleter = 0 , + IndexedPropertyEnumeratorCallback enumerator = 0, + IndexedPropertyDefinerCallback definer = 0, + Local data = Local(), + PropertyHandlerFlags flags = PropertyHandlerFlags::kNone) + : getter(getter), + setter(setter), + query(0), + deleter(deleter), + enumerator(enumerator), + definer(definer), + descriptor(descriptor), data(data), flags(flags) {} @@ -2285,6 +2358,8 @@ struct IndexedPropertyHandlerConfiguration { IndexedPropertyQueryCallback query; IndexedPropertyDeleterCallback deleter; IndexedPropertyEnumeratorCallback enumerator; + IndexedPropertyDefinerCallback definer; + IndexedPropertyDescriptorCallback descriptor; Handle data; PropertyHandlerFlags flags; }; @@ -2321,6 +2396,8 @@ class V8_EXPORT ObjectTemplate : public Template { NamedPropertyQueryCallback query = 0, NamedPropertyDeleterCallback deleter = 0, NamedPropertyEnumeratorCallback enumerator = 0, + NamedPropertyDefinerCallback definer = 0, + NamedPropertyDescriptorCallback descriptor = 0, Handle data = Handle()); void SetHandler(const NamedPropertyHandlerConfiguration& configuration); @@ -2331,6 +2408,8 @@ class V8_EXPORT ObjectTemplate : public Template { IndexedPropertyQueryCallback query = 0, IndexedPropertyDeleterCallback deleter = 0, IndexedPropertyEnumeratorCallback enumerator = 0, + IndexedPropertyDefinerCallback definer = 0, + IndexedPropertyDescriptorCallback descriptor = 0, Handle data = Handle()); void SetAccessCheckCallbacks( diff --git a/deps/chakrashim/src/inspector/v8-console.cc b/deps/chakrashim/src/inspector/v8-console.cc index 6b0f2f436a3..2c153038cd4 100644 --- a/deps/chakrashim/src/inspector/v8-console.cc +++ b/deps/chakrashim/src/inspector/v8-console.cc @@ -842,7 +842,7 @@ V8Console::CommandLineAPIScope::~CommandLineAPIScope() { v8::Local descriptor; bool success = m_global ->GetOwnPropertyDescriptor( - m_context, v8::Local::Cast(name)) + m_context, v8::Local::Cast(name)) .ToLocal(&descriptor); DCHECK(success); USE(success); diff --git a/deps/chakrashim/src/jsrtutils.cc b/deps/chakrashim/src/jsrtutils.cc index 8abb3baa40f..59cb8988576 100644 --- a/deps/chakrashim/src/jsrtutils.cc +++ b/deps/chakrashim/src/jsrtutils.cc @@ -580,6 +580,81 @@ JsErrorCode CreatePropertyDescriptor(v8::PropertyAttribute attributes, descriptor); } +JsErrorCode CreateV8PropertyDescriptor( + JsValueRef descriptor, + v8::PropertyDescriptor* result) { + IsolateShim * isolateShim = IsolateShim::GetCurrent(); + JsPropertyIdRef valueIdRef = isolateShim + ->GetCachedPropertyIdRef(CachedPropertyIdRef::value); + bool hasProperty = false; + IfJsErrorRet(JsHasProperty(descriptor, valueIdRef, &hasProperty)); + + v8::PropertyDescriptor desc; + if (hasProperty) { + JsValueRef value; + IfJsErrorRet(JsGetProperty(descriptor, valueIdRef, &value)); + + JsPropertyIdRef writableIdRef = isolateShim + ->GetCachedPropertyIdRef(CachedPropertyIdRef::writable); + IfJsErrorRet(JsHasProperty(descriptor, writableIdRef, &hasProperty)); + + if (hasProperty) { + JsValueRef writableVar = JS_INVALID_REFERENCE; + IfJsErrorRet(JsGetProperty(descriptor, writableIdRef, &writableVar)); + + bool writable = false; + IfJsErrorRet(ValueToBoolLikely(writableVar, &writable)); + desc = v8::PropertyDescriptor( + v8::Local::New(value), writable); + } else { + desc = v8::PropertyDescriptor( + v8::Local::New(value)); + } + } else { + JsPropertyIdRef getIdRef = isolateShim + ->GetCachedPropertyIdRef(CachedPropertyIdRef::get); + JsPropertyIdRef setIdRef = isolateShim + ->GetCachedPropertyIdRef(CachedPropertyIdRef::set); + + JsValueRef getValue = JS_INVALID_REFERENCE; + JsValueRef setValue = JS_INVALID_REFERENCE; + + IfJsErrorRet(JsGetProperty(descriptor, getIdRef, &getValue)); + IfJsErrorRet(JsGetProperty(descriptor, setIdRef, &setValue)); + + desc = v8::PropertyDescriptor( + v8::Local::New(getValue), + v8::Local::New(setValue)); + } + + JsPropertyIdRef enumerableIdRef = isolateShim + ->GetCachedPropertyIdRef(CachedPropertyIdRef::enumerable); + JsPropertyIdRef configurableIdRef = isolateShim + ->GetCachedPropertyIdRef(CachedPropertyIdRef::configurable); + + IfJsErrorRet(JsHasProperty(descriptor, enumerableIdRef, &hasProperty)); + if (hasProperty) { + JsValueRef enumerableVar = JS_INVALID_REFERENCE; + IfJsErrorRet(JsGetProperty(descriptor, enumerableIdRef, &enumerableVar)); + bool enumerable = false; + IfJsErrorRet(ValueToBoolLikely(enumerableVar, &enumerable)); + desc.set_enumerable(enumerable); + } + + IfJsErrorRet(JsHasProperty(descriptor, configurableIdRef, &hasProperty)); + if (hasProperty) { + JsValueRef configurableVar = JS_INVALID_REFERENCE; + IfJsErrorRet(JsGetProperty(descriptor, configurableIdRef, + &configurableVar)); + bool configurable = false; + IfJsErrorRet(ValueToBoolLikely(configurableVar, &configurable)); + desc.set_configurable(configurable); + } + + *result = std::move(desc); + return JsNoError; +} + JsErrorCode DefineProperty(JsValueRef object, JsPropertyIdRef propertyIdRef, PropertyDescriptorOptionValues writable, diff --git a/deps/chakrashim/src/jsrtutils.h b/deps/chakrashim/src/jsrtutils.h index 777c961b1bb..5d02900d314 100644 --- a/deps/chakrashim/src/jsrtutils.h +++ b/deps/chakrashim/src/jsrtutils.h @@ -348,6 +348,9 @@ JsErrorCode CreatePropertyDescriptor(v8::PropertyAttribute attributes, JsValueRef setter, JsValueRef *descriptor); +JsErrorCode CreateV8PropertyDescriptor(JsValueRef descriptor, + v8::PropertyDescriptor* result); + JsErrorCode DefineProperty(JsValueRef object, const char * propertyName, PropertyDescriptorOptionValues writable, diff --git a/deps/chakrashim/src/v8chakra.h b/deps/chakrashim/src/v8chakra.h index b9a8d1e706d..0c651d3b34f 100644 --- a/deps/chakrashim/src/v8chakra.h +++ b/deps/chakrashim/src/v8chakra.h @@ -108,12 +108,16 @@ class ObjectData: public ExternalData { NamedPropertyQueryCallback namedPropertyQuery; NamedPropertyDeleterCallback namedPropertyDeleter; NamedPropertyEnumeratorCallback namedPropertyEnumerator; + NamedPropertyDefinerCallback namedPropertyDefiner; + NamedPropertyDescriptorCallback namedPropertyDescriptor; Persistent namedPropertyInterceptorData; IndexedPropertyGetterCallback indexedPropertyGetter; IndexedPropertySetterCallback indexedPropertySetter; IndexedPropertyQueryCallback indexedPropertyQuery; IndexedPropertyDeleterCallback indexedPropertyDeleter; IndexedPropertyEnumeratorCallback indexedPropertyEnumerator; + IndexedPropertyDefinerCallback indexedPropertyDefiner; + IndexedPropertyDescriptorCallback indexedPropertyDescriptor; Persistent indexedPropertyInterceptorData; int internalFieldCount; FieldValue* internalFields; @@ -206,6 +210,12 @@ class Utils { JsValueRef *arguments, unsigned short argumentCount, // NOLINT(runtime/int) void *callbackState); + static JsValueRef CHAKRA_CALLBACK DefinePropertyCallback( + JsValueRef callee, + bool isConstructCall, + JsValueRef *arguments, + unsigned short argumentCount, // NOLINT(runtime/int) + void *callbackState); static void CHAKRA_CALLBACK WeakReferenceCallbackWrapperCallback( JsRef ref, void *data); diff --git a/deps/chakrashim/src/v8object.cc b/deps/chakrashim/src/v8object.cc index 3d6cc33dc22..4eb026ff388 100644 --- a/deps/chakrashim/src/v8object.cc +++ b/deps/chakrashim/src/v8object.cc @@ -267,7 +267,7 @@ PropertyAttribute Object::GetPropertyAttributes(Handle key) { } MaybeLocal Object::GetOwnPropertyDescriptor(Local context, - Local key) { + Local key) { JsValueRef result; if (jsrt::GetOwnPropertyDescriptor(this, *key, &result) != JsNoError) { return Local(); @@ -275,7 +275,7 @@ MaybeLocal Object::GetOwnPropertyDescriptor(Local context, return Local::New(result); } -Local Object::GetOwnPropertyDescriptor(Local key) { +Local Object::GetOwnPropertyDescriptor(Local key) { return FromMaybe(GetOwnPropertyDescriptor(Local(), key)); } diff --git a/deps/chakrashim/src/v8objecttemplate.cc b/deps/chakrashim/src/v8objecttemplate.cc index d56e1a2236a..30ced0edda6 100755 --- a/deps/chakrashim/src/v8objecttemplate.cc +++ b/deps/chakrashim/src/v8objecttemplate.cc @@ -33,12 +33,16 @@ class ObjectTemplateData : public TemplateData { NamedPropertyQueryCallback namedPropertyQuery; NamedPropertyDeleterCallback namedPropertyDeleter; NamedPropertyEnumeratorCallback namedPropertyEnumerator; + NamedPropertyDefinerCallback namedPropertyDefiner; + NamedPropertyDescriptorCallback namedPropertyDescriptor; Persistent namedPropertyInterceptorData; IndexedPropertyGetterCallback indexedPropertyGetter; IndexedPropertySetterCallback indexedPropertySetter; IndexedPropertyQueryCallback indexedPropertyQuery; IndexedPropertyDeleterCallback indexedPropertyDeleter; IndexedPropertyEnumeratorCallback indexedPropertyEnumerator; + IndexedPropertyDefinerCallback indexedPropertyDefiner; + IndexedPropertyDescriptorCallback indexedPropertyDescriptor; Persistent indexedPropertyInterceptorData; FunctionCallback functionCallDelegate; Persistent functionCallDelegateInterceptorData; @@ -51,11 +55,15 @@ class ObjectTemplateData : public TemplateData { namedPropertyQuery(nullptr), namedPropertyDeleter(nullptr), namedPropertyEnumerator(nullptr), + namedPropertyDefiner(nullptr), + namedPropertyDescriptor(nullptr), indexedPropertyGetter(nullptr), indexedPropertySetter(nullptr), indexedPropertyQuery(nullptr), indexedPropertyDeleter(nullptr), indexedPropertyEnumerator(nullptr), + indexedPropertyDefiner(nullptr), + indexedPropertyDescriptor(nullptr), functionCallDelegate(nullptr), functionCallDelegateInterceptorData(nullptr), internalFieldCount(0) { @@ -82,11 +90,15 @@ class ObjectTemplateData : public TemplateData { namedPropertyGetter != nullptr || namedPropertyQuery != nullptr || namedPropertySetter != nullptr || + namedPropertyDefiner != nullptr || + namedPropertyDescriptor != nullptr || indexedPropertyDeleter != nullptr || indexedPropertyEnumerator != nullptr || indexedPropertyGetter != nullptr || indexedPropertyQuery != nullptr || - indexedPropertySetter != nullptr; + indexedPropertySetter != nullptr || + indexedPropertyDefiner != nullptr || + indexedPropertyDescriptor != nullptr; /* CHAKRA: functionCallDelegate is intentionaly not added as interceptors because it can be invoked through Object::CallAsFunction or Object::CallAsConstructor @@ -153,6 +165,8 @@ ObjectData::ObjectData(ObjectTemplate* objectTemplate, namedPropertyQuery(templateData->namedPropertyQuery), namedPropertyDeleter(templateData->namedPropertyDeleter), namedPropertyEnumerator(templateData->namedPropertyEnumerator), + namedPropertyDefiner(templateData->namedPropertyDefiner), + namedPropertyDescriptor(templateData->namedPropertyDescriptor), namedPropertyInterceptorData( nullptr, templateData->namedPropertyInterceptorData), indexedPropertyGetter(templateData->indexedPropertyGetter), @@ -160,6 +174,8 @@ ObjectData::ObjectData(ObjectTemplate* objectTemplate, indexedPropertyQuery(templateData->indexedPropertyQuery), indexedPropertyDeleter(templateData->indexedPropertyDeleter), indexedPropertyEnumerator(templateData->indexedPropertyEnumerator), + indexedPropertyDefiner(templateData->indexedPropertyDefiner), + indexedPropertyDescriptor(templateData->indexedPropertyDescriptor), indexedPropertyInterceptorData( nullptr, templateData->indexedPropertyInterceptorData), internalFieldCount(templateData->internalFieldCount) { @@ -596,7 +612,6 @@ JsValueRef CHAKRA_CALLBACK Utils::GetOwnPropertyDescriptorCallback( JsValueRef object = arguments[1]; JsValueRef prop = arguments[2]; - JsValueRef descriptor; ObjectData* objectData = nullptr; if (!ExternalData::TryGet(object, &objectData)) { @@ -611,6 +626,7 @@ JsValueRef CHAKRA_CALLBACK Utils::GetOwnPropertyDescriptorCallback( JsValueRef queryResult = JS_INVALID_REFERENCE; JsValueRef value = JS_INVALID_REFERENCE; + JsValueRef descriptor = JS_INVALID_REFERENCE; if (isPropIntType) { if (objectData->indexedPropertyQuery != nullptr) { @@ -638,6 +654,16 @@ JsValueRef CHAKRA_CALLBACK Utils::GetOwnPropertyDescriptorCallback( return jsrt::GetUndefined(); } } + + // We should not have both a Descriptor and a Query. + if (objectData->indexedPropertyDescriptor != nullptr) { + PropertyCallbackInfo info( + *objectData->indexedPropertyInterceptorData, + reinterpret_cast(object), + /*holder*/reinterpret_cast(object)); + objectData->indexedPropertyDescriptor(index, info); + descriptor = reinterpret_cast(info.GetReturnValue().Get()); + } } else { // named property... // query the property descriptor if there is such, and then get the value // from the proxy in order to go through the interceptor @@ -666,15 +692,16 @@ JsValueRef CHAKRA_CALLBACK Utils::GetOwnPropertyDescriptorCallback( return jsrt::GetUndefined(); } } - } - // if neither is intercepted, fallback to default - if (queryResult == JS_INVALID_REFERENCE && value == JS_INVALID_REFERENCE) { - if (jsrt::GetOwnPropertyDescriptor(object, prop, - &descriptor) != JsNoError) { - return jsrt::GetUndefined(); + if (objectData->namedPropertyDescriptor != nullptr) { + PropertyCallbackInfo info( + *objectData->namedPropertyInterceptorData, + reinterpret_cast(object), + /*holder*/reinterpret_cast(object)); + objectData->namedPropertyDescriptor( + reinterpret_cast(prop), info); + descriptor = reinterpret_cast(info.GetReturnValue().Get()); } - return descriptor; } int queryResultInt = v8::PropertyAttribute::DontEnum; @@ -682,19 +709,93 @@ JsValueRef CHAKRA_CALLBACK Utils::GetOwnPropertyDescriptorCallback( if (jsrt::ValueToIntLikely(queryResult, &queryResultInt) != JsNoError) { return jsrt::GetUndefined(); } + + v8::PropertyAttribute attributes = + static_cast(queryResultInt); + if (jsrt::CreatePropertyDescriptor(attributes, value, JS_INVALID_REFERENCE, + JS_INVALID_REFERENCE, + &descriptor) != JsNoError) { + return jsrt::GetUndefined(); + } } - v8::PropertyAttribute attributes = - static_cast(queryResultInt); - if (jsrt::CreatePropertyDescriptor(attributes, value, JS_INVALID_REFERENCE, - JS_INVALID_REFERENCE, - &descriptor) != JsNoError) { - return jsrt::GetUndefined(); + // if nothing is intercepted, fallback to default + if (descriptor == JS_INVALID_REFERENCE) { + if (jsrt::GetOwnPropertyDescriptor(object, prop, + &descriptor) != JsNoError) { + return jsrt::GetUndefined(); + } } return descriptor; } +JsValueRef CHAKRA_CALLBACK Utils::DefinePropertyCallback( + JsValueRef callee, + bool isConstructCall, + JsValueRef *arguments, + unsigned short argumentCount, // NOLINT(runtime/int) + void *callbackState) { + CHAKRA_VERIFY(argumentCount >= 4); + + JsValueRef object = arguments[1]; + JsValueRef prop = arguments[2]; + JsValueRef descriptor = arguments[3]; + + PropertyDescriptor v8desc; + jsrt::CreateV8PropertyDescriptor(descriptor, &v8desc); + + ObjectData* objectData = nullptr; + if (!ExternalData::TryGet(object, &objectData)) { + return jsrt::GetUndefined(); + } + + bool isPropIntType; + unsigned int index; + if (jsrt::TryParseUInt32(prop, &isPropIntType, &index) != JsNoError) { + return jsrt::GetUndefined(); + } + + JsValueRef result = JS_INVALID_REFERENCE; + + if (isPropIntType) { + if (objectData->indexedPropertyDefiner != nullptr) { + PropertyCallbackInfo info( + *objectData->indexedPropertyInterceptorData, + reinterpret_cast(object), + /*holder*/reinterpret_cast(object)); + objectData->indexedPropertyDefiner(index, v8desc, info); + result = reinterpret_cast(info.GetReturnValue().Get()); + } + } else { + if (objectData->namedPropertyDefiner != nullptr) { + PropertyCallbackInfo info( + *objectData->namedPropertyInterceptorData, + reinterpret_cast(object), + /*holder*/reinterpret_cast(object)); + objectData->namedPropertyDefiner( + reinterpret_cast(prop), v8desc, info); + result = reinterpret_cast(info.GetReturnValue().Get()); + } + } + + if (result == JS_INVALID_REFERENCE) { + // No interception took place; fall back to default behavior + JsPropertyIdRef propertyIdRef; + if (jsrt::GetPropertyIdFromName(prop, &propertyIdRef) != JsNoError) { + return jsrt::GetFalse(); + } + + bool result = false; + if (JsDefineProperty(object, propertyIdRef, descriptor, &result) + != JsNoError || !result) { + return jsrt::GetFalse(); + } + } + + return jsrt::GetTrue(); +} + Local ObjectTemplate::New(Isolate* isolate) { JsValueRef objectTemplateRef; ObjectTemplateData* templateData = new ObjectTemplateData(); @@ -791,11 +892,19 @@ Local ObjectTemplate::NewInstance(Handle prototype) { if (objectTemplateData->indexedPropertyQuery != nullptr || objectTemplateData->namedPropertyQuery != nullptr || objectTemplateData->indexedPropertyGetter != nullptr || - objectTemplateData->namedPropertyGetter != nullptr) { + objectTemplateData->namedPropertyGetter != nullptr || + objectTemplateData->indexedPropertyDescriptor != nullptr || + objectTemplateData->namedPropertyDescriptor != nullptr) { proxyConf[jsrt::ProxyTraps::GetOwnPropertyDescriptorTrap] = Utils::GetOwnPropertyDescriptorCallback; } + if (objectTemplateData->indexedPropertyDefiner != nullptr || + objectTemplateData->namedPropertyDefiner != nullptr) { + proxyConf[jsrt::ProxyTraps::DefinePropertyTrap] = + Utils::DefinePropertyCallback; + } + JsErrorCode error = jsrt::CreateProxy(newInstanceTargetRef, proxyConf, &newInstanceRef); @@ -851,6 +960,8 @@ void ObjectTemplate::SetNamedPropertyHandler( NamedPropertyQueryCallback query, NamedPropertyDeleterCallback remover, NamedPropertyEnumeratorCallback enumerator, + NamedPropertyDefinerCallback definer, + NamedPropertyDescriptorCallback descriptor, Handle data) { ObjectTemplateData *objectTemplateData = nullptr; if (!ExternalData::TryGet(this, &objectTemplateData)) { @@ -861,6 +972,8 @@ void ObjectTemplate::SetNamedPropertyHandler( objectTemplateData->namedPropertyQuery = query; objectTemplateData->namedPropertyDeleter = remover; objectTemplateData->namedPropertyEnumerator = enumerator; + objectTemplateData->namedPropertyDefiner = definer; + objectTemplateData->namedPropertyDescriptor = descriptor; objectTemplateData->namedPropertyInterceptorData = data; } @@ -872,6 +985,8 @@ void ObjectTemplate::SetHandler( reinterpret_cast(config.query), reinterpret_cast(config.deleter), reinterpret_cast(config.enumerator), + reinterpret_cast(config.definer), + reinterpret_cast(config.descriptor), config.data); } @@ -881,6 +996,8 @@ void ObjectTemplate::SetIndexedPropertyHandler( IndexedPropertyQueryCallback query, IndexedPropertyDeleterCallback remover, IndexedPropertyEnumeratorCallback enumerator, + IndexedPropertyDefinerCallback definer, + IndexedPropertyDescriptorCallback descriptor, Handle data) { ObjectTemplateData *objectTemplateData = nullptr; if (!ExternalData::TryGet(this, &objectTemplateData)) { @@ -892,6 +1009,8 @@ void ObjectTemplate::SetIndexedPropertyHandler( objectTemplateData->indexedPropertyQuery = query; objectTemplateData->indexedPropertyDeleter = remover; objectTemplateData->indexedPropertyEnumerator = enumerator; + objectTemplateData->indexedPropertyDefiner = definer; + objectTemplateData->indexedPropertyDescriptor = descriptor; objectTemplateData->indexedPropertyInterceptorData = data; } @@ -903,6 +1022,8 @@ void ObjectTemplate::SetHandler( config.query, config.deleter, config.enumerator, + config.definer, + config.descriptor, config.data); } diff --git a/deps/chakrashim/src/v8propertydescriptor.cc b/deps/chakrashim/src/v8propertydescriptor.cc index 7ce1795c3a6..7535955a5bd 100644 --- a/deps/chakrashim/src/v8propertydescriptor.cc +++ b/deps/chakrashim/src/v8propertydescriptor.cc @@ -85,7 +85,17 @@ PropertyDescriptor::PropertyDescriptor(Local get, } } +PropertyDescriptor & +PropertyDescriptor::operator=(PropertyDescriptor && other) { + private_ = other.private_; + other.private_ = nullptr; + return *this; +} + PropertyDescriptor::~PropertyDescriptor() { + if (private_ == nullptr) { + return; + } if (private_->value != JS_INVALID_REFERENCE) { JsRelease(private_->value, nullptr); }