Bug 1101182 - One interpose call for one property access. r=bholley
authorGabor Krizsanits <gkrizsanits@mozilla.com>
Mon, 04 May 2015 08:57:52 +0200
changeset 273594 f20483b68bda5a002dbc6cfdad752083408ed116
parent 273549 d1b2c31a46d091d87734f3e0509837b03d93a878
child 273595 446a65d17e3387f5cfeb1eab97c62809d1931da2
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1101182
milestone40.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 1101182 - One interpose call for one property access. r=bholley
dom/base/nsGlobalWindow.h
js/xpconnect/tests/unit/test_interposition.js
js/xpconnect/wrappers/AddonWrapper.cpp
--- a/dom/base/nsGlobalWindow.h
+++ b/dom/base/nsGlobalWindow.h
@@ -140,16 +140,18 @@ NS_CreateJSTimeoutHandler(nsGlobalWindow
                           const mozilla::dom::Sequence<JS::Value>& aArguments,
                           mozilla::ErrorResult& aError);
 
 extern already_AddRefed<nsIScriptTimeoutHandler>
 NS_CreateJSTimeoutHandler(JSContext* aCx, nsGlobalWindow *aWindow,
                           const nsAString& aExpression,
                           mozilla::ErrorResult& aError);
 
+extern const js::Class OuterWindowProxyClass;
+
 /*
  * Timeout struct that holds information about each script
  * timeout.  Holds a strong reference to an nsIScriptTimeoutHandler, which
  * abstracts the language specific cruft.
  */
 struct nsTimeout final
   : mozilla::LinkedListElement<nsTimeout>
 {
--- a/js/xpconnect/tests/unit/test_interposition.js
+++ b/js/xpconnect/tests/unit/test_interposition.js
@@ -58,18 +58,20 @@ let TestInterposition = {
     return null;
   }
 };
 
 function run_test()
 {
   Cu.setAddonInterposition(ADDONID, TestInterposition);
 
+  Cu.importGlobalProperties(["XMLHttpRequest"]);
+
   let sandbox = Cu.Sandbox(this, {addonId: ADDONID});
-  sandbox.outerObj = {};
+  sandbox.outerObj = new XMLHttpRequest();
 
   expectAccess("abcxyz", () => {
     Cu.evalInSandbox("outerObj.abcxyz = 12;", sandbox);
   });
 
   expectAccess("utils", () => {
     Cu.evalInSandbox("Components.utils;", sandbox);
   });
--- a/js/xpconnect/wrappers/AddonWrapper.cpp
+++ b/js/xpconnect/wrappers/AddonWrapper.cpp
@@ -6,28 +6,41 @@
 
 #include "AddonWrapper.h"
 #include "WrapperFactory.h"
 #include "XrayWrapper.h"
 #include "jsapi.h"
 #include "jsfriendapi.h"
 #include "nsIAddonInterposition.h"
 #include "xpcprivate.h"
+#include "mozilla/dom/BindingUtils.h"
+#include "nsGlobalWindow.h"
 
 #include "nsID.h"
 
 using namespace js;
 using namespace JS;
 
 namespace xpc {
 
 bool
 Interpose(JSContext* cx, HandleObject target, const nsIID* iid, HandleId id,
           MutableHandle<JSPropertyDescriptor> descriptor)
 {
+    // We only want to do interpostion on DOM instances and
+    // wrapped natives.
+    RootedObject unwrapped(cx, UncheckedUnwrap(target));
+    const js::Class* clasp = js::GetObjectClass(unwrapped);
+    if (!mozilla::dom::IsDOMClass(clasp) &&
+        !IS_WN_CLASS(clasp) &&
+        !IS_PROTO_CLASS(clasp) &&
+        clasp != &OuterWindowProxyClass) {
+        return true;
+    }
+
     XPCWrappedNativeScope* scope = ObjectScope(CurrentGlobalOrNull(cx));
     MOZ_ASSERT(scope->HasInterposition());
 
     nsCOMPtr<nsIAddonInterposition> interp = scope->GetInterposition();
     JSAddonId* addonId = AddonIdOfObject(target);
     RootedValue addonIdValue(cx, StringValue(StringOfAddonId(addonId)));
     RootedValue prop(cx, IdToValue(id));
     RootedValue targetValue(cx, ObjectValue(*target));