diff --git a/deps/chakrashim/src/jsrtcontextshim.cc b/deps/chakrashim/src/jsrtcontextshim.cc index 15aefc3809c..1d754d1a32d 100644 --- a/deps/chakrashim/src/jsrtcontextshim.cc +++ b/deps/chakrashim/src/jsrtcontextshim.cc @@ -292,7 +292,7 @@ bool ContextShim::InitializeBuiltIns() { return false; } - if (DefineProperty(globalObject, + if (DefinePropertyById(globalObject, GetIsolateShim()->GetKeepAliveObjectSymbolPropertyIdRef(), PropertyDescriptorOptionValues::False, PropertyDescriptorOptionValues::False, diff --git a/deps/chakrashim/src/jsrtutils.cc b/deps/chakrashim/src/jsrtutils.cc index 59cb8988576..bdfe29fa7c9 100644 --- a/deps/chakrashim/src/jsrtutils.cc +++ b/deps/chakrashim/src/jsrtutils.cc @@ -40,9 +40,7 @@ JsErrorCode UintToValue(uint32_t value, JsValueRef* result) { JsErrorCode GetProperty(JsValueRef ref, JsValueRef propName, JsValueRef *result) { - JsPropertyIdRef idRef = JS_INVALID_REFERENCE; - IfJsErrorRet(GetPropertyIdFromName(propName, &idRef)); - IfJsErrorRet(JsGetProperty(ref, idRef, result)); + IfJsErrorRet(JsObjectGetProperty(ref, propName, result)); return JsNoError; } @@ -113,9 +111,7 @@ JsErrorCode SetProperty(JsValueRef ref, JsErrorCode SetProperty(JsValueRef ref, JsValueRef propName, JsValueRef propValue) { - JsPropertyIdRef idRef = JS_INVALID_REFERENCE; - IfJsErrorRet(GetPropertyIdFromName(propName, &idRef)); - IfJsErrorRet(JsSetProperty(ref, idRef, propValue, false)); + IfJsErrorRet(JsObjectSetProperty(ref, propName, propValue, false)); return JsNoError; } @@ -171,9 +167,7 @@ JsErrorCode SetProperty(JsValueRef ref, JsErrorCode DeleteProperty(JsValueRef ref, JsValueRef propName, JsValueRef* result) { - JsPropertyIdRef idRef = JS_INVALID_REFERENCE; - IfJsErrorRet(GetPropertyIdFromName(propName, &idRef)); - IfJsErrorRet(JsDeleteProperty(ref, idRef, false, result)); + IfJsErrorRet(JsObjectDeleteProperty(ref, propName, false, result)); return JsNoError; } @@ -292,11 +286,8 @@ JsErrorCode HasOwnProperty(JsValueRef object, *result = JS_INVALID_REFERENCE; - JsPropertyIdRef propId = JS_INVALID_REFERENCE; - IfJsErrorRet(GetPropertyIdFromValue(prop, &propId)); - bool hasOwnProperty = false; - IfJsErrorRet(JsHasOwnProperty(object, propId, &hasOwnProperty)); + IfJsErrorRet(JsObjectHasOwnProperty(object, prop, &hasOwnProperty)); IfJsErrorRet(JsBoolToBoolean(hasOwnProperty, result)); return JsNoError; @@ -305,10 +296,7 @@ JsErrorCode HasOwnProperty(JsValueRef object, JsErrorCode GetOwnPropertyDescriptor(JsValueRef ref, JsValueRef prop, JsValueRef* result) { - JsPropertyIdRef idRef = JS_INVALID_REFERENCE; - IfJsErrorRet(GetPropertyIdFromName(prop, &idRef)); - - return JsGetOwnPropertyDescriptor(ref, idRef, result); + return JsObjectGetOwnPropertyDescriptor(ref, prop, result); } JsErrorCode IsZero(JsValueRef value, @@ -399,7 +387,7 @@ JsErrorCode AddExternalData(JsValueRef ref, IfJsErrorRet(JsCreateExternalObject(data, onObjectFinalize, &externalObjectRef)); - IfJsErrorRet(DefineProperty(ref, + IfJsErrorRet(DefinePropertyById(ref, externalDataPropertyId, PropertyDescriptorOptionValues::False, PropertyDescriptorOptionValues::False, @@ -655,7 +643,7 @@ JsErrorCode CreateV8PropertyDescriptor( return JsNoError; } -JsErrorCode DefineProperty(JsValueRef object, +JsErrorCode DefinePropertyById(JsValueRef object, JsPropertyIdRef propertyIdRef, PropertyDescriptorOptionValues writable, PropertyDescriptorOptionValues enumerable, @@ -677,6 +665,28 @@ JsErrorCode DefineProperty(JsValueRef object, return JsNoError; } +JsErrorCode DefinePropertyByName(JsValueRef object, + JsValueRef propertyName, + PropertyDescriptorOptionValues writable, + PropertyDescriptorOptionValues enumerable, + PropertyDescriptorOptionValues configurable, + JsValueRef value, + JsValueRef getter, + JsValueRef setter) { + JsValueRef descriptor = JS_INVALID_REFERENCE; + IfJsErrorRet(CreatePropertyDescriptor(writable, enumerable, configurable, + value, getter, setter, &descriptor)); + + bool result = false; + IfJsErrorRet(JsObjectDefineProperty(object, propertyName, descriptor, &result)); + + if (!result) { + return JsErrorInvalidArgument; + } + + return JsNoError; +} + JsErrorCode GetPropertyIdFromName(JsValueRef nameRef, JsPropertyIdRef *idRef) { StringUtf8 str; @@ -751,9 +761,7 @@ JsErrorCode DeleteIndexedProperty(JsValueRef object, JsErrorCode HasProperty(JsValueRef object, JsValueRef propName, bool *result) { - JsPropertyIdRef idRef = JS_INVALID_REFERENCE; - IfJsErrorRet(GetPropertyIdFromName(propName, &idRef)); - IfJsErrorRet(JsHasProperty(object, idRef, result)); + IfJsErrorRet(JsObjectHasProperty(object, propName, result)); return JsNoError; } @@ -884,9 +892,6 @@ JsErrorCode GetPrivate(JsValueRef object, JsValueRef key, return JsNoError; } - JsPropertyIdRef keyIdRef = JS_INVALID_REFERENCE; - IfJsErrorRet(GetPropertyIdFromName(key, &keyIdRef)); - // Is 'key' present in hiddenValuesTable? If not, return undefined JsValueRef hasPropertyRef = JS_INVALID_REFERENCE; IfJsErrorRet(HasOwnProperty(hiddenValuesTable, key, &hasPropertyRef)); @@ -899,7 +904,7 @@ JsErrorCode GetPrivate(JsValueRef object, JsValueRef key, return JsNoError; } - IfJsErrorRet(JsGetProperty(hiddenValuesTable, keyIdRef, result)); + IfJsErrorRet(JsObjectGetProperty(hiddenValuesTable, key, result)); return JsNoError; } @@ -917,7 +922,7 @@ JsErrorCode SetPrivate(JsValueRef object, JsValueRef key, if (isUndefined) { IfJsErrorRet(JsCreateObject(&hiddenValuesTable)); - IfJsErrorRet(DefineProperty(object, hiddenValuesIdRef, + IfJsErrorRet(DefinePropertyById(object, hiddenValuesIdRef, PropertyDescriptorOptionValues::False, PropertyDescriptorOptionValues::False, PropertyDescriptorOptionValues::False, diff --git a/deps/chakrashim/src/jsrtutils.h b/deps/chakrashim/src/jsrtutils.h index 5d02900d314..c0cd34b1304 100644 --- a/deps/chakrashim/src/jsrtutils.h +++ b/deps/chakrashim/src/jsrtutils.h @@ -351,8 +351,8 @@ JsErrorCode CreatePropertyDescriptor(v8::PropertyAttribute attributes, JsErrorCode CreateV8PropertyDescriptor(JsValueRef descriptor, v8::PropertyDescriptor* result); -JsErrorCode DefineProperty(JsValueRef object, - const char * propertyName, +JsErrorCode DefinePropertyById(JsValueRef object, + JsPropertyIdRef propertyIdRef, PropertyDescriptorOptionValues writable, PropertyDescriptorOptionValues enumerable, PropertyDescriptorOptionValues configurable, @@ -360,8 +360,8 @@ JsErrorCode DefineProperty(JsValueRef object, JsValueRef getter, JsValueRef setter); -JsErrorCode DefineProperty(JsValueRef object, - JsPropertyIdRef propertyIdRef, +JsErrorCode DefinePropertyByName(JsValueRef object, + JsValueRef propertyName, PropertyDescriptorOptionValues writable, PropertyDescriptorOptionValues enumerable, PropertyDescriptorOptionValues configurable, diff --git a/deps/chakrashim/src/v8external.cc b/deps/chakrashim/src/v8external.cc index 71698dbf907..6505e3c753f 100644 --- a/deps/chakrashim/src/v8external.cc +++ b/deps/chakrashim/src/v8external.cc @@ -47,7 +47,7 @@ Local External::New(Isolate* isolate, void* value) { IsolateShim* iso = IsolateShim::FromIsolate(isolate); JsValueRef trueRef = iso->GetCurrentContextShim()->GetTrue(); - if (jsrt::DefineProperty(externalRef, + if (jsrt::DefinePropertyById(externalRef, iso->GetCachedSymbolPropertyIdRef( jsrt::CachedSymbolPropertyIdRef::__isexternal__), jsrt::PropertyDescriptorOptionValues::False, diff --git a/deps/chakrashim/src/v8function.cc b/deps/chakrashim/src/v8function.cc index 45147cac6da..342eb37e051 100644 --- a/deps/chakrashim/src/v8function.cc +++ b/deps/chakrashim/src/v8function.cc @@ -26,7 +26,7 @@ namespace v8 { using jsrt::IsolateShim; using jsrt::ContextShim; using jsrt::PropertyDescriptorOptionValues; -using jsrt::DefineProperty; +using jsrt::DefinePropertyById; MaybeLocal Function::New(Local context, FunctionCallback callback, @@ -106,7 +106,7 @@ Local Function::Call(Handle recv, } void Function::SetName(Handle name) { - JsErrorCode error = jsrt::DefineProperty((JsValueRef)this, + JsErrorCode error = jsrt::DefinePropertyById((JsValueRef)this, IsolateShim::GetCurrent()->GetCachedPropertyIdRef( jsrt::CachedPropertyIdRef::name), PropertyDescriptorOptionValues::False, diff --git a/deps/chakrashim/src/v8functiontemplate.cc b/deps/chakrashim/src/v8functiontemplate.cc index 4d32b0cda57..283f5b35744 100755 --- a/deps/chakrashim/src/v8functiontemplate.cc +++ b/deps/chakrashim/src/v8functiontemplate.cc @@ -277,7 +277,7 @@ class FunctionTemplateData : public TemplateData { } if (!className.IsEmpty()) { - if (jsrt::DefineProperty(*prototype, + if (jsrt::DefinePropertyById(*prototype, iso->GetToStringTagSymbolPropertyIdRef(), jsrt::PropertyDescriptorOptionValues::True, /* writable */ jsrt::PropertyDescriptorOptionValues::False, /* enumerable */ @@ -289,7 +289,7 @@ class FunctionTemplateData : public TemplateData { } } - if (jsrt::DefineProperty(*prototype, + if (jsrt::DefinePropertyById(*prototype, iso->GetCachedPropertyIdRef( jsrt::CachedPropertyIdRef::constructor), jsrt::PropertyDescriptorOptionValues::True, /* writable */ diff --git a/deps/chakrashim/src/v8object.cc b/deps/chakrashim/src/v8object.cc index 4eb026ff388..48210b24c50 100644 --- a/deps/chakrashim/src/v8object.cc +++ b/deps/chakrashim/src/v8object.cc @@ -66,16 +66,11 @@ bool Object::Set(Handle key, Handle value) { Maybe Object::Set(Handle key, Handle value, PropertyAttribute attribs, bool force) { - JsPropertyIdRef idRef; - - if (jsrt::GetPropertyIdFromValue((JsValueRef)*key, &idRef) != JsNoError) { - return Nothing(); - } - // Do it faster if there are no property attributes if (!force && attribs == None) { - if (JsSetProperty((JsValueRef)this, - idRef, (JsValueRef)*value, false) != JsNoError) { + if (JsObjectSetProperty((JsValueRef)this, + (JsValueRef)*key, (JsValueRef)*value, + false) != JsNoError) { return Nothing(); } } else { // we have attributes just use it @@ -100,8 +95,8 @@ Maybe Object::Set(Handle key, Handle value, configurable = jsrt::PropertyDescriptorOptionValues::True; } - if (jsrt::DefineProperty((JsValueRef)this, - idRef, + if (jsrt::DefinePropertyByName((JsValueRef)this, + (JsValueRef)*key, writable, enumerable, configurable, @@ -134,12 +129,6 @@ Maybe Object::DefineOwnProperty( Maybe Object::DefineProperty(Local context, Local key, PropertyDescriptor& descriptor) { - JsPropertyIdRef idRef; - - if (jsrt::GetPropertyIdFromValue((JsValueRef)*key, &idRef) != JsNoError) { - return Nothing(); - } - Local value = descriptor.value(); Local get = descriptor.get(); Local set = descriptor.set(); @@ -149,8 +138,9 @@ Maybe Object::DefineProperty(Local context, !descriptor.has_enumerable() && !descriptor.has_configurable() && !descriptor.has_writable()) { - if (JsSetProperty((JsValueRef)this, - idRef, (JsValueRef)*value, false) != JsNoError) { + if (JsObjectSetProperty((JsValueRef)this, + (JsValueRef)*key, (JsValueRef)*value, + false) != JsNoError) { return Nothing(); } } else { // we have attributes just use it @@ -179,8 +169,8 @@ Maybe Object::DefineProperty(Local context, jsrt::PropertyDescriptorOptionValues::False; } - if (jsrt::DefineProperty((JsValueRef)this, - idRef, + if (jsrt::DefinePropertyByName((JsValueRef)this, + (JsValueRef)*key, writable, enumerable, configurable, @@ -280,13 +270,8 @@ Local Object::GetOwnPropertyDescriptor(Local key) { } Maybe Object::Has(Local context, Local key) { - JsPropertyIdRef idRef; - if (jsrt::GetPropertyIdFromValue((JsValueRef)*key, &idRef) != JsNoError) { - return Nothing(); - } - bool result; - if (JsHasProperty(this, idRef, &result) != JsNoError) { + if (JsHasProperty(this, (JsValueRef)*key, &result) != JsNoError) { return Nothing(); } @@ -298,13 +283,8 @@ bool Object::Has(Handle key) { } Maybe Object::Delete(Local context, Local key) { - JsPropertyIdRef idRef; - if (jsrt::GetPropertyIdFromValue((JsValueRef)*key, &idRef) != JsNoError) { - return Nothing(); - } - JsValueRef result; - if (JsDeleteProperty(this, idRef, false, &result) != JsNoError) { + if (JsDeleteProperty(this, (JsValueRef)*key, false, &result) != JsNoError) { return Nothing(); } @@ -356,11 +336,6 @@ Maybe Object::SetAccessor(Handle name, JsValueRef getterRef = JS_INVALID_REFERENCE; JsValueRef setterRef = JS_INVALID_REFERENCE; - JsPropertyIdRef idRef; - if (jsrt::GetPropertyIdFromName((JsValueRef)*name, &idRef) != JsNoError) { - return Nothing(); - } - if (getter != nullptr) { AccessorExternalData *externalData = new AccessorExternalData(); externalData->type = Getter; @@ -400,8 +375,8 @@ Maybe Object::SetAccessor(Handle name, // CHAKRA-TODO: we ignore AccessControl for now.. - if (jsrt::DefineProperty((JsValueRef)this, - idRef, + if (jsrt::DefinePropertyByName((JsValueRef)this, + (JsValueRef)*name, jsrt::PropertyDescriptorOptionValues::None, enumerable, configurable, @@ -828,10 +803,6 @@ void Object::SetAccessorProperty(Local name, Local getter, Local setter, PropertyAttribute attribute, AccessControl settings) { - JsPropertyIdRef idRef; - if (jsrt::GetPropertyIdFromName((JsValueRef)*name, &idRef) != JsNoError) { - return; - } jsrt::PropertyDescriptorOptionValues enumerable = jsrt::GetPropertyDescriptorOptionValue(!(attribute & DontEnum)); @@ -840,8 +811,8 @@ void Object::SetAccessorProperty(Local name, Local getter, // CHAKRA-TODO: we ignore AccessControl for now.. - if (jsrt::DefineProperty((JsValueRef)this, - idRef, + if (jsrt::DefinePropertyByName((JsValueRef)this, + (JsValueRef)*name, jsrt::PropertyDescriptorOptionValues::None, enumerable, configurable, diff --git a/deps/chakrashim/src/v8objecttemplate.cc b/deps/chakrashim/src/v8objecttemplate.cc index 30ced0edda6..f3d76d683c6 100755 --- a/deps/chakrashim/src/v8objecttemplate.cc +++ b/deps/chakrashim/src/v8objecttemplate.cc @@ -780,14 +780,8 @@ JsValueRef CHAKRA_CALLBACK Utils::DefinePropertyCallback( } 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) + if (JsObjectDefineProperty(object, prop, descriptor, &result) != JsNoError || !result) { return jsrt::GetFalse(); }