Bug 856067 - Add some helpful logging to the console when we deny access to a non-Xrayable object. r=gabor
authorBobby Holley <bobbyholley@gmail.com>
Mon, 14 Jul 2014 10:09:07 -0700
changeset 215756 d8d4e3267f18eaa5708a9d08c28888f379bdb979
parent 215755 01c8a2687cd96406cb9b0c82c1b2fcad3db4970f
child 215757 66a22c818713f8dd76b05c5863dae0f09282f040
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor
bugs856067
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 856067 - Add some helpful logging to the console when we deny access to a non-Xrayable object. r=gabor
js/xpconnect/wrappers/XrayWrapper.cpp
--- a/js/xpconnect/wrappers/XrayWrapper.cpp
+++ b/js/xpconnect/wrappers/XrayWrapper.cpp
@@ -64,16 +64,18 @@ IsErrorObjectKey(JSProtoKey key)
 }
 
 inline bool
 IsTypedArrayKey(JSProtoKey key)
 {
     return key >= JSProto_Int8Array && key <= JSProto_Uint8ClampedArray;
 }
 
+bool SilentFailure(JSContext *cx, JS::HandleId id, const char *reason);
+
 // Whitelist for the standard ES classes we can Xray to.
 static bool
 IsJSXraySupported(JSProtoKey key)
 {
     if (IsTypedArrayKey(key))
         return true;
     if (IsErrorObjectKey(key))
         return true;
@@ -488,16 +490,27 @@ public:
 
     virtual bool resolveNativeProperty(JSContext *cx, HandleObject wrapper,
                                        HandleObject holder, HandleId id,
                                        MutableHandle<JSPropertyDescriptor> desc) MOZ_OVERRIDE
     {
         MOZ_CRASH("resolveNativeProperty hook should never be called with HasPrototype = 1");
     }
 
+    virtual bool resolveOwnProperty(JSContext *cx, const Wrapper &jsWrapper, HandleObject wrapper,
+                                    HandleObject holder, HandleId id,
+                                    MutableHandle<JSPropertyDescriptor> desc) MOZ_OVERRIDE
+    {
+        bool ok = XrayTraits::resolveOwnProperty(cx, jsWrapper, wrapper, holder, id, desc);
+        if (!ok || desc.object())
+            return ok;
+
+        return SilentFailure(cx, id, "Object is not safely Xrayable");
+    }
+
     bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id,
                         MutableHandle<JSPropertyDescriptor> desc,
                         Handle<JSPropertyDescriptor> existingDesc, bool *defined)
     {
         *defined = false;
         return true;
     }
 
@@ -555,27 +568,27 @@ public:
     {
         RootedObject global(cx, JS_GetGlobalForObject(cx, wrapper));
         return JS_NewObjectWithGivenProto(cx, nullptr, JS::NullPtr(), global);
     }
 
     static OpaqueXrayTraits singleton;
 };
 
-inline bool
+bool
 SilentFailure(JSContext *cx, HandleId id, const char *reason)
 {
 #ifdef DEBUG
     nsAutoJSString name;
     if (!name.init(cx, id))
         return false;
     AutoFilename filename;
     unsigned line = 0;
     DescribeScriptedCaller(cx, &filename, &line);
-    NS_WARNING(nsPrintfCString("Denied access to property |%s| on Xrayed Object: %s (@%s:%u)",
+    NS_WARNING(nsPrintfCString("Silently denied access to property |%s|: %s (@%s:%u)",
                                NS_LossyConvertUTF16toASCII(name).get(), reason,
                                filename.get(), line).get());
 #endif
     return true;
 }
 
 bool JSXrayTraits::getOwnPropertyFromTargetIfSafe(JSContext *cx,
                                                   HandleObject target,