From a1270138396ac4be324e25454c5282c5b5629c73 Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Thu, 3 Jan 2013 15:31:36 -0600 Subject: [PATCH] Bug 826447 - Change all the proxy API signatures to take unsigned flags, rather than bool set, so that it's easier to find all tests of JSRESOLVE_ASSIGNING. r=bz --HG-- extra : rebase_source : 3b88b411965087984d7973a90f8fa1b06457a6ce --- dom/bindings/BindingUtils.cpp | 6 +- dom/bindings/BindingUtils.h | 2 +- dom/bindings/Codegen.py | 17 ++-- dom/bindings/DOMJSClass.h | 2 +- dom/bindings/DOMJSProxyHandler.cpp | 6 +- dom/bindings/DOMJSProxyHandler.h | 16 ++-- js/src/builtin/Object.cpp | 4 +- js/src/jsapi.cpp | 6 +- js/src/jsobj.cpp | 4 +- js/src/jsproxy.cpp | 77 +++++++++--------- js/src/jsproxy.h | 25 +++--- js/src/jswrapper.cpp | 34 ++++---- js/src/jswrapper.h | 24 +++--- js/src/shell/js.cpp | 2 +- js/src/vm/ScopeObject.cpp | 10 +-- js/xpconnect/src/XPCComponents.cpp | 14 ++-- js/xpconnect/wrappers/ChromeObjectWrapper.cpp | 14 ++-- js/xpconnect/wrappers/ChromeObjectWrapper.h | 6 +- js/xpconnect/wrappers/FilteringWrapper.cpp | 9 ++- js/xpconnect/wrappers/FilteringWrapper.h | 4 +- js/xpconnect/wrappers/WaiveXrayWrapper.cpp | 8 +- js/xpconnect/wrappers/WaiveXrayWrapper.h | 4 +- js/xpconnect/wrappers/XrayWrapper.cpp | 81 +++++++++---------- js/xpconnect/wrappers/XrayWrapper.h | 15 ++-- 24 files changed, 191 insertions(+), 199 deletions(-) diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index 31d119b4a61d..3d328047470c 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -611,15 +611,15 @@ GetNativePropertyHooks(JSContext *cx, JSObject *obj, DOMObjectType& type) bool XrayResolveOwnProperty(JSContext* cx, JSObject* wrapper, JSObject* obj, jsid id, - bool set, JSPropertyDescriptor* desc) + JSPropertyDescriptor* desc, unsigned flags) { DOMObjectType type; const NativePropertyHooks *nativePropertyHooks = GetNativePropertyHooks(cx, obj, type); return type != eInstance || !nativePropertyHooks->mResolveOwnProperty || - nativePropertyHooks->mResolveOwnProperty(cx, wrapper, obj, id, set, - desc); + nativePropertyHooks->mResolveOwnProperty(cx, wrapper, obj, id, desc, + flags); } static bool diff --git a/dom/bindings/BindingUtils.h b/dom/bindings/BindingUtils.h index 609fd68f75c9..7ccdd65e7dcd 100644 --- a/dom/bindings/BindingUtils.h +++ b/dom/bindings/BindingUtils.h @@ -1575,7 +1575,7 @@ AddStringToIDVector(JSContext* cx, JS::AutoIdVector& vector, const char* name) */ bool XrayResolveOwnProperty(JSContext* cx, JSObject* wrapper, JSObject* obj, - jsid id, bool set, JSPropertyDescriptor* desc); + jsid id, JSPropertyDescriptor* desc, unsigned flags); /** * This resolves operations, attributes and constants of the interfaces for obj. diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 1a7e063d5618..ebbd58208368 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -5599,13 +5599,13 @@ class CGResolveOwnProperty(CGAbstractMethod): def __init__(self, descriptor): args = [Argument('JSContext*', 'cx'), Argument('JSObject*', 'wrapper'), Argument('JSObject*', 'obj'), Argument('jsid', 'id'), - Argument('bool', 'set'), - Argument('JSPropertyDescriptor*', 'desc')] + Argument('JSPropertyDescriptor*', 'desc'), Argument('unsigned', 'flags'), + ] CGAbstractMethod.__init__(self, descriptor, "ResolveOwnProperty", "bool", args) def definition_body(self): return """ // We rely on getOwnPropertyDescriptor not shadowing prototype properties by named // properties. If that changes we'll need to filter here. - return js::GetProxyHandler(obj)->getOwnPropertyDescriptor(cx, wrapper, id, set, desc); + return js::GetProxyHandler(obj)->getOwnPropertyDescriptor(cx, wrapper, id, desc, flags); """ class CGEnumerateOwnProperties(CGAbstractMethod): @@ -5862,8 +5862,8 @@ class CGDOMJSProxyHandler_CGDOMJSProxyHandler(ClassConstructor): class CGDOMJSProxyHandler_getOwnPropertyDescriptor(ClassMethod): def __init__(self, descriptor): args = [Argument('JSContext*', 'cx'), Argument('JSObject*', 'proxy'), - Argument('jsid', 'id'), Argument('bool', 'set'), - Argument('JSPropertyDescriptor*', 'desc')] + Argument('jsid', 'id'), + Argument('JSPropertyDescriptor*', 'desc'), Argument('unsigned', 'flags')] ClassMethod.__init__(self, "getOwnPropertyDescriptor", "bool", args) self.descriptor = descriptor def getBody(self): @@ -5882,7 +5882,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(ClassMethod): "}\n") % (self.descriptor.nativeType) if indexedSetter or self.descriptor.operations['NamedSetter']: - setOrIndexedGet += "if (set) {\n" + setOrIndexedGet += "if (flags & JSRESOLVE_ASSIGNING) {\n" if indexedSetter: setOrIndexedGet += (" if (IsArrayIndex(index)) {\n") if not 'IndexedCreator' in self.descriptor.operations: @@ -5912,7 +5912,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(ClassMethod): "}") setOrIndexedGet += "\n\n" elif indexedGetter: - setOrIndexedGet += ("if (!set) {\n" + + setOrIndexedGet += ("if (!(flags & JSRESOLVE_ASSIGNING)) {\n" + CGIndenter(CGGeneric(get)).define() + "}\n\n") @@ -5924,7 +5924,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(ClassMethod): # Once we start supporting OverrideBuiltins we need to make # ResolveOwnProperty or EnumerateOwnProperties filter out named # properties that shadow prototype properties. - condition = "!set && !HasPropertyOnPrototype(cx, proxy, this, id)" + condition = "!(flags & JSRESOLVE_ASSIGNING) && !HasPropertyOnPrototype(cx, proxy, this, id)" if self.descriptor.supportsIndexedProperties(): condition = "!IsArrayIndex(index) && " + condition namedGet = ("\n" + @@ -5936,7 +5936,6 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(ClassMethod): return setOrIndexedGet + """JSObject* expando; if (!xpc::WrapperFactory::IsXrayWrapper(proxy) && (expando = GetExpandoObject(proxy))) { - unsigned flags = (set ? JSRESOLVE_ASSIGNING : 0); if (!JS_GetPropertyDescriptorById(cx, expando, id, flags, desc)) { return false; } diff --git a/dom/bindings/DOMJSClass.h b/dom/bindings/DOMJSClass.h index c4c013476e99..cc08a8221a32 100644 --- a/dom/bindings/DOMJSClass.h +++ b/dom/bindings/DOMJSClass.h @@ -50,7 +50,7 @@ namespace dom { typedef bool (* ResolveOwnProperty)(JSContext* cx, JSObject* wrapper, JSObject* obj, jsid id, - bool set, JSPropertyDescriptor* desc); + JSPropertyDescriptor* desc, unsigned flags); typedef bool (* EnumerateOwnProperties)(JSContext* cx, JSObject* wrapper, JSObject* obj, diff --git a/dom/bindings/DOMJSProxyHandler.cpp b/dom/bindings/DOMJSProxyHandler.cpp index 34de291441cb..ea1ac97b1fe5 100644 --- a/dom/bindings/DOMJSProxyHandler.cpp +++ b/dom/bindings/DOMJSProxyHandler.cpp @@ -76,10 +76,10 @@ DOMProxyHandler::EnsureExpandoObject(JSContext* cx, JSObject* obj) } bool -DOMProxyHandler::getPropertyDescriptor(JSContext* cx, JSObject* proxy, jsid id, bool set, - JSPropertyDescriptor* desc) +DOMProxyHandler::getPropertyDescriptor(JSContext* cx, JSObject* proxy, jsid id, + JSPropertyDescriptor* desc, unsigned flags) { - if (!getOwnPropertyDescriptor(cx, proxy, id, set, desc)) { + if (!getOwnPropertyDescriptor(cx, proxy, id, desc, flags)) { return false; } if (desc->obj) { diff --git a/dom/bindings/DOMJSProxyHandler.h b/dom/bindings/DOMJSProxyHandler.h index a689bfd2fd15..0045d13aff6a 100644 --- a/dom/bindings/DOMJSProxyHandler.h +++ b/dom/bindings/DOMJSProxyHandler.h @@ -6,12 +6,14 @@ #ifndef mozilla_dom_DOMJSProxyHandler_h #define mozilla_dom_DOMJSProxyHandler_h +#include "mozilla/Attributes.h" +#include "mozilla/Likely.h" + #include "jsapi.h" #include "jsfriendapi.h" #include "jsproxy.h" #include "xpcpublic.h" #include "nsStringGlue.h" -#include "mozilla/Likely.h" #define DOM_PROXY_OBJECT_SLOT js::JSSLOT_PROXY_PRIVATE @@ -34,14 +36,14 @@ public: { } - bool getPropertyDescriptor(JSContext* cx, JSObject* proxy, jsid id, bool set, - JSPropertyDescriptor* desc); + bool getPropertyDescriptor(JSContext* cx, JSObject* proxy, jsid id, JSPropertyDescriptor* desc, + unsigned flags) MOZ_OVERRIDE; bool defineProperty(JSContext* cx, JSObject* proxy, jsid id, - JSPropertyDescriptor* desc); - bool delete_(JSContext* cx, JSObject* proxy, jsid id, bool* bp); - bool enumerate(JSContext* cx, JSObject* proxy, JS::AutoIdVector& props); + JSPropertyDescriptor* desc) MOZ_OVERRIDE; + bool delete_(JSContext* cx, JSObject* proxy, jsid id, bool* bp) MOZ_OVERRIDE; + bool enumerate(JSContext* cx, JSObject* proxy, JS::AutoIdVector& props) MOZ_OVERRIDE; bool fix(JSContext* cx, JSObject* proxy, JS::Value* vp); - bool has(JSContext* cx, JSObject* proxy, jsid id, bool* bp); + bool has(JSContext* cx, JSObject* proxy, jsid id, bool* bp) MOZ_OVERRIDE; using js::BaseProxyHandler::obj_toString; static JSObject* GetExpandoObject(JSObject* obj) diff --git a/js/src/builtin/Object.cpp b/js/src/builtin/Object.cpp index 9fddbb8957ba..ecd9f4769cc6 100644 --- a/js/src/builtin/Object.cpp +++ b/js/src/builtin/Object.cpp @@ -446,7 +446,7 @@ obj_lookupGetter(JSContext *cx, unsigned argc, Value *vp) // native. Handle proxies separately. args.rval().setUndefined(); AutoPropertyDescriptorRooter desc(cx); - if (!Proxy::getPropertyDescriptor(cx, obj, id, false, &desc)) + if (!Proxy::getPropertyDescriptor(cx, obj, id, &desc, 0)) return JS_FALSE; if (desc.obj && (desc.attrs & JSPROP_GETTER) && desc.getter) args.rval().set(CastAsObjectJsval(desc.getter)); @@ -482,7 +482,7 @@ obj_lookupSetter(JSContext *cx, unsigned argc, Value *vp) // native. Handle proxies separately. args.rval().setUndefined(); AutoPropertyDescriptorRooter desc(cx); - if (!Proxy::getPropertyDescriptor(cx, obj, id, false, &desc)) + if (!Proxy::getPropertyDescriptor(cx, obj, id, &desc, 0)) return JS_FALSE; if (desc.obj && (desc.attrs & JSPROP_SETTER) && desc.setter) args.rval().set(CastAsObjectJsval(desc.setter)); diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 53b0a4fc7d41..c02b86f58452 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -3574,7 +3574,7 @@ LookupResult(JSContext *cx, HandleObject obj, HandleObject obj2, jsid id, return js_GetDenseArrayElementValue(cx, obj2, id, vp); if (obj2->isProxy()) { AutoPropertyDescriptorRooter desc(cx); - if (!Proxy::getPropertyDescriptor(cx, obj2, id, false, &desc)) + if (!Proxy::getPropertyDescriptor(cx, obj2, id, &desc, 0)) return false; if (!(desc.attrs & JSPROP_SHARED)) { *vp = desc.value; @@ -4058,8 +4058,8 @@ GetPropertyDescriptorById(JSContext *cx, HandleObject obj, HandleId id, unsigned if (obj2->isProxy()) { JSAutoResolveFlags rf(cx, flags); return own - ? Proxy::getOwnPropertyDescriptor(cx, obj2, id, false, desc) - : Proxy::getPropertyDescriptor(cx, obj2, id, false, desc); + ? Proxy::getOwnPropertyDescriptor(cx, obj2, id, desc, 0) + : Proxy::getPropertyDescriptor(cx, obj2, id, desc, 0); } if (!JSObject::getGenericAttributes(cx, obj2, id, &desc->attrs)) return false; diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index d2003e74012d..4a809b0acf96 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -257,7 +257,7 @@ js::GetOwnPropertyDescriptor(JSContext *cx, HandleObject obj, HandleId id, { // FIXME: Call TrapGetOwnProperty directly once ScriptedIndirectProxies is removed if (obj->isProxy()) - return Proxy::getOwnPropertyDescriptor(cx, obj, id, false, desc); + return Proxy::getOwnPropertyDescriptor(cx, obj, id, desc, 0); RootedObject pobj(cx); RootedShape shape(cx); @@ -3610,7 +3610,7 @@ baseops::SetPropertyHelper(JSContext *cx, HandleObject obj, HandleObject receive if (!pobj->isNative()) { if (pobj->isProxy()) { AutoPropertyDescriptorRooter pd(cx); - if (!Proxy::getPropertyDescriptor(cx, pobj, id, true, &pd)) + if (!Proxy::getPropertyDescriptor(cx, pobj, id, &pd, JSRESOLVE_ASSIGNING)) return false; if ((pd.attrs & (JSPROP_SHARED | JSPROP_SHADOWABLE)) == JSPROP_SHARED) { diff --git a/js/src/jsproxy.cpp b/js/src/jsproxy.cpp index 66602f23c006..3d07c14d6a39 100644 --- a/js/src/jsproxy.cpp +++ b/js/src/jsproxy.cpp @@ -63,7 +63,7 @@ bool BaseProxyHandler::has(JSContext *cx, JSObject *proxy, jsid id, bool *bp) { AutoPropertyDescriptorRooter desc(cx); - if (!getPropertyDescriptor(cx, proxy, id, false, &desc)) + if (!getPropertyDescriptor(cx, proxy, id, &desc, 0)) return false; *bp = !!desc.obj; return true; @@ -73,7 +73,7 @@ bool BaseProxyHandler::hasOwn(JSContext *cx, JSObject *proxy, jsid id, bool *bp) { AutoPropertyDescriptorRooter desc(cx); - if (!getOwnPropertyDescriptor(cx, proxy, id, false, &desc)) + if (!getOwnPropertyDescriptor(cx, proxy, id, &desc, 0)) return false; *bp = !!desc.obj; return true; @@ -86,7 +86,7 @@ BaseProxyHandler::get(JSContext *cx, JSObject *proxy, JSObject *receiver_, jsid RootedId id(cx, id_); AutoPropertyDescriptorRooter desc(cx); - if (!getPropertyDescriptor(cx, proxy, id, false, &desc)) + if (!getPropertyDescriptor(cx, proxy, id, &desc, 0)) return false; if (!desc.obj) { vp->setUndefined(); @@ -143,7 +143,7 @@ BaseProxyHandler::set(JSContext *cx, JSObject *proxy_, JSObject *receiver_, jsid RootedId id(cx, id_); AutoPropertyDescriptorRooter desc(cx); - if (!getOwnPropertyDescriptor(cx, proxy, id, true, &desc)) + if (!getOwnPropertyDescriptor(cx, proxy, id, &desc, JSRESOLVE_ASSIGNING)) return false; /* The control-flow here differs from ::get() because of the fall-through case below. */ if (desc.obj) { @@ -173,7 +173,7 @@ BaseProxyHandler::set(JSContext *cx, JSObject *proxy_, JSObject *receiver_, jsid desc.value = *vp; return defineProperty(cx, receiver, id, &desc); } - if (!getPropertyDescriptor(cx, proxy, id, true, &desc)) + if (!getPropertyDescriptor(cx, proxy, id, &desc, JSRESOLVE_ASSIGNING)) return false; if (desc.obj) { // Check for read-only properties. @@ -226,7 +226,7 @@ BaseProxyHandler::keys(JSContext *cx, JSObject *proxy, AutoIdVector &props) for (size_t j = 0, len = props.length(); j < len; j++) { JS_ASSERT(i <= j); jsid id = props[j]; - if (!getOwnPropertyDescriptor(cx, proxy, id, false, &desc)) + if (!getOwnPropertyDescriptor(cx, proxy, id, &desc, 0)) return false; if (desc.obj && (desc.attrs & JSPROP_ENUMERATE)) props[i++] = id; @@ -375,8 +375,7 @@ BaseProxyHandler::getPrototypeOf(JSContext *cx, JSObject *proxy, JSObject **prot bool DirectProxyHandler::getPropertyDescriptor(JSContext *cx, JSObject *proxy, - jsid id, bool set, - PropertyDescriptor *desc) + jsid id, PropertyDescriptor *desc, unsigned flags) { RootedObject target(cx, GetProxyTargetObject(proxy)); return JS_GetPropertyDescriptorById(cx, target, id, 0, desc); @@ -389,9 +388,7 @@ GetOwnPropertyDescriptor(JSContext *cx, HandleObject obj, jsid id, unsigned flag // If obj is a proxy, we can do better than just guessing. This is // important for certain types of wrappers that wrap other wrappers. if (obj->isProxy()) - return Proxy::getOwnPropertyDescriptor(cx, obj, id, - flags & JSRESOLVE_ASSIGNING, - desc); + return Proxy::getOwnPropertyDescriptor(cx, obj, id, desc, flags); if (!JS_GetPropertyDescriptorById(cx, obj, id, flags, desc)) return false; @@ -402,8 +399,7 @@ GetOwnPropertyDescriptor(JSContext *cx, HandleObject obj, jsid id, unsigned flag bool DirectProxyHandler::getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, - jsid id, bool set, - PropertyDescriptor *desc) + jsid id, PropertyDescriptor *desc, unsigned flags) { RootedObject target(cx, GetProxyTargetObject(proxy)); return GetOwnPropertyDescriptor(cx, target, id, 0, desc); @@ -723,10 +719,10 @@ class ScriptedIndirectProxyHandler : public BaseProxyHandler { virtual ~ScriptedIndirectProxyHandler(); /* ES5 Harmony fundamental proxy traps. */ - virtual bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, - PropertyDescriptor *desc) MOZ_OVERRIDE; - virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, - PropertyDescriptor *desc) MOZ_OVERRIDE; + virtual bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, + PropertyDescriptor *desc, unsigned flags) MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, + PropertyDescriptor *desc, unsigned flags) MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, JSObject *proxy, jsid id, PropertyDescriptor *desc) MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, JSObject *proxy, AutoIdVector &props); @@ -785,8 +781,8 @@ GetIndirectProxyHandlerObject(JSObject *proxy) } bool -ScriptedIndirectProxyHandler::getPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id_, bool set, - PropertyDescriptor *desc) +ScriptedIndirectProxyHandler::getPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id_, + PropertyDescriptor *desc, unsigned flags) { RootedId id(cx, id_); RootedObject proxy(cx, proxy_); @@ -800,8 +796,8 @@ ScriptedIndirectProxyHandler::getPropertyDescriptor(JSContext *cx, JSObject *pro } bool -ScriptedIndirectProxyHandler::getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id_, bool set, - PropertyDescriptor *desc) +ScriptedIndirectProxyHandler::getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id_, + PropertyDescriptor *desc, unsigned flags) { RootedId id(cx, id_); RootedObject proxy(cx, proxy_); @@ -1002,10 +998,10 @@ class ScriptedDirectProxyHandler : public DirectProxyHandler { virtual ~ScriptedDirectProxyHandler(); /* ES5 Harmony fundamental proxy traps. */ - virtual bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, - PropertyDescriptor *desc) MOZ_OVERRIDE; - virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, - PropertyDescriptor *desc) MOZ_OVERRIDE; + virtual bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, + PropertyDescriptor *desc, unsigned flags) MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, + PropertyDescriptor *desc, unsigned flags) MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, JSObject *proxy, jsid id, PropertyDescriptor *desc) MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, JSObject *proxy, AutoIdVector &props); @@ -1571,7 +1567,7 @@ ScriptedDirectProxyHandler::~ScriptedDirectProxyHandler() // FIXME: Move to Proxy::getPropertyDescriptor once ScriptedIndirectProxy is removed bool ScriptedDirectProxyHandler::getPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id_, - bool set, PropertyDescriptor *desc) + PropertyDescriptor *desc, unsigned flags) { JS_CHECK_RECURSION(cx, return false); Rooted proxy(cx, proxy_); @@ -1592,7 +1588,7 @@ ScriptedDirectProxyHandler::getPropertyDescriptor(JSContext *cx, JSObject *proxy bool ScriptedDirectProxyHandler::getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id_, - bool set, PropertyDescriptor *desc) + PropertyDescriptor *desc, unsigned flags) { RootedObject proxy(cx, proxy_); RootedId id(cx, id_); @@ -2197,16 +2193,16 @@ ScriptedDirectProxyHandler ScriptedDirectProxyHandler::singleton; bool -Proxy::getPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id_, bool set, - PropertyDescriptor *desc) +Proxy::getPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id_, PropertyDescriptor *desc, + unsigned flags) { JS_CHECK_RECURSION(cx, return false); RootedObject proxy(cx, proxy_); RootedId id(cx, id_); BaseProxyHandler *handler = GetProxyHandler(proxy); if (!handler->hasPrototype()) - return handler->getPropertyDescriptor(cx, proxy, id, set, desc); - if (!handler->getOwnPropertyDescriptor(cx, proxy, id, set, desc)) + return handler->getPropertyDescriptor(cx, proxy, id, desc, flags); + if (!handler->getOwnPropertyDescriptor(cx, proxy, id, desc, flags)) return false; if (desc->obj) return true; @@ -2215,31 +2211,32 @@ Proxy::getPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id_, bool set } bool -Proxy::getPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id, bool set, Value *vp) +Proxy::getPropertyDescriptor(JSContext *cx, JSObject *proxy_, unsigned flags, jsid id, Value *vp) { JS_CHECK_RECURSION(cx, return false); RootedObject proxy(cx, proxy_); AutoPropertyDescriptorRooter desc(cx); - return Proxy::getPropertyDescriptor(cx, proxy, id, set, &desc) && + return Proxy::getPropertyDescriptor(cx, proxy, id, &desc, flags) && NewPropertyDescriptorObject(cx, &desc, vp); } bool -Proxy::getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id, bool set, - PropertyDescriptor *desc) +Proxy::getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id, PropertyDescriptor *desc, + unsigned flags) { JS_CHECK_RECURSION(cx, return false); RootedObject proxy(cx, proxy_); - return GetProxyHandler(proxy)->getOwnPropertyDescriptor(cx, proxy, id, set, desc); + return GetProxyHandler(proxy)->getOwnPropertyDescriptor(cx, proxy, id, desc, flags); } bool -Proxy::getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id, bool set, Value *vp) +Proxy::getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy_, unsigned flags, jsid id, + Value *vp) { JS_CHECK_RECURSION(cx, return false); RootedObject proxy(cx, proxy_); AutoPropertyDescriptorRooter desc(cx); - return Proxy::getOwnPropertyDescriptor(cx, proxy, id, set, &desc) && + return Proxy::getOwnPropertyDescriptor(cx, proxy, id, &desc, flags) && NewPropertyDescriptorObject(cx, &desc, vp); } @@ -2688,7 +2685,7 @@ static JSBool proxy_GetGenericAttributes(JSContext *cx, HandleObject obj, HandleId id, unsigned *attrsp) { AutoPropertyDescriptorRooter desc(cx); - if (!Proxy::getOwnPropertyDescriptor(cx, obj, id, false, &desc)) + if (!Proxy::getOwnPropertyDescriptor(cx, obj, id, &desc, 0)) return false; *attrsp = desc.attrs; return true; @@ -2722,7 +2719,7 @@ proxy_SetGenericAttributes(JSContext *cx, HandleObject obj, HandleId id, unsigne { /* Lookup the current property descriptor so we have setter/getter/value. */ AutoPropertyDescriptorRooter desc(cx); - if (!Proxy::getOwnPropertyDescriptor(cx, obj, id, true, &desc)) + if (!Proxy::getOwnPropertyDescriptor(cx, obj, id, &desc, JSRESOLVE_ASSIGNING)) return false; desc.attrs = (*attrsp & (~JSPROP_SHORTID)); return Proxy::defineProperty(cx, obj, id, &desc); diff --git a/js/src/jsproxy.h b/js/src/jsproxy.h index c693178a367c..25c60d3e3939 100644 --- a/js/src/jsproxy.h +++ b/js/src/jsproxy.h @@ -73,10 +73,9 @@ class JS_FRIEND_API(BaseProxyHandler) { /* ES5 Harmony fundamental proxy traps. */ virtual bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, - bool set, PropertyDescriptor *desc) = 0; + PropertyDescriptor *desc, unsigned flags) = 0; virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, - jsid id, bool set, - PropertyDescriptor *desc) = 0; + jsid id, PropertyDescriptor *desc, unsigned flags) = 0; virtual bool defineProperty(JSContext *cx, JSObject *proxy, jsid id, PropertyDescriptor *desc) = 0; virtual bool getOwnPropertyNames(JSContext *cx, JSObject *proxy, @@ -128,11 +127,10 @@ public: /* ES5 Harmony fundamental proxy traps. */ virtual bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, - bool set, - PropertyDescriptor *desc) MOZ_OVERRIDE; + PropertyDescriptor *desc, unsigned flags) MOZ_OVERRIDE; virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, - jsid id, bool set, - PropertyDescriptor *desc) MOZ_OVERRIDE; + jsid id, PropertyDescriptor *desc, + unsigned flags) MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, JSObject *proxy, jsid id, PropertyDescriptor *desc) MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, JSObject *proxy, @@ -178,12 +176,13 @@ public: class Proxy { public: /* ES5 Harmony fundamental proxy traps. */ - static bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, - PropertyDescriptor *desc); - static bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, Value *vp); - static bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, - PropertyDescriptor *desc); - static bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, + static bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, + PropertyDescriptor *desc, unsigned flags); + static bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, unsigned flags, jsid id, + Value *vp); + static bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, + PropertyDescriptor *desc, unsigned flags); + static bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, unsigned flags, jsid id, Value *vp); static bool defineProperty(JSContext *cx, JSObject *proxy, jsid id, PropertyDescriptor *desc); static bool defineProperty(JSContext *cx, JSObject *proxy, jsid id, const Value &v); diff --git a/js/src/jswrapper.cpp b/js/src/jswrapper.cpp index 6fc4e26234f4..3510c232037a 100644 --- a/js/src/jswrapper.cpp +++ b/js/src/jswrapper.cpp @@ -162,22 +162,20 @@ Wrapper::~Wrapper() bool Wrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrapper, - jsid id, bool set, - PropertyDescriptor *desc) + jsid id, PropertyDescriptor *desc, unsigned flags) { JS_ASSERT(!hasPrototype()); // Should never be called when there's a prototype. desc->obj = NULL; // default result if we refuse to perform this action - CHECKED(DirectProxyHandler::getPropertyDescriptor(cx, wrapper, id, set, desc), - set ? SET : GET); + CHECKED(DirectProxyHandler::getPropertyDescriptor(cx, wrapper, id, desc, flags), + (flags & JSRESOLVE_ASSIGNING) ? SET : GET); } bool Wrapper::getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, - jsid id, bool set, - PropertyDescriptor *desc) + jsid id, PropertyDescriptor *desc, unsigned flags) { desc->obj = NULL; // default result if we refuse to perform this action - CHECKED(DirectProxyHandler::getOwnPropertyDescriptor(cx, wrapper, id, set, desc), GET); + CHECKED(DirectProxyHandler::getOwnPropertyDescriptor(cx, wrapper, id, desc, flags), GET); } bool @@ -417,21 +415,21 @@ CrossCompartmentWrapper::~CrossCompartmentWrapper() bool CrossCompartmentWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, - bool set, PropertyDescriptor *desc) + PropertyDescriptor *desc, unsigned flags) { - PIERCE(cx, wrapper, set ? SET : GET, + PIERCE(cx, wrapper, (flags & JSRESOLVE_ASSIGNING) ? SET : GET, cx->compartment->wrapId(cx, &id), - Wrapper::getPropertyDescriptor(cx, wrapper, id, set, desc), + Wrapper::getPropertyDescriptor(cx, wrapper, id, desc, flags), cx->compartment->wrap(cx, desc)); } bool CrossCompartmentWrapper::getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, - bool set, PropertyDescriptor *desc) + PropertyDescriptor *desc, unsigned flags) { - PIERCE(cx, wrapper, set ? SET : GET, + PIERCE(cx, wrapper, (flags & JSRESOLVE_ASSIGNING) ? SET : GET, cx->compartment->wrapId(cx, &id), - Wrapper::getOwnPropertyDescriptor(cx, wrapper, id, set, desc), + Wrapper::getOwnPropertyDescriptor(cx, wrapper, id, desc, flags), cx->compartment->wrap(cx, desc)); } @@ -823,18 +821,16 @@ DeadObjectProxy::DeadObjectProxy() } bool -DeadObjectProxy::getPropertyDescriptor(JSContext *cx, JSObject *wrapper, - jsid id, bool set, - PropertyDescriptor *desc) +DeadObjectProxy::getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, + PropertyDescriptor *desc, unsigned flags) { JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT); return false; } bool -DeadObjectProxy::getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, - jsid id, bool set, - PropertyDescriptor *desc) +DeadObjectProxy::getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, + PropertyDescriptor *desc, unsigned flags) { JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT); return false; diff --git a/js/src/jswrapper.h b/js/src/jswrapper.h index 0b20a26232c9..ea23cd54b393 100644 --- a/js/src/jswrapper.h +++ b/js/src/jswrapper.h @@ -82,11 +82,11 @@ class JS_FRIEND_API(Wrapper) : public DirectProxyHandler /* ES5 Harmony fundamental wrapper traps. */ virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper, - jsid id, bool set, - PropertyDescriptor *desc) MOZ_OVERRIDE; + jsid id, PropertyDescriptor *desc, + unsigned flags) MOZ_OVERRIDE; virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, - jsid id, bool set, - PropertyDescriptor *desc) MOZ_OVERRIDE; + jsid id, PropertyDescriptor *desc, + unsigned flags) MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, JSObject *wrapper, jsid id, PropertyDescriptor *desc) MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, JSObject *wrapper, @@ -131,10 +131,10 @@ class JS_FRIEND_API(CrossCompartmentWrapper) : public Wrapper virtual ~CrossCompartmentWrapper(); /* ES5 Harmony fundamental wrapper traps. */ - virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set, - PropertyDescriptor *desc) MOZ_OVERRIDE; - virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set, - PropertyDescriptor *desc) MOZ_OVERRIDE; + virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, + PropertyDescriptor *desc, unsigned flags) MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, + PropertyDescriptor *desc, unsigned flags) MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, JSObject *wrapper, jsid id, PropertyDescriptor *desc) MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, JSObject *wrapper, AutoIdVector &props) MOZ_OVERRIDE; @@ -207,10 +207,10 @@ class JS_FRIEND_API(DeadObjectProxy) : public BaseProxyHandler explicit DeadObjectProxy(); /* ES5 Harmony fundamental wrapper traps. */ - virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set, - PropertyDescriptor *desc) MOZ_OVERRIDE; - virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set, - PropertyDescriptor *desc) MOZ_OVERRIDE; + virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, + PropertyDescriptor *desc, unsigned flags) MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, + PropertyDescriptor *desc, unsigned flags) MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, JSObject *wrapper, jsid id, PropertyDescriptor *desc) MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, JSObject *wrapper, AutoIdVector &props) MOZ_OVERRIDE; diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index d0338649cedc..29ef262c53c4 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -2743,7 +2743,7 @@ CopyProperty(JSContext *cx, HandleObject obj, HandleObject referent, HandleId id propFlags = shape->getFlags(); } else if (IsProxy(referent)) { PropertyDescriptor desc; - if (!Proxy::getOwnPropertyDescriptor(cx, referent, id, false, &desc)) + if (!Proxy::getOwnPropertyDescriptor(cx, referent, id, &desc, 0)) return false; if (!desc.obj) return true; diff --git a/js/src/vm/ScopeObject.cpp b/js/src/vm/ScopeObject.cpp index e842abdf9e79..1a4b08bdb4eb 100644 --- a/js/src/vm/ScopeObject.cpp +++ b/js/src/vm/ScopeObject.cpp @@ -1316,14 +1316,14 @@ class DebugScopeProxy : public BaseProxyHandler DebugScopeProxy() : BaseProxyHandler(&family) {} - bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, - PropertyDescriptor *desc) MOZ_OVERRIDE + bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, PropertyDescriptor *desc, + unsigned flags) MOZ_OVERRIDE { - return getOwnPropertyDescriptor(cx, proxy, id, set, desc); + return getOwnPropertyDescriptor(cx, proxy, id, desc, flags); } - bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid idArg, bool set, - PropertyDescriptor *desc) MOZ_OVERRIDE + bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid idArg, + PropertyDescriptor *desc, unsigned flags) MOZ_OVERRIDE { Rooted debugScope(cx, &proxy->asDebugScope()); Rooted scope(cx, &debugScope->scope()); diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index 5ff63d435be1..261637755504 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -3143,15 +3143,16 @@ XPC_WN_Helper_SetProperty(JSContext *cx, JSHandleObject obj, JSHandleId id, JSBo bool xpc::SandboxProxyHandler::getPropertyDescriptor(JSContext *cx, JSObject *proxy, - jsid id_, bool set, - PropertyDescriptor *desc) + jsid id_, + PropertyDescriptor *desc, + unsigned flags) { js::RootedObject obj(cx, wrappedObject(proxy)); js::RootedId id(cx, id_); MOZ_ASSERT(js::GetObjectCompartment(obj) == js::GetObjectCompartment(proxy)); if (!JS_GetPropertyDescriptorById(cx, obj, id, - (set ? JSRESOLVE_ASSIGNING : 0), desc)) + flags, desc)) return false; if (!desc->obj) @@ -3191,10 +3192,11 @@ xpc::SandboxProxyHandler::getPropertyDescriptor(JSContext *cx, JSObject *proxy, bool xpc::SandboxProxyHandler::getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, - jsid id, bool set, - PropertyDescriptor *desc) + jsid id, + PropertyDescriptor *desc, + unsigned flags) { - if (!getPropertyDescriptor(cx, proxy, id, set, desc)) + if (!getPropertyDescriptor(cx, proxy, id, desc, flags)) return false; if (desc->obj != wrappedObject(proxy)) diff --git a/js/xpconnect/wrappers/ChromeObjectWrapper.cpp b/js/xpconnect/wrappers/ChromeObjectWrapper.cpp index afe43d8ab426..109c91286699 100644 --- a/js/xpconnect/wrappers/ChromeObjectWrapper.cpp +++ b/js/xpconnect/wrappers/ChromeObjectWrapper.cpp @@ -25,15 +25,15 @@ PropIsFromStandardPrototype(JSContext *cx, JSPropertyDescriptor *desc) bool ChromeObjectWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrapper, - jsid id, bool set, - js::PropertyDescriptor *desc) + jsid id, js::PropertyDescriptor *desc, + unsigned flags) { // First, try the lookup on the base wrapper. This can throw for various // reasons, including sets (gets fail silently). There's nothing we can really // do for sets, so we can conveniently propagate any exception we hit here. desc->obj = NULL; if (!ChromeObjectWrapperBase::getPropertyDescriptor(cx, wrapper, id, - set, desc)) { + desc, flags)) { return false; } @@ -46,8 +46,8 @@ ChromeObjectWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrapper, // If we found something, were doing a set, or have no proto, we're done. JSObject *wrapperProto; if (!JS_GetPrototype(cx, wrapper, &wrapperProto)) - return false; - if (desc->obj || set || !wrapperProto) + return false; + if (desc->obj || (flags & JSRESOLVE_ASSIGNING) || !wrapperProto) return true; // If not, try doing the lookup on the prototype. @@ -86,8 +86,8 @@ ChromeObjectWrapper::get(JSContext *cx, JSObject *wrapper, JSObject *receiver, // this because the call signature of ::get doesn't give us any way to // determine the object upon which the property was found. JSPropertyDescriptor desc; - if (!ChromeObjectWrapperBase::getPropertyDescriptor(cx, wrapper, id, false, - &desc)) { + if (!ChromeObjectWrapperBase::getPropertyDescriptor(cx, wrapper, id, &desc, + 0)) { return false; } diff --git a/js/xpconnect/wrappers/ChromeObjectWrapper.h b/js/xpconnect/wrappers/ChromeObjectWrapper.h index d40adc2f36f5..b5e0b7e9708e 100644 --- a/js/xpconnect/wrappers/ChromeObjectWrapper.h +++ b/js/xpconnect/wrappers/ChromeObjectWrapper.h @@ -8,6 +8,8 @@ #ifndef __ChromeObjectWrapper_h__ #define __ChromeObjectWrapper_h__ +#include "mozilla/Attributes.h" + #include "FilteringWrapper.h" #include "AccessCheck.h" @@ -28,8 +30,8 @@ class ChromeObjectWrapper : public ChromeObjectWrapperBase /* Custom traps. */ virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper, - jsid id, bool set, - js::PropertyDescriptor *desc) MOZ_OVERRIDE; + jsid id, js::PropertyDescriptor *desc, + unsigned flags) MOZ_OVERRIDE; virtual bool has(JSContext *cx, JSObject *wrapper, jsid id, bool *bp) MOZ_OVERRIDE; virtual bool get(JSContext *cx, JSObject *wrapper, JSObject *receiver, diff --git a/js/xpconnect/wrappers/FilteringWrapper.cpp b/js/xpconnect/wrappers/FilteringWrapper.cpp index 1e2ed93bbf52..fe299184f5df 100644 --- a/js/xpconnect/wrappers/FilteringWrapper.cpp +++ b/js/xpconnect/wrappers/FilteringWrapper.cpp @@ -61,9 +61,9 @@ FilterSetter(JSContext *cx, JSObject *wrapper, jsid id, js::PropertyDescriptor * template bool FilteringWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, - bool set, js::PropertyDescriptor *desc) + js::PropertyDescriptor *desc, unsigned flags) { - if (!Base::getPropertyDescriptor(cx, wrapper, id, set, desc)) + if (!Base::getPropertyDescriptor(cx, wrapper, id, desc, flags)) return false; return FilterSetter(cx, wrapper, id, desc); } @@ -71,9 +71,10 @@ FilteringWrapper::getPropertyDescriptor(JSContext *cx, JSObject *w template bool FilteringWrapper::getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, - bool set, js::PropertyDescriptor *desc) + js::PropertyDescriptor *desc, + unsigned flags) { - if (!Base::getOwnPropertyDescriptor(cx, wrapper, id, set, desc)) + if (!Base::getOwnPropertyDescriptor(cx, wrapper, id, desc, flags)) return false; return FilterSetter(cx, wrapper, id, desc); } diff --git a/js/xpconnect/wrappers/FilteringWrapper.h b/js/xpconnect/wrappers/FilteringWrapper.h index a6784158fe6b..b084da305292 100644 --- a/js/xpconnect/wrappers/FilteringWrapper.h +++ b/js/xpconnect/wrappers/FilteringWrapper.h @@ -19,8 +19,8 @@ class FilteringWrapper : public Base { FilteringWrapper(unsigned flags); virtual ~FilteringWrapper(); - virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set, js::PropertyDescriptor *desc) MOZ_OVERRIDE; - virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, bool set, js::PropertyDescriptor *desc) MOZ_OVERRIDE; + virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, js::PropertyDescriptor *desc, unsigned flags) MOZ_OVERRIDE; + virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, js::PropertyDescriptor *desc, unsigned flags) MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, JSObject *wrapper, js::AutoIdVector &props) MOZ_OVERRIDE; virtual bool enumerate(JSContext *cx, JSObject *wrapper, js::AutoIdVector &props) MOZ_OVERRIDE; virtual bool keys(JSContext *cx, JSObject *wrapper, js::AutoIdVector &props) MOZ_OVERRIDE; diff --git a/js/xpconnect/wrappers/WaiveXrayWrapper.cpp b/js/xpconnect/wrappers/WaiveXrayWrapper.cpp index 0a68d2c55448..4969170fdd12 100644 --- a/js/xpconnect/wrappers/WaiveXrayWrapper.cpp +++ b/js/xpconnect/wrappers/WaiveXrayWrapper.cpp @@ -25,17 +25,17 @@ WaiveXrayWrapper::~WaiveXrayWrapper() bool WaiveXrayWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, - bool set, js::PropertyDescriptor *desc) + js::PropertyDescriptor *desc, unsigned flags) { - return CrossCompartmentWrapper::getPropertyDescriptor(cx, wrapper, id, set, desc) && + return CrossCompartmentWrapper::getPropertyDescriptor(cx, wrapper, id, desc, flags) && WrapperFactory::WaiveXrayAndWrap(cx, &desc->value); } bool WaiveXrayWrapper::getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, - bool set, js::PropertyDescriptor *desc) + js::PropertyDescriptor *desc, unsigned flags) { - return CrossCompartmentWrapper::getOwnPropertyDescriptor(cx, wrapper, id, set, desc) && + return CrossCompartmentWrapper::getOwnPropertyDescriptor(cx, wrapper, id, desc, flags) && WrapperFactory::WaiveXrayAndWrap(cx, &desc->value); } diff --git a/js/xpconnect/wrappers/WaiveXrayWrapper.h b/js/xpconnect/wrappers/WaiveXrayWrapper.h index 26992d579608..e4b2041aa069 100644 --- a/js/xpconnect/wrappers/WaiveXrayWrapper.h +++ b/js/xpconnect/wrappers/WaiveXrayWrapper.h @@ -21,9 +21,9 @@ class WaiveXrayWrapper : public js::CrossCompartmentWrapper { virtual ~WaiveXrayWrapper(); virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, - bool set, js::PropertyDescriptor *desc) MOZ_OVERRIDE; + js::PropertyDescriptor *desc, unsigned flags) MOZ_OVERRIDE; virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, - bool set, js::PropertyDescriptor *desc) MOZ_OVERRIDE; + js::PropertyDescriptor *desc, unsigned flags) MOZ_OVERRIDE; virtual bool get(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id, js::Value *vp) MOZ_OVERRIDE; diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index c9b70afbbc82..c5b42a1943a5 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -132,7 +132,7 @@ public: virtual bool resolveOwnProperty(JSContext *cx, js::Wrapper &jsWrapper, JSObject *wrapper, JSObject *holder, - jsid id, bool set, JSPropertyDescriptor *desc); + jsid id, JSPropertyDescriptor *desc, unsigned flags); static bool call(JSContext *cx, JSObject *wrapper, unsigned argc, Value *vp) { @@ -183,10 +183,10 @@ class XPCWrappedNativeXrayTraits : public XrayTraits { public: static bool resolveNativeProperty(JSContext *cx, JSObject *wrapper, JSObject *holder, jsid id, - bool set, JSPropertyDescriptor *desc); + JSPropertyDescriptor *desc, unsigned flags); virtual bool resolveOwnProperty(JSContext *cx, js::Wrapper &jsWrapper, JSObject *wrapper, - JSObject *holder, jsid id, bool set, - JSPropertyDescriptor *desc); + JSObject *holder, jsid id, JSPropertyDescriptor *desc, + unsigned flags); static bool defineProperty(JSContext *cx, JSObject *wrapper, jsid id, JSPropertyDescriptor *desc, bool *defined); static bool enumerateNames(JSContext *cx, JSObject *wrapper, unsigned flags, @@ -198,7 +198,7 @@ public: static bool isResolving(JSContext *cx, JSObject *holder, jsid id); static bool resolveDOMCollectionProperty(JSContext *cx, JSObject *wrapper, JSObject *holder, - jsid id, bool set, PropertyDescriptor *desc); + jsid id, PropertyDescriptor *desc, unsigned flags); static XPCWrappedNative* getWN(JSObject *wrapper) { return GetWrappedNative(getTargetObject(wrapper)); @@ -223,10 +223,10 @@ class DOMXrayTraits : public XrayTraits { public: static bool resolveNativeProperty(JSContext *cx, JSObject *wrapper, JSObject *holder, jsid id, - bool set, JSPropertyDescriptor *desc); + JSPropertyDescriptor *desc, unsigned flags); virtual bool resolveOwnProperty(JSContext *cx, js::Wrapper &jsWrapper, JSObject *wrapper, - JSObject *holder, jsid id, bool set, - JSPropertyDescriptor *desc); + JSObject *holder, jsid id, JSPropertyDescriptor *desc, + unsigned flags); static bool enumerateNames(JSContext *cx, JSObject *wrapper, unsigned flags, JS::AutoIdVector &props); static bool call(JSContext *cx, JSObject *wrapper, unsigned argc, Value *vp); @@ -619,8 +619,8 @@ private: // any native property. bool XPCWrappedNativeXrayTraits::resolveDOMCollectionProperty(JSContext *cx, JSObject *wrapper, - JSObject *holder, jsid id, bool set, - PropertyDescriptor *desc) + JSObject *holder, jsid id, + PropertyDescriptor *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). @@ -638,7 +638,6 @@ XPCWrappedNativeXrayTraits::resolveDOMCollectionProperty(JSContext *cx, JSObject bool retval = true; JSObject *pobj = NULL; - unsigned flags = (set ? JSRESOLVE_ASSIGNING : 0); nsresult rv = wn->GetScriptableInfo()->GetCallback()->NewResolve(wn, cx, wrapper, id, flags, &pobj, &retval); if (NS_FAILED(rv)) { @@ -716,17 +715,17 @@ XPCWrappedNativeXrayTraits::preserveWrapper(JSObject *target) bool XPCWrappedNativeXrayTraits::resolveNativeProperty(JSContext *cx, JSObject *wrapper, - JSObject *holder, jsid id, bool set, - JSPropertyDescriptor *desc) + JSObject *holder, jsid id, + JSPropertyDescriptor *desc, unsigned flags) { MOZ_ASSERT(js::GetObjectJSClass(holder) == &HolderClass); XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance(); - if (!set && + if (!(flags & JSRESOLVE_ASSIGNING) && id == rt->GetStringID(XPCJSRuntime::IDX_MOZMATCHESSELECTOR) && Is(wrapper)) { // XPC calling mechanism cannot handle call/bind properly in some cases - // especially through xray wrappers. This is a temoorary work around for + // especially through xray wrappers. This is a temporary work around for // this problem for mozMatchesSelector. See: bug 763897. desc->obj = wrapper; desc->attrs = JSPROP_ENUMERATE; @@ -755,7 +754,7 @@ XPCWrappedNativeXrayTraits::resolveNativeProperty(JSContext *cx, JSObject *wrapp // check for those. if (!JSID_IS_STRING(id)) { /* Not found */ - return resolveDOMCollectionProperty(cx, wrapper, holder, id, set, desc); + return resolveDOMCollectionProperty(cx, wrapper, holder, id, desc, flags); } XPCNativeInterface *iface; @@ -766,7 +765,7 @@ XPCWrappedNativeXrayTraits::resolveNativeProperty(JSContext *cx, JSObject *wrapp !(iface = ccx.GetInterface()) || !(member = ccx.GetMember())) { /* Not found */ - return resolveDOMCollectionProperty(cx, wrapper, holder, id, set, desc); + return resolveDOMCollectionProperty(cx, wrapper, holder, id, desc, flags); } desc->obj = holder; @@ -912,7 +911,7 @@ nodePrincipal_getter(JSContext *cx, JSHandleObject wrapper, JSHandleId id, JSMut bool XrayTraits::resolveOwnProperty(JSContext *cx, js::Wrapper &jsWrapper, JSObject *wrapper, JSObject *holder, jsid id, - bool set, PropertyDescriptor *desc) + PropertyDescriptor *desc, unsigned flags) { desc->obj = NULL; JSObject *target = getTargetObject(wrapper); @@ -938,11 +937,11 @@ XrayTraits::resolveOwnProperty(JSContext *cx, js::Wrapper &jsWrapper, bool XPCWrappedNativeXrayTraits::resolveOwnProperty(JSContext *cx, js::Wrapper &jsWrapper, JSObject *wrapper, JSObject *holder, jsid id, - bool set, PropertyDescriptor *desc) + PropertyDescriptor *desc, unsigned flags) { // Call the common code. bool ok = XrayTraits::resolveOwnProperty(cx, jsWrapper, wrapper, holder, - id, set, desc); + id, desc, flags); if (!ok || desc->obj) return ok; @@ -957,7 +956,7 @@ XPCWrappedNativeXrayTraits::resolveOwnProperty(JSContext *cx, js::Wrapper &jsWra (id == rt->GetStringID(XPCJSRuntime::IDX_DOCUMENTURIOBJECT) && Is(wrapper)))) { bool status; - Wrapper::Action action = set ? Wrapper::SET : Wrapper::GET; + Wrapper::Action action = (flags & JSRESOLVE_ASSIGNING) ? Wrapper::SET : Wrapper::GET; desc->obj = NULL; // default value if (!jsWrapper.enter(cx, wrapper, id, action, &status)) return status; @@ -976,7 +975,6 @@ XPCWrappedNativeXrayTraits::resolveOwnProperty(JSContext *cx, js::Wrapper &jsWra return true; } - unsigned flags = (set ? JSRESOLVE_ASSIGNING : 0); JSBool hasProp; if (!JS_HasPropertyById(cx, holder, id, &hasProp)) { return false; @@ -1118,7 +1116,7 @@ XPCWrappedNativeXrayTraits::construct(JSContext *cx, JSObject *wrapper, bool DOMXrayTraits::resolveNativeProperty(JSContext *cx, JSObject *wrapper, JSObject *holder, jsid id, - bool set, JSPropertyDescriptor *desc) + JSPropertyDescriptor *desc, unsigned flags) { JSObject *obj = getTargetObject(wrapper); if (!XrayResolveNativeProperty(cx, wrapper, obj, id, desc)) @@ -1132,16 +1130,17 @@ DOMXrayTraits::resolveNativeProperty(JSContext *cx, JSObject *wrapper, JSObject bool DOMXrayTraits::resolveOwnProperty(JSContext *cx, js::Wrapper &jsWrapper, JSObject *wrapper, - JSObject *holder, jsid id, bool set, JSPropertyDescriptor *desc) + JSObject *holder, jsid id, JSPropertyDescriptor *desc, + unsigned flags) { // Call the common code. bool ok = XrayTraits::resolveOwnProperty(cx, jsWrapper, wrapper, holder, - id, set, desc); + id, desc, flags); if (!ok || desc->obj) return ok; JSObject *obj = getTargetObject(wrapper); - if (!XrayResolveOwnProperty(cx, wrapper, obj, id, set, desc)) + if (!XrayResolveOwnProperty(cx, wrapper, obj, id, desc, flags)) return false; NS_ASSERTION(!desc->obj || desc->obj == wrapper, @@ -1302,7 +1301,7 @@ XrayToString(JSContext *cx, unsigned argc, jsval *vp) template bool XrayWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, - bool set, js::PropertyDescriptor *desc) + js::PropertyDescriptor *desc, unsigned flags) { JSObject *holder = Traits::singleton.ensureHolder(cx, wrapper); if (Traits::isResolving(cx, holder, id)) { @@ -1311,7 +1310,7 @@ XrayWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrappe } bool status; - Wrapper::Action action = set ? Wrapper::SET : Wrapper::GET; + Wrapper::Action action = (flags & JSRESOLVE_ASSIGNING) ? Wrapper::SET : Wrapper::GET; desc->obj = NULL; // default value if (!this->enter(cx, wrapper, id, action, &status)) return status; @@ -1323,11 +1322,8 @@ XrayWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrappe JSObject *obj = Traits::getTargetObject(wrapper); { JSAutoCompartment ac(cx, obj); - if (!JS_GetPropertyDescriptorById(cx, obj, id, - (set ? JSRESOLVE_ASSIGNING : 0), - desc)) { + if (!JS_GetPropertyDescriptorById(cx, obj, id, flags, desc)) return false; - } } if (desc->obj) @@ -1345,7 +1341,7 @@ XrayWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrappe if (AccessCheck::wrapperSubsumes(wrapper) && id == rt->GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT)) { bool status; - Wrapper::Action action = set ? Wrapper::SET : Wrapper::GET; + Wrapper::Action action = (flags & JSRESOLVE_ASSIGNING) ? Wrapper::SET : Wrapper::GET; desc->obj = NULL; // default value if (!this->enter(cx, wrapper, id, action, &status)) return status; @@ -1359,7 +1355,7 @@ XrayWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrappe return true; } - if (!Traits::singleton.resolveOwnProperty(cx, *this, wrapper, holder, id, set, desc)) + if (!Traits::singleton.resolveOwnProperty(cx, *this, wrapper, holder, id, desc, flags)) return false; if (desc->obj) @@ -1373,7 +1369,7 @@ XrayWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrappe } // Nothing in the cache. Call through, and cache the result. - if (!Traits::resolveNativeProperty(cx, wrapper, holder, id, set, desc)) + if (!Traits::resolveNativeProperty(cx, wrapper, holder, id, desc, flags)) return false; if (!desc->obj) { @@ -1393,7 +1389,6 @@ XrayWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrappe desc->obj = wrapper; - unsigned flags = (set ? JSRESOLVE_ASSIGNING : 0); return JS_DefinePropertyById(cx, holder, id, desc->value, desc->getter, desc->setter, desc->attrs) && JS_GetPropertyDescriptorById(cx, holder, id, flags, desc); @@ -1402,7 +1397,7 @@ XrayWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrappe template bool XrayWrapper::getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, - bool set, PropertyDescriptor *desc) + PropertyDescriptor *desc, unsigned flags) { JSObject *holder = Traits::singleton.ensureHolder(cx, wrapper); if (Traits::isResolving(cx, holder, id)) { @@ -1411,7 +1406,7 @@ XrayWrapper::getOwnPropertyDescriptor(JSContext *cx, JSObject *wra } bool status; - Wrapper::Action action = set ? Wrapper::SET : Wrapper::GET; + Wrapper::Action action = (flags & JSRESOLVE_ASSIGNING) ? Wrapper::SET : Wrapper::GET; desc->obj = NULL; // default value if (!this->enter(cx, wrapper, id, action, &status)) return status; @@ -1425,24 +1420,20 @@ XrayWrapper::getOwnPropertyDescriptor(JSContext *cx, JSObject *wra JSObject *obj = Traits::getTargetObject(wrapper); { JSAutoCompartment ac(cx, obj); - if (!JS_GetPropertyDescriptorById(cx, obj, id, - (set ? JSRESOLVE_ASSIGNING : 0), - desc)) { + if (!JS_GetPropertyDescriptorById(cx, obj, id, flags, desc)) return false; - } } desc->obj = (desc->obj == obj) ? wrapper : nullptr; return JS_WrapPropertyDescriptor(cx, desc); } - if (!Traits::singleton.resolveOwnProperty(cx, *this, wrapper, holder, id, set, desc)) + if (!Traits::singleton.resolveOwnProperty(cx, *this, wrapper, holder, id, desc, flags)) return false; if (desc->obj) return true; - unsigned flags = (set ? JSRESOLVE_ASSIGNING : 0); if (!JS_GetPropertyDescriptorById(cx, holder, id, flags, desc)) return false; @@ -1470,7 +1461,7 @@ XrayWrapper::defineProperty(JSContext *cx, JSObject *wrapper, jsid } PropertyDescriptor existing_desc; - if (!getOwnPropertyDescriptor(cx, wrapper, id, true, &existing_desc)) + if (!getOwnPropertyDescriptor(cx, wrapper, id, &existing_desc, JSRESOLVE_ASSIGNING)) return false; if (existing_desc.obj && (existing_desc.attrs & JSPROP_PERMANENT)) diff --git a/js/xpconnect/wrappers/XrayWrapper.h b/js/xpconnect/wrappers/XrayWrapper.h index ffba122faa83..06b9ac29e968 100644 --- a/js/xpconnect/wrappers/XrayWrapper.h +++ b/js/xpconnect/wrappers/XrayWrapper.h @@ -5,9 +5,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "mozilla/Attributes.h" +#include "mozilla/GuardObjects.h" + #include "jsapi.h" #include "jswrapper.h" -#include "mozilla/GuardObjects.h" // Xray wrappers re-resolve the original native properties on the native // object and always directly access to those properties. @@ -62,9 +64,10 @@ class XrayWrapper : public Base { /* Fundamental proxy traps. */ virtual bool getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, - bool set, js::PropertyDescriptor *desc); + js::PropertyDescriptor *desc, unsigned flags) MOZ_OVERRIDE; virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id, - bool set, js::PropertyDescriptor *desc); + js::PropertyDescriptor *desc, + unsigned flags) MOZ_OVERRIDE; virtual bool defineProperty(JSContext *cx, JSObject *wrapper, jsid id, js::PropertyDescriptor *desc); virtual bool getOwnPropertyNames(JSContext *cx, JSObject *wrapper, @@ -108,10 +111,10 @@ public: } virtual bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, - bool set, js::PropertyDescriptor *desc) MOZ_OVERRIDE; + js::PropertyDescriptor *desc, unsigned flags) MOZ_OVERRIDE; virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, - jsid id, bool set, - js::PropertyDescriptor *desc) MOZ_OVERRIDE; + jsid id, js::PropertyDescriptor *desc, + unsigned flags) MOZ_OVERRIDE; // We just forward the derived traps to the BaseProxyHandler versions which // implement them in terms of the fundamental traps.