Bug 975277 - Clean up the XPCWN XrayHolder a bit. r=gabor
authorBobby Holley <bobbyholley@gmail.com>
Fri, 21 Feb 2014 15:55:31 -0800
changeset 181022 fd04a8b8ccc489af9a2a9ad10f639f35dd0857ba
parent 181021 5db44a9eece27d6aa7345fcd97a3e2b33fa77629
child 181023 02dffb9d2748f78b2e171a94834f130d36879852
push idunknown
push userunknown
push dateunknown
reviewersgabor
bugs975277
milestone30.0a1
Bug 975277 - Clean up the XPCWN XrayHolder a bit. r=gabor
js/xpconnect/wrappers/AccessCheck.cpp
js/xpconnect/wrappers/WrapperFactory.cpp
js/xpconnect/wrappers/XrayWrapper.cpp
js/xpconnect/wrappers/XrayWrapper.h
--- a/js/xpconnect/wrappers/AccessCheck.cpp
+++ b/js/xpconnect/wrappers/AccessCheck.cpp
@@ -200,17 +200,17 @@ AccessCheck::isCrossOriginAccessPermitte
 
     // For XOWs, we generally want to deny enumerate-like operations, but fail
     // silently (see CrossOriginAccessiblePropertiesOnly::deny).
     if (act == Wrapper::ENUMERATE)
         return false;
 
     const char *name;
     const js::Class *clasp = js::GetObjectClass(obj);
-    MOZ_ASSERT(Jsvalify(clasp) != &XrayUtils::HolderClass, "shouldn't have a holder here");
+    MOZ_ASSERT(!XrayUtils::IsXPCWNHolderClass(Jsvalify(clasp)), "shouldn't have a holder here");
     if (clasp->ext.innerObject)
         name = "Window";
     else
         name = clasp->name;
 
     if (JSID_IS_STRING(id)) {
         if (IsPermitted(name, JSID_TO_FLAT_STRING(id), act == Wrapper::SET))
             return true;
--- a/js/xpconnect/wrappers/WrapperFactory.cpp
+++ b/js/xpconnect/wrappers/WrapperFactory.cpp
@@ -369,17 +369,17 @@ JSObject *
 WrapperFactory::Rewrap(JSContext *cx, HandleObject existing, HandleObject obj,
                        HandleObject wrappedProto, HandleObject parent,
                        unsigned flags)
 {
     MOZ_ASSERT(!IsWrapper(obj) ||
                GetProxyHandler(obj) == &XrayWaiver ||
                js::GetObjectClass(obj)->ext.innerObject,
                "wrapped object passed to rewrap");
-    MOZ_ASSERT(JS_GetClass(obj) != &XrayUtils::HolderClass, "trying to wrap a holder");
+    MOZ_ASSERT(!XrayUtils::IsXPCWNHolderClass(JS_GetClass(obj)), "trying to wrap a holder");
     MOZ_ASSERT(!js::IsInnerObject(obj));
     // We sometimes end up here after nsContentUtils has been shut down but before
     // XPConnect has been shut down, so check the context stack the roundabout way.
     MOZ_ASSERT(XPCJSRuntime::Get()->GetJSContextStack()->Peek() == cx);
 
     // Compute the information we need to select the right wrapper.
     JSCompartment *origin = js::GetObjectCompartment(obj);
     JSCompartment *target = js::GetContextCompartment(cx);
--- a/js/xpconnect/wrappers/XrayWrapper.cpp
+++ b/js/xpconnect/wrappers/XrayWrapper.cpp
@@ -32,44 +32,33 @@ using namespace mozilla;
 using js::Wrapper;
 using js::BaseProxyHandler;
 using js::IsCrossCompartmentWrapper;
 using js::UncheckedUnwrap;
 using js::CheckedUnwrap;
 
 namespace xpc {
 
-static const uint32_t JSSLOT_RESOLVING = 0;
-
-namespace XrayUtils {
-
-const JSClass HolderClass = {
-    "NativePropertyHolder",
-    JSCLASS_HAS_RESERVED_SLOTS(2),
-    JS_PropertyStub,        JS_DeletePropertyStub, holder_get,      holder_set,
-    JS_EnumerateStub,       JS_ResolveStub,  JS_ConvertStub
-};
-}
-
 using namespace XrayUtils;
 
 XrayType
 GetXrayType(JSObject *obj)
 {
     obj = js::UncheckedUnwrap(obj, /* stopAtOuter = */ false);
     if (mozilla::dom::UseDOMXray(obj))
         return XrayForDOMObject;
 
     const js::Class* clasp = js::GetObjectClass(obj);
     if (IS_WN_CLASS(clasp) || clasp->ext.innerObject)
         return XrayForWrappedNative;
 
     return NotXray;
 }
 
+const uint32_t JSSLOT_RESOLVING = 0;
 ResolvingId::ResolvingId(JSContext *cx, HandleObject wrapper, HandleId id)
   : mId(id),
     mHolder(cx, getHolderObject(wrapper)),
     mPrev(getResolvingId(mHolder)),
     mXrayShadowing(false)
 {
     js::SetReservedSlot(mHolder, JSSLOT_RESOLVING, js::PrivateValue(this));
 }
@@ -226,19 +215,26 @@ public:
     }
 
     virtual void preserveWrapper(JSObject *target);
 
     typedef ResolvingId ResolvingIdImpl;
 
     virtual JSObject* createHolder(JSContext *cx, JSObject *wrapper);
 
+    static const JSClass HolderClass;
     static XPCWrappedNativeXrayTraits singleton;
 };
 
+const JSClass XPCWrappedNativeXrayTraits::HolderClass = {
+    "NativePropertyHolder", JSCLASS_HAS_RESERVED_SLOTS(2),
+    JS_PropertyStub, JS_DeletePropertyStub, holder_get, holder_set,
+    JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub
+};
+
 class DOMXrayTraits : public XrayTraits
 {
 public:
     enum {
         HasPrototype = 0
     };
 
     static const XrayType Type = XrayForDOMObject;
@@ -530,16 +526,27 @@ XPCWrappedNativeXrayTraits::isResolving(
                                         jsid id)
 {
     ResolvingId *cur = ResolvingId::getResolvingId(holder);
     if (!cur)
         return false;
     return cur->isResolving(id);
 }
 
+namespace XrayUtils {
+
+bool
+IsXPCWNHolderClass(const JSClass *clasp)
+{
+  return clasp == &XPCWrappedNativeXrayTraits::HolderClass;
+}
+
+}
+
+
 // Some DOM objects have shared properties that don't have an explicit
 // getter/setter and rely on the class getter/setter. We install a
 // class getter/setter on the holder object to trigger them.
 bool
 holder_get(JSContext *cx, HandleObject wrapper, HandleId id, MutableHandleValue vp)
 {
     // JSClass::getProperty is wacky enough that it's hard to be sure someone
     // can't inherit this getter by prototyping a random object to an
--- a/js/xpconnect/wrappers/XrayWrapper.h
+++ b/js/xpconnect/wrappers/XrayWrapper.h
@@ -23,17 +23,17 @@ namespace xpc {
 bool
 holder_get(JSContext *cx, JS::HandleObject holder, JS::HandleId id, JS::MutableHandleValue vp);
 bool
 holder_set(JSContext *cx, JS::HandleObject holder, JS::HandleId id, bool strict,
            JS::MutableHandleValue vp);
 
 namespace XrayUtils {
 
-extern const JSClass HolderClass;
+bool IsXPCWNHolderClass(const JSClass *clasp);
 
 bool CloneExpandoChain(JSContext *cx, JSObject *src, JSObject *dst);
 
 bool
 IsTransparent(JSContext *cx, JS::HandleObject wrapper, JS::HandleId id);
 
 JSObject *
 GetNativePropertiesObject(JSContext *cx, JSObject *wrapper);