From 11678aa48cf3dcbab8d45b3722ea5918e5a47da2 Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Mon, 12 Aug 2013 12:09:14 +0100 Subject: [PATCH] Bug 903352 - Handlify remaining PropertyDescriptor APIs r=terrence r=bholley r=smaug --- content/base/public/nsContentUtils.h | 2 +- content/base/src/nsContentUtils.cpp | 2 +- content/xbl/src/nsXBLBinding.cpp | 8 +-- content/xbl/src/nsXBLBinding.h | 5 +- content/xbl/src/nsXBLProtoImpl.cpp | 2 +- content/xbl/src/nsXBLProtoImpl.h | 26 ++++---- dom/bindings/BindingUtils.cpp | 65 +++++++++---------- dom/bindings/BindingUtils.h | 2 +- dom/bindings/Codegen.py | 6 +- dom/bindings/DOMJSProxyHandler.cpp | 2 +- js/ipc/JavaScriptChild.cpp | 8 +-- js/src/jit/AsmJSLink.cpp | 8 +-- js/src/jsapi.cpp | 10 +-- js/src/jsapi.h | 17 +++-- js/src/jsfriendapi.cpp | 10 +-- js/src/jsfriendapi.h | 16 +---- js/src/jsproxy.cpp | 15 ++--- js/src/vm/ScopeObject.cpp | 2 +- js/xpconnect/src/XPCComponents.cpp | 4 +- js/xpconnect/wrappers/AccessCheck.cpp | 2 +- js/xpconnect/wrappers/ChromeObjectWrapper.cpp | 4 +- js/xpconnect/wrappers/XrayWrapper.cpp | 29 +++++---- 22 files changed, 115 insertions(+), 130 deletions(-) diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 4eecbf17288..0e901979d64 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -194,7 +194,7 @@ public: static bool IsImageSrcSetDisabled(); static bool LookupBindingMember(JSContext* aCx, nsIContent *aContent, - JS::HandleId aId, JSPropertyDescriptor* aDesc); + JS::HandleId aId, JS::MutableHandle aDesc); /** * Returns the parent node of aChild crossing document boundaries. diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 7db0f1561ba..79583f1b704 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -1756,7 +1756,7 @@ nsContentUtils::IsImageSrcSetDisabled() // static bool nsContentUtils::LookupBindingMember(JSContext* aCx, nsIContent *aContent, - JS::HandleId aId, JSPropertyDescriptor* aDesc) + JS::HandleId aId, JS::MutableHandle aDesc) { nsXBLBinding* binding = aContent->GetXBLBinding(); if (!binding) diff --git a/content/xbl/src/nsXBLBinding.cpp b/content/xbl/src/nsXBLBinding.cpp index 9f0042a8e00..fdc1c459221 100644 --- a/content/xbl/src/nsXBLBinding.cpp +++ b/content/xbl/src/nsXBLBinding.cpp @@ -1105,10 +1105,10 @@ nsXBLBinding::ResolveAllFields(JSContext *cx, JS::Handle obj) const bool nsXBLBinding::LookupMember(JSContext* aCx, JS::HandleId aId, - JSPropertyDescriptor* aDesc) + JS::MutableHandle aDesc) { // We should never enter this function with a pre-filled property descriptor. - MOZ_ASSERT(!aDesc->obj); + MOZ_ASSERT(!aDesc.object()); // Get the string as an nsString before doing anything, so we can make // convenient comparisons during our search. @@ -1148,7 +1148,7 @@ nsXBLBinding::LookupMember(JSContext* aCx, JS::HandleId aId, bool nsXBLBinding::LookupMemberInternal(JSContext* aCx, nsString& aName, JS::HandleId aNameAsId, - JSPropertyDescriptor* aDesc, + JS::MutableHandle aDesc, JS::Handle aXBLScope) { // First, see if we have a JSClass. If we don't, it means that this binding @@ -1186,7 +1186,7 @@ nsXBLBinding::LookupMemberInternal(JSContext* aCx, nsString& aName, { return false; } - if (aDesc->obj || !mNextBinding) { + if (aDesc.object() || !mNextBinding) { return true; } diff --git a/content/xbl/src/nsXBLBinding.h b/content/xbl/src/nsXBLBinding.h index 072c4e76a20..add13ebf2bb 100644 --- a/content/xbl/src/nsXBLBinding.h +++ b/content/xbl/src/nsXBLBinding.h @@ -81,7 +81,7 @@ public: * May only be called when XBL code is being run in a separate scope, because * otherwise we don't have untainted data with which to do a proper lookup. */ - bool LookupMember(JSContext* aCx, JS::HandleId aId, JSPropertyDescriptor* aDesc); + bool LookupMember(JSContext* aCx, JS::HandleId aId, JS::MutableHandle aDesc); /* * Determines whether the binding has a field with the given name. @@ -94,7 +94,8 @@ protected: * Internal version. Requires that aCx is in appropriate xbl scope. */ bool LookupMemberInternal(JSContext* aCx, nsString& aName, JS::HandleId aNameAsId, - JSPropertyDescriptor* aDesc, JS::Handle aXBLScope); + JS::MutableHandle aDesc, + JS::Handle aXBLScope); public: diff --git a/content/xbl/src/nsXBLProtoImpl.cpp b/content/xbl/src/nsXBLProtoImpl.cpp index 124f9720c11..6025464f404 100644 --- a/content/xbl/src/nsXBLProtoImpl.cpp +++ b/content/xbl/src/nsXBLProtoImpl.cpp @@ -216,7 +216,7 @@ nsXBLProtoImpl::CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding) bool nsXBLProtoImpl::LookupMember(JSContext* aCx, nsString& aName, JS::HandleId aNameAsId, - JSPropertyDescriptor* aDesc, + JS::MutableHandle aDesc, JSObject* aClassObject) { for (nsXBLProtoImplMember* m = mMembers; m; m = m->GetNext()) { diff --git a/content/xbl/src/nsXBLProtoImpl.h b/content/xbl/src/nsXBLProtoImpl.h index b6314abedb9..52dc799427e 100644 --- a/content/xbl/src/nsXBLProtoImpl.h +++ b/content/xbl/src/nsXBLProtoImpl.h @@ -19,34 +19,34 @@ class nsXBLProtoImplAnonymousMethod; class nsXBLProtoImpl { public: - nsXBLProtoImpl() + nsXBLProtoImpl() : mClassObject(nullptr), mMembers(nullptr), mFields(nullptr), mConstructor(nullptr), mDestructor(nullptr) - { - MOZ_COUNT_CTOR(nsXBLProtoImpl); + { + MOZ_COUNT_CTOR(nsXBLProtoImpl); } - ~nsXBLProtoImpl() - { + ~nsXBLProtoImpl() + { MOZ_COUNT_DTOR(nsXBLProtoImpl); // Note: the constructor and destructor are in mMembers, so we'll // clean them up automatically. delete mMembers; delete mFields; } - + nsresult InstallImplementation(nsXBLPrototypeBinding* aPrototypeBinding, nsXBLBinding* aBinding); nsresult InitTargetObjects(nsXBLPrototypeBinding* aBinding, - nsIContent* aBoundElement, + nsIContent* aBoundElement, nsIXPConnectJSObjectHolder** aScriptObjectHolder, JS::MutableHandle aTargetClassObject, bool* aTargetIsNew); nsresult CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding); bool LookupMember(JSContext* aCx, nsString& aName, JS::HandleId aNameAsId, - JSPropertyDescriptor* aDesc, JSObject* aClassObject); + JS::MutableHandle aDesc, JSObject* aClassObject); void SetMemberList(nsXBLProtoImplMember* aMemberList) { @@ -95,9 +95,9 @@ protected: } void DestroyMembers(); - + public: - nsCString mClassName; // The name of the class. + nsCString mClassName; // The name of the class. protected: JSObject* mClassObject; // The class object for the binding. We'll use this to pre-compile properties @@ -106,15 +106,15 @@ protected: nsXBLProtoImplMember* mMembers; // The members of an implementation are chained in this singly-linked list. nsXBLProtoImplField* mFields; // Our fields - + public: nsXBLProtoImplAnonymousMethod* mConstructor; // Our class constructor. nsXBLProtoImplAnonymousMethod* mDestructor; // Our class destructor. }; nsresult -NS_NewXBLProtoImpl(nsXBLPrototypeBinding* aBinding, - const PRUnichar* aClassName, +NS_NewXBLProtoImpl(nsXBLPrototypeBinding* aBinding, + const PRUnichar* aClassName, nsXBLProtoImpl** aResult); #endif // nsXBLProtoImpl_h__ diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index d9d1f3de344..d76f62a9190 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -829,7 +829,7 @@ static bool XrayResolveAttribute(JSContext* cx, JS::Handle wrapper, JS::Handle obj, JS::Handle id, const Prefable* attributes, jsid* attributeIds, - const JSPropertySpec* attributeSpecs, JSPropertyDescriptor* desc) + const JSPropertySpec* attributeSpecs, JS::MutableHandle desc) { for (; attributes->specs; ++attributes) { if (attributes->isEnabled(cx, obj)) { @@ -842,7 +842,7 @@ XrayResolveAttribute(JSContext* cx, JS::Handle wrapper, // Because of centralization, we need to make sure we fault in the // JitInfos as well. At present, until the JSAPI changes, the easiest // way to do this is wrap them up as functions ourselves. - desc->attrs = attrSpec.flags & ~JSPROP_NATIVE_ACCESSORS; + desc.setAttributes(attrSpec.flags & ~JSPROP_NATIVE_ACCESSORS); // They all have getters, so we can just make it. JS::Rooted global(cx, JS_GetGlobalForObject(cx, wrapper)); JS::Rooted fun(cx, @@ -852,8 +852,8 @@ XrayResolveAttribute(JSContext* cx, JS::Handle wrapper, return false; SET_JITINFO(fun, attrSpec.getter.info); JSObject *funobj = JS_GetFunctionObject(fun); - desc->getter = js::CastAsJSPropertyOp(funobj); - desc->attrs |= JSPROP_GETTER; + desc.setGetterObject(funobj); + desc.attributesRef() |= JSPROP_GETTER; if (attrSpec.setter.op) { // We have a setter! Make it. fun = JS_NewFunctionById(cx, (JSNative)attrSpec.setter.op, 1, 0, @@ -862,12 +862,12 @@ XrayResolveAttribute(JSContext* cx, JS::Handle wrapper, return false; SET_JITINFO(fun, attrSpec.setter.info); funobj = JS_GetFunctionObject(fun); - desc->setter = js::CastAsJSStrictPropertyOp(funobj); - desc->attrs |= JSPROP_SETTER; + desc.setSetterObject(funobj); + desc.attributesRef() |= JSPROP_SETTER; } else { - desc->setter = nullptr; + desc.setSetter(nullptr); } - desc->obj = wrapper; + desc.object().set(wrapper); return true; } } @@ -879,7 +879,7 @@ XrayResolveAttribute(JSContext* cx, JS::Handle wrapper, static bool XrayResolveProperty(JSContext* cx, JS::Handle wrapper, JS::Handle obj, JS::Handle id, - JSPropertyDescriptor* desc, DOMObjectType type, + JS::MutableHandle desc, DOMObjectType type, const NativeProperties* nativeProperties) { const Prefable* methods; @@ -912,11 +912,11 @@ XrayResolveProperty(JSContext* cx, JS::Handle wrapper, } SET_JITINFO(fun, methodSpec.call.info); JSObject *funobj = JS_GetFunctionObject(fun); - desc->value.setObject(*funobj); - desc->attrs = methodSpec.flags; - desc->obj = wrapper; - desc->setter = nullptr; - desc->getter = nullptr; + desc.value().setObject(*funobj); + desc.setAttributes(methodSpec.flags); + desc.object().set(wrapper); + desc.setSetter(nullptr); + desc.setGetter(nullptr); return true; } } @@ -932,7 +932,7 @@ XrayResolveProperty(JSContext* cx, JS::Handle wrapper, nativeProperties->staticAttributeSpecs, desc)) { return false; } - if (desc->obj) { + if (desc.object()) { return true; } } @@ -944,7 +944,7 @@ XrayResolveProperty(JSContext* cx, JS::Handle wrapper, nativeProperties->attributeSpecs, desc)) { return false; } - if (desc->obj) { + if (desc.object()) { return true; } } @@ -956,7 +956,7 @@ XrayResolveProperty(JSContext* cx, JS::Handle wrapper, desc)) { return false; } - if (desc->obj) { + if (desc.object()) { return true; } } @@ -971,9 +971,9 @@ XrayResolveProperty(JSContext* cx, JS::Handle wrapper, size_t i = constant->specs - nativeProperties->constantSpecs; for ( ; nativeProperties->constantIds[i] != JSID_VOID; ++i) { if (id == nativeProperties->constantIds[i]) { - desc->attrs = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT; - desc->obj = wrapper; - desc->value = nativeProperties->constantSpecs[i].value; + desc.setAttributes(JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT); + desc.object().set(wrapper); + desc.value().set(nativeProperties->constantSpecs[i].value); return true; } } @@ -988,7 +988,7 @@ static bool ResolvePrototypeOrConstructor(JSContext* cx, JS::Handle wrapper, JS::Handle obj, size_t protoAndIfaceArrayIndex, unsigned attrs, - JSPropertyDescriptor* desc) + JS::MutableHandle desc) { JS::Rooted global(cx, js::GetGlobalForObjectCrossCompartment(obj)); { @@ -998,12 +998,12 @@ ResolvePrototypeOrConstructor(JSContext* cx, JS::Handle wrapper, if (!protoOrIface) { return false; } - desc->obj = wrapper; - desc->shortid = 0; - desc->attrs = attrs; - desc->getter = JS_PropertyStub; - desc->setter = JS_StrictPropertyStub; - desc->value = JS::ObjectValue(*protoOrIface); + desc.object().set(wrapper); + desc.setShortId(0); + desc.setAttributes(attrs); + desc.setGetter(JS_PropertyStub); + desc.setSetter(JS_StrictPropertyStub); + desc.value().set(JS::ObjectValue(*protoOrIface)); } return JS_WrapPropertyDescriptor(cx, desc); } @@ -1013,7 +1013,7 @@ XrayResolveNativeProperty(JSContext* cx, JS::Handle wrapper, const NativePropertyHooks* nativePropertyHooks, DOMObjectType type, JS::Handle obj, JS::Handle id, - JSPropertyDescriptor* desc) + JS::MutableHandle desc) { if (type == eInterface && IdEquals(id, "prototype")) { return nativePropertyHooks->mPrototypeID == prototypes::id::_ID_Count || @@ -1039,7 +1039,7 @@ XrayResolveNativeProperty(JSContext* cx, JS::Handle wrapper, return false; } - if (!desc->obj && + if (!desc.object() && nativeProperties.chromeOnly && xpc::AccessCheck::isChrome(js::GetObjectCompartment(wrapper)) && !XrayResolveProperty(cx, wrapper, obj, id, desc, type, @@ -1053,7 +1053,7 @@ XrayResolveNativeProperty(JSContext* cx, JS::Handle wrapper, bool XrayResolveNativeProperty(JSContext* cx, JS::Handle wrapper, JS::Handle obj, - JS::Handle id, JSPropertyDescriptor* desc) + JS::Handle id, JS::MutableHandle desc) { DOMObjectType type; const NativePropertyHooks* nativePropertyHooks = @@ -1072,7 +1072,7 @@ XrayResolveNativeProperty(JSContext* cx, JS::Handle wrapper, return false; } - if (desc->obj) { + if (desc.object()) { return true; } } while ((nativePropertyHooks = nativePropertyHooks->mProtoHooks)); @@ -1459,8 +1459,7 @@ NativeToString(JSContext* cx, JS::Handle wrapper, toStringDesc.value().set(JS::UndefinedValue()); JS::Rooted id(cx, nsXPConnect::GetRuntimeInstance()->GetStringID(XPCJSRuntime::IDX_TO_STRING)); - if (!XrayResolveNativeProperty(cx, wrapper, obj, id, - toStringDesc.address())) { + if (!XrayResolveNativeProperty(cx, wrapper, obj, id, &toStringDesc)) { return false; } diff --git a/dom/bindings/BindingUtils.h b/dom/bindings/BindingUtils.h index fc9e79b7a14..3e36909445a 100644 --- a/dom/bindings/BindingUtils.h +++ b/dom/bindings/BindingUtils.h @@ -1924,7 +1924,7 @@ XrayResolveOwnProperty(JSContext* cx, JS::Handle wrapper, bool XrayResolveNativeProperty(JSContext* cx, JS::Handle wrapper, JS::Handle obj, - JS::Handle id, JSPropertyDescriptor* desc); + JS::Handle id, JS::MutableHandle desc); /** * Define a property on obj through an Xray wrapper. diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 71e4210edde..17f227c1bda 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -7125,7 +7125,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(ClassMethod): "}\n") % (self.descriptor.nativeType) if UseHolderForUnforgeable(self.descriptor): - getUnforgeable = """if (!JS_GetPropertyDescriptorById(cx, ${holder}, id, flags, desc.address())) { + getUnforgeable = """if (!JS_GetPropertyDescriptorById(cx, ${holder}, id, flags, desc)) { return false; } MOZ_ASSERT_IF(desc.object(), desc.object() == ${holder});""" @@ -7133,7 +7133,7 @@ MOZ_ASSERT_IF(desc.object(), desc.object() == ${holder});""" getUnforgeable, "isXray") getUnforgeable += """if (desc.object()) { desc.object().set(proxy); - return !isXray || JS_WrapPropertyDescriptor(cx, desc.address()); + return !isXray || JS_WrapPropertyDescriptor(cx, desc); } """ @@ -7202,7 +7202,7 @@ MOZ_ASSERT_IF(desc.object(), desc.object() == ${holder});""" return setOrIndexedGet + """JS::Rooted expando(cx); if (!isXray && (expando = GetExpandoObject(proxy))) { - if (!JS_GetPropertyDescriptorById(cx, expando, id, flags, desc.address())) { + if (!JS_GetPropertyDescriptorById(cx, expando, id, flags, desc)) { return false; } if (desc.object()) { diff --git a/dom/bindings/DOMJSProxyHandler.cpp b/dom/bindings/DOMJSProxyHandler.cpp index 73eb7dfb721..a610899821c 100644 --- a/dom/bindings/DOMJSProxyHandler.cpp +++ b/dom/bindings/DOMJSProxyHandler.cpp @@ -182,7 +182,7 @@ BaseDOMProxyHandler::getPropertyDescriptor(JSContext* cx, return true; } - return JS_GetPropertyDescriptorById(cx, proto, id, 0, desc.address()); + return JS_GetPropertyDescriptorById(cx, proto, id, 0, desc); } bool diff --git a/js/ipc/JavaScriptChild.cpp b/js/ipc/JavaScriptChild.cpp index f87e0fa0c2f..7a87e15fb6a 100644 --- a/js/ipc/JavaScriptChild.cpp +++ b/js/ipc/JavaScriptChild.cpp @@ -189,7 +189,7 @@ JavaScriptChild::AnswerGetPropertyDescriptor(const ObjectId &objId, const nsStri return fail(cx, rs); Rooted desc(cx); - if (!JS_GetPropertyDescriptorById(cx, obj, internedId, flags, desc.address())) + if (!JS_GetPropertyDescriptorById(cx, obj, internedId, flags, &desc)) return fail(cx, rs); if (!desc.object()) @@ -222,7 +222,7 @@ JavaScriptChild::AnswerGetOwnPropertyDescriptor(const ObjectId &objId, const nsS return fail(cx, rs); Rooted desc(cx); - if (!JS_GetPropertyDescriptorById(cx, obj, internedId, flags, desc.address())) + if (!JS_GetPropertyDescriptorById(cx, obj, internedId, flags, &desc)) return fail(cx, rs); if (desc.object() != obj) @@ -339,10 +339,10 @@ JavaScriptChild::AnswerHasOwn(const ObjectId &objId, const nsString &id, ReturnS if (!convertGeckoStringToId(cx, id, &internedId)) return fail(cx, rs); - JSPropertyDescriptor desc; + Rooted desc(cx); if (!JS_GetPropertyDescriptorById(cx, obj, internedId, 0, &desc)) return fail(cx, rs); - *bp = (desc.obj == obj); + *bp = (desc.object() == obj); return ok(rs); } diff --git a/js/src/jit/AsmJSLink.cpp b/js/src/jit/AsmJSLink.cpp index e55673f897a..8c404c8011f 100644 --- a/js/src/jit/AsmJSLink.cpp +++ b/js/src/jit/AsmJSLink.cpp @@ -46,17 +46,17 @@ GetDataProperty(JSContext *cx, const Value &objVal, HandlePropertyName field, Mu if (!objVal.isObject()) return LinkFail(cx, "accessing property of non-object"); - JSPropertyDescriptor desc; + Rooted desc(cx); if (!JS_GetPropertyDescriptorById(cx, &objVal.toObject(), NameToId(field), 0, &desc)) return false; - if (!desc.obj) + if (!desc.object()) return LinkFail(cx, "property not present on object"); - if (desc.attrs & (JSPROP_GETTER | JSPROP_SETTER)) + if (desc.hasGetterOrSetterObject()) return LinkFail(cx, "property is not a data property"); - v.set(desc.value); + v.set(desc.value()); return true; } diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index a9787db6e4f..d5efee6b167 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -3601,7 +3601,7 @@ GetPropertyDescriptorById(JSContext *cx, HandleObject obj, HandleId id, unsigned if (!LookupPropertyById(cx, obj, id, flags, &obj2, &shape)) return false; - JS_ASSERT(desc.isClear()); + desc.clear(); if (!shape || (own && obj != obj2)) return true; @@ -3636,15 +3636,11 @@ GetPropertyDescriptorById(JSContext *cx, HandleObject obj, HandleId id, unsigned JS_PUBLIC_API(bool) JS_GetPropertyDescriptorById(JSContext *cx, JSObject *objArg, jsid idArg, unsigned flags, - JSPropertyDescriptor *desc_) + MutableHandle desc) { RootedObject obj(cx, objArg); RootedId id(cx, idArg); - Rooted desc(cx); - if (!GetPropertyDescriptorById(cx, obj, id, flags, false, &desc)) - return false; - *desc_ = desc; - return true; + return GetPropertyDescriptorById(cx, obj, id, flags, false, desc); } JS_PUBLIC_API(bool) diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 53ae6d49cfa..d250f7d7950 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -3478,11 +3478,6 @@ class PropertyDescriptorOperations JS::Handle value() const { return JS::Handle::fromMarkedLocation(&desc()->value); } - - bool isClear() const { - return desc()->obj == NULL && desc()->attrs == 0 && desc()->getter == NULL && - desc()->setter == NULL && desc()->value.isUndefined(); - } }; template @@ -3491,6 +3486,16 @@ class MutablePropertyDescriptorOperations : public PropertyDescriptorOperations< JSPropertyDescriptor * desc() { return static_cast(this)->extractMutable(); } public: + + void clear() { + object().set(NULL); + setAttributes(0); + setShortId(0); + setGetter(NULL); + setSetter(NULL); + value().setUndefined(); + } + JS::MutableHandle object() { return JS::MutableHandle::fromMarkedLocation(&desc()->obj); } @@ -3574,7 +3579,7 @@ class MutableHandleBase */ extern JS_PUBLIC_API(bool) JS_GetPropertyDescriptorById(JSContext *cx, JSObject *obj, jsid id, unsigned flags, - JSPropertyDescriptor *desc); + JS::MutableHandle desc); extern JS_PUBLIC_API(bool) JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *obj, jsid id, JS::MutableHandle vp); diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index b05e17b4061..f8dd7332deb 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -244,12 +244,9 @@ JS_SetCompartmentPrincipals(JSCompartment *compartment, JSPrincipals *principals } JS_FRIEND_API(bool) -JS_WrapPropertyDescriptor(JSContext *cx, js::PropertyDescriptor *descArg) +JS_WrapPropertyDescriptor(JSContext *cx, JS::MutableHandle desc) { - Rooted desc(cx, *descArg); - bool status = cx->compartment()->wrap(cx, &desc); - *descArg = desc; - return status; + return cx->compartment()->wrap(cx, desc); } JS_FRIEND_API(bool) @@ -1092,11 +1089,10 @@ js::GetObjectMetadata(JSObject *obj) JS_FRIEND_API(bool) js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg, - const js::PropertyDescriptor& descriptorArg, bool *bp) + JS::Handle descriptor, bool *bp) { RootedObject obj(cx, objArg); RootedId id(cx, idArg); - Rooted descriptor(cx, descriptorArg); JS_ASSERT(cx->runtime()->heapState == js::Idle); CHECK_REQUEST(cx); assertSameCompartment(cx, obj, id, descriptor.value()); diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h index ff568b9bda7..7c9d83aa2b8 100644 --- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -175,7 +175,7 @@ extern JS_FRIEND_API(bool) JS_CopyPropertiesFrom(JSContext *cx, JSObject *target, JSObject *obj); extern JS_FRIEND_API(bool) -JS_WrapPropertyDescriptor(JSContext *cx, JSPropertyDescriptor *desc); +JS_WrapPropertyDescriptor(JSContext *cx, JS::MutableHandle desc); extern JS_FRIEND_API(bool) JS_WrapAutoIdVector(JSContext *cx, JS::AutoIdVector &props); @@ -575,18 +575,6 @@ AtomToLinearString(JSAtom *atom) return reinterpret_cast(atom); } -static inline JSPropertyOp -CastAsJSPropertyOp(JSObject *object) -{ - return JS_DATA_TO_FUNC_PTR(JSPropertyOp, object); -} - -static inline JSStrictPropertyOp -CastAsJSStrictPropertyOp(JSObject *object) -{ - return JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, object); -} - JS_FRIEND_API(bool) GetPropertyNames(JSContext *cx, JSObject *obj, unsigned flags, js::AutoIdVector *props); @@ -1816,7 +1804,7 @@ class AsmJSModuleSourceDesc extern JS_FRIEND_API(bool) js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg, - const JSPropertyDescriptor& descriptor, bool *bp); + JS::Handle descriptor, bool *bp); extern JS_FRIEND_API(bool) js_ReportIsNotFunction(JSContext *cx, const JS::Value& v); diff --git a/js/src/jsproxy.cpp b/js/src/jsproxy.cpp index 8d456e4614e..6a18d56544d 100644 --- a/js/src/jsproxy.cpp +++ b/js/src/jsproxy.cpp @@ -370,7 +370,7 @@ DirectProxyHandler::getPropertyDescriptor(JSContext *cx, HandleObject proxy, Han assertEnteredPolicy(cx, proxy, id); JS_ASSERT(!hasPrototype()); // Should never be called if there's a prototype. RootedObject target(cx, proxy->as().target()); - return JS_GetPropertyDescriptorById(cx, target, id, 0, desc.address()); + return JS_GetPropertyDescriptorById(cx, target, id, 0, desc); } static bool @@ -382,7 +382,7 @@ GetOwnPropertyDescriptor(JSContext *cx, HandleObject obj, HandleId id, unsigned if (obj->is()) return Proxy::getOwnPropertyDescriptor(cx, obj, id, desc, flags); - if (!JS_GetPropertyDescriptorById(cx, obj, id, flags, desc.address())) + if (!JS_GetPropertyDescriptorById(cx, obj, id, flags, desc)) return false; if (desc.object() != obj) desc.object().set(NULL); @@ -553,7 +553,7 @@ DirectProxyHandler::hasOwn(JSContext *cx, HandleObject proxy, HandleId id, bool assertEnteredPolicy(cx, proxy, id); RootedObject target(cx, proxy->as().target()); Rooted desc(cx); - if (!JS_GetPropertyDescriptorById(cx, target, id, 0, desc.address())) + if (!JS_GetPropertyDescriptorById(cx, target, id, 0, &desc)) return false; *bp = (desc.object() == target); return true; @@ -1321,7 +1321,7 @@ static bool HasOwn(JSContext *cx, HandleObject obj, HandleId id, bool *bp) { Rooted desc(cx); - if (!JS_GetPropertyDescriptorById(cx, obj, id, 0, desc.address())) + if (!JS_GetPropertyDescriptorById(cx, obj, id, 0, &desc)) return false; *bp = (desc.object() == obj); return true; @@ -1716,7 +1716,7 @@ ScriptedDirectProxyHandler::getPropertyDescriptor(JSContext *cx, HandleObject pr JS_ASSERT(!desc.object()); return true; } - return JS_GetPropertyDescriptorById(cx, proto, id, 0, desc.address()); + return JS_GetPropertyDescriptorById(cx, proto, id, 0, desc); } bool @@ -2310,8 +2310,7 @@ Proxy::getPropertyDescriptor(JSContext *cx, HandleObject proxy, HandleId id, return false; if (desc.object()) return true; - INVOKE_ON_PROTOTYPE(cx, handler, proxy, - JS_GetPropertyDescriptorById(cx, proto, id, 0, desc.address())); + INVOKE_ON_PROTOTYPE(cx, handler, proxy, JS_GetPropertyDescriptorById(cx, proto, id, 0, desc)); } bool @@ -2544,7 +2543,7 @@ Proxy::set(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id return false; if (proto) { Rooted desc(cx); - if (!JS_GetPropertyDescriptorById(cx, proto, id, 0, desc.address())) + if (!JS_GetPropertyDescriptorById(cx, proto, id, 0, &desc)) return false; if (desc.object() && desc.setter()) return JSObject::setGeneric(cx, proto, receiver, id, vp, strict); diff --git a/js/src/vm/ScopeObject.cpp b/js/src/vm/ScopeObject.cpp index b5837ac2905..7cdc7f81eaa 100644 --- a/js/src/vm/ScopeObject.cpp +++ b/js/src/vm/ScopeObject.cpp @@ -1415,7 +1415,7 @@ class DebugScopeProxy : public BaseProxyHandler return true; } - return JS_GetPropertyDescriptorById(cx, scope, id, 0, desc.address()); + return JS_GetPropertyDescriptorById(cx, scope, id, 0, desc); } bool get(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id, diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index 7f18988600b..619e00680bb 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -2693,7 +2693,7 @@ nsXPCComponents_Utils::LookupMethod(const JS::Value& object, // Alright, now do the lookup. *retval = UndefinedValue(); Rooted desc(cx); - if (!JS_GetPropertyDescriptorById(cx, xray, methodId, 0, desc.address())) + if (!JS_GetPropertyDescriptorById(cx, xray, methodId, 0, &desc)) return NS_ERROR_FAILURE; // First look for a method value. If that's not there, try a getter, @@ -3141,7 +3141,7 @@ xpc::SandboxProxyHandler::getPropertyDescriptor(JSContext *cx, MOZ_ASSERT(js::GetObjectCompartment(obj) == js::GetObjectCompartment(proxy)); if (!JS_GetPropertyDescriptorById(cx, obj, id, - flags, desc.address())) + flags, desc)) return false; if (!desc.object()) diff --git a/js/xpconnect/wrappers/AccessCheck.cpp b/js/xpconnect/wrappers/AccessCheck.cpp index dbe0093fde2..3f3b4ff5778 100644 --- a/js/xpconnect/wrappers/AccessCheck.cpp +++ b/js/xpconnect/wrappers/AccessCheck.cpp @@ -348,7 +348,7 @@ ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapperArg, jsid idArg, Wr Access access = NO_ACCESS; Rooted desc(cx); - if (!JS_GetPropertyDescriptorById(cx, hallpass, id, 0, desc.address())) { + if (!JS_GetPropertyDescriptorById(cx, hallpass, id, 0, &desc)) { return false; // Error } if (!desc.object() || !desc.isEnumerable()) diff --git a/js/xpconnect/wrappers/ChromeObjectWrapper.cpp b/js/xpconnect/wrappers/ChromeObjectWrapper.cpp index 05e1a662aa7..15468dce777 100644 --- a/js/xpconnect/wrappers/ChromeObjectWrapper.cpp +++ b/js/xpconnect/wrappers/ChromeObjectWrapper.cpp @@ -90,7 +90,7 @@ ChromeObjectWrapper::getPropertyDescriptor(JSContext *cx, // If not, try doing the lookup on the prototype. MOZ_ASSERT(js::IsObjectInContextCompartment(wrapper, cx)); - return JS_GetPropertyDescriptorById(cx, wrapperProto, id, 0, desc.address()); + return JS_GetPropertyDescriptorById(cx, wrapperProto, id, 0, desc); } bool @@ -115,7 +115,7 @@ ChromeObjectWrapper::has(JSContext *cx, HandleObject wrapper, // Try the prototype if that failed. MOZ_ASSERT(js::IsObjectInContextCompartment(wrapper, cx)); Rooted desc(cx); - if (!JS_GetPropertyDescriptorById(cx, wrapperProto, id, 0, desc.address())) + if (!JS_GetPropertyDescriptorById(cx, wrapperProto, id, 0, &desc)) return false; *bp = !!desc.object(); return true; diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index 3294710c310..9dabe3068ec 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -207,7 +207,7 @@ public: static bool resolveDOMCollectionProperty(JSContext *cx, HandleObject wrapper, HandleObject holder, HandleId id, - JSPropertyDescriptor *desc, unsigned flags); + MutableHandle desc, unsigned flags); static XPCWrappedNative* getWN(JSObject *wrapper) { return XPCWrappedNative::Get(getTargetObject(wrapper)); @@ -615,7 +615,8 @@ private: bool XPCWrappedNativeXrayTraits::resolveDOMCollectionProperty(JSContext *cx, HandleObject wrapper, HandleObject holder, HandleId id, - JSPropertyDescriptor *desc, unsigned flags) + MutableHandle desc, + unsigned flags) { // If we are not currently resolving this id and resolveNative is called // we don't do anything. (see defineProperty in case of shadowing is forbidden). @@ -709,7 +710,7 @@ XPCWrappedNativeXrayTraits::resolveNativeProperty(JSContext *cx, HandleObject wr // check for those. if (!JSID_IS_STRING(id)) { /* Not found */ - return resolveDOMCollectionProperty(cx, wrapper, holder, id, desc.address(), flags); + return resolveDOMCollectionProperty(cx, wrapper, holder, id, desc, flags); } XPCNativeInterface *iface; @@ -723,7 +724,7 @@ XPCWrappedNativeXrayTraits::resolveNativeProperty(JSContext *cx, HandleObject wr } else if (!(iface = ccx.GetInterface()) || !(member = ccx.GetMember())) { /* Not found */ - return resolveDOMCollectionProperty(cx, wrapper, holder, id, desc.address(), flags); + return resolveDOMCollectionProperty(cx, wrapper, holder, id, desc, flags); } desc.object().set(holder); @@ -809,11 +810,11 @@ XrayTraits::resolveOwnProperty(JSContext *cx, Wrapper &jsWrapper, // in the target compartment. if (expando) { JSAutoCompartment ac(cx, expando); - if (!JS_GetPropertyDescriptorById(cx, expando, id, 0, desc.address())) + if (!JS_GetPropertyDescriptorById(cx, expando, id, 0, desc)) return false; } if (desc.object()) { - if (!JS_WrapPropertyDescriptor(cx, desc.address())) + if (!JS_WrapPropertyDescriptor(cx, desc)) return false; // Pretend the property lives on the wrapper. desc.object().set(wrapper); @@ -853,7 +854,7 @@ XPCWrappedNativeXrayTraits::resolveOwnProperty(JSContext *cx, Wrapper &jsWrapper } desc.value().setObject(*obj); mozilla::dom::FillPropertyDescriptor(desc, wrapper, true); - return JS_WrapPropertyDescriptor(cx, desc.address()); + return JS_WrapPropertyDescriptor(cx, desc); } } } @@ -901,7 +902,7 @@ XPCWrappedNativeXrayTraits::resolveOwnProperty(JSContext *cx, Wrapper &jsWrapper // return non-|own| properties from Object.getOwnPropertyDescriptor if // lookups are performed in a certain order, but we can probably live with // that until XPCWN Xrays go away with the new DOM bindings. - return JS_GetPropertyDescriptorById(cx, holder, id, 0, desc.address()); + return JS_GetPropertyDescriptorById(cx, holder, id, 0, desc); } bool @@ -1031,7 +1032,7 @@ DOMXrayTraits::resolveNativeProperty(JSContext *cx, HandleObject wrapper, MutableHandle desc, unsigned flags) { RootedObject obj(cx, getTargetObject(wrapper)); - if (!XrayResolveNativeProperty(cx, wrapper, obj, id, desc.address())) + if (!XrayResolveNativeProperty(cx, wrapper, obj, id, desc)) return false; NS_ASSERTION(!desc.object() || desc.object() == wrapper, @@ -1393,7 +1394,7 @@ XrayWrapper::getPropertyDescriptor(JSContext *cx, HandleObject wra return false; // Check the holder. - if (!desc.object() && !JS_GetPropertyDescriptorById(cx, holder, id, 0, desc.address())) + if (!desc.object() && !JS_GetPropertyDescriptorById(cx, holder, id, 0, desc)) return false; if (desc.object()) { desc.object().set(wrapper); @@ -1424,7 +1425,7 @@ XrayWrapper::getPropertyDescriptor(JSContext *cx, HandleObject wra mozilla::dom::FillPropertyDescriptor(desc, wrapper, ObjectValue(*childObj), /* readOnly = */ true); - return JS_WrapPropertyDescriptor(cx, desc.address()); + return JS_WrapPropertyDescriptor(cx, desc); } } @@ -1463,7 +1464,7 @@ XrayWrapper::getPropertyDescriptor(JSContext *cx, HandleObject wra EnsureCompartmentPrivate(wrapper)->scope->IsXBLScope() && (content = do_QueryInterfaceNative(cx, wrapper))) { - if (!nsContentUtils::LookupBindingMember(cx, content, id, desc.address())) + if (!nsContentUtils::LookupBindingMember(cx, content, id, desc)) return false; DEBUG_CheckXBLLookup(cx, desc.address()); } @@ -1474,7 +1475,7 @@ XrayWrapper::getPropertyDescriptor(JSContext *cx, HandleObject wra if (!JS_DefinePropertyById(cx, holder, id, desc.value(), desc.getter(), desc.setter(), desc.attributes()) || - !JS_GetPropertyDescriptorById(cx, holder, id, flags, desc.address())) + !JS_GetPropertyDescriptorById(cx, holder, id, flags, desc)) { return false; } @@ -1600,7 +1601,7 @@ XrayWrapper::defineProperty(JSContext *cx, HandleObject wrapper, // Wrap the property descriptor for the target compartment. Rooted wrappedDesc(cx, desc); - if (!JS_WrapPropertyDescriptor(cx, wrappedDesc.address())) + if (!JS_WrapPropertyDescriptor(cx, &wrappedDesc)) return false; // Fix up Xray waivers.