Backed out changeset c79e8bee853e (bug 851892)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Fri, 20 Jan 2017 19:29:38 +0100
changeset 377685 7d4dc504eea50040e44edc20e0857cb28c2e4a96
parent 377684 8241272efd6a432caa36ca9b2da4bd8c8cb7e9f8
child 377686 b01edf06d37c5187a99e79565b5b22bceb582aaa
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs851892
milestone53.0a1
backs outc79e8bee853e454fd563fc46349224479b7ddc56
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
Backed out changeset c79e8bee853e (bug 851892)
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfo.h
dom/bindings/Bindings.conf
layout/style/Rule.h
layout/style/nsCSSRules.cpp
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -64,16 +64,17 @@
 #include "nsIDOMXULButtonElement.h"
 #include "nsIDOMXULCheckboxElement.h"
 #include "nsIDOMXULPopupElement.h"
 
 // Event related includes
 #include "nsIDOMEventTarget.h"
 
 // CSS related includes
+#include "nsCSSRules.h"
 #include "nsIDOMCSSRule.h"
 #include "nsMemory.h"
 
 // includes needed for the prototype chain interfaces
 #include "nsIDOMXULCommandDispatcher.h"
 #include "nsIControllers.h"
 #ifdef MOZ_XUL
 #include "nsITreeSelection.h"
@@ -1887,16 +1888,42 @@ nsEventTargetSH::PreCreate(nsISupports *
 
 void
 nsEventTargetSH::PreserveWrapper(nsISupports *aNative)
 {
   DOMEventTargetHelper* target = DOMEventTargetHelper::FromSupports(aNative);
   target->PreserveWrapper(aNative);
 }
 
+// CSS rule helper
+NS_IMETHODIMP
+nsCSSRuleSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
+                       JSObject *aGlobalObj, JSObject **parentObj)
+{
+  JS::Rooted<JSObject*> globalObj(cx, aGlobalObj);
+  nsCOMPtr<nsIDOMCSSRule> rule = do_QueryInterface(nativeObj);
+  if (!rule) {
+    return NS_ERROR_UNEXPECTED;
+  }
+  css::Rule* cssRule = rule->GetCSSRule();
+  MOZ_ASSERT(cssRule);
+  nsIDocument* doc = cssRule->GetDocument();
+  if (!doc) {
+    *parentObj = globalObj;
+    return NS_OK;
+  }
+
+  nsIGlobalObject* global = doc->GetScopeObject();
+  if (!global) {
+    return NS_ERROR_UNEXPECTED;
+  }
+  *parentObj = global->GetGlobalJSObject();
+  return *parentObj ? NS_OK : NS_ERROR_FAILURE;
+}
+
 // nsIDOMEventListener::HandleEvent() 'this' converter helper
 
 NS_INTERFACE_MAP_BEGIN(nsEventListenerThisTranslator)
   NS_INTERFACE_MAP_ENTRY(nsIXPCFunctionThisTranslator)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
 
--- a/dom/base/nsDOMClassInfo.h
+++ b/dom/base/nsDOMClassInfo.h
@@ -177,16 +177,38 @@ protected:
   }
 public:
   NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
                        JSObject *globalObj, JSObject **parentObj) override;
 
   virtual void PreserveWrapper(nsISupports *aNative) override;
 };
 
+// Makes sure that we always create our wrapper in the right global, so we won't
+// cache one from the wrong global.
+class nsCSSRuleSH : public nsDOMGenericSH
+{
+protected:
+  explicit nsCSSRuleSH(nsDOMClassInfoData* aData) : nsDOMGenericSH(aData)
+  {
+  }
+
+  virtual ~nsCSSRuleSH()
+  {
+  }
+public:
+  NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
+                       JSObject *globalObj, JSObject **parentObj) override;
+
+  static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
+  {
+    return new nsCSSRuleSH(aData);
+  }
+};
+
 // A place to hang some static methods that we should really consider
 // moving to be nsGlobalWindow member methods.  See bug 1062418.
 class nsWindowSH
 {
 protected:
   static nsresult GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
                                 JS::Handle<JSObject*> obj, JS::Handle<jsid> id,
                                 JS::MutableHandle<JS::PropertyDescriptor> desc);
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -259,16 +259,17 @@ DOMInterfaces = {
     'headerFile': 'nsCSSRules.h',
 },
 
 'CSSPrimitiveValue': {
     'nativeType': 'nsROCSSPrimitiveValue',
 },
 
 'CSSRule': {
+    'hasXPConnectImpls': True,
     'concrete': False,
     'nativeType': 'mozilla::css::Rule'
 },
 
 'CSSStyleDeclaration': {
     'nativeType': 'nsICSSDeclaration'
 },
 
--- a/layout/style/Rule.h
+++ b/layout/style/Rule.h
@@ -137,9 +137,23 @@ protected:
   // Keep the same type so that MSVC packs them.
   uint32_t          mLineNumber;
   uint32_t          mColumnNumber;
 };
 
 } // namespace css
 } // namespace mozilla
 
+// Specialization of the bindings UnwrapArg setup for css::Rule, so we can avoid
+// adding an IID to css::Rule.  This can go away once all css::Rule subclasses
+// are on WebIDL bindings.
+
+#include "js/TypeDecls.h"
+
+namespace mozilla {
+namespace dom {
+template <>
+nsresult
+UnwrapArg(JS::Handle<JSObject*> src, css::Rule** ppArg);
+} // namepace dom
+} // namespace mozilla
+
 #endif /* mozilla_css_Rule_h___ */
--- a/layout/style/nsCSSRules.cpp
+++ b/layout/style/nsCSSRules.cpp
@@ -51,16 +51,37 @@
 #include "nsCCUncollectableMarker.h"
 #include "nsWrapperCacheInlines.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 // base class for all rule types in a CSS style sheet
 
+// Temporary code that can go away once all css::Rules are on WebIDL bindings.
+#include "xpcpublic.h"
+namespace mozilla {
+namespace dom {
+template<>
+nsresult
+UnwrapArg(JS::Handle<JSObject*> src, css::Rule** ppArg)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  nsCOMPtr<nsIDOMCSSRule> rule =
+    do_QueryInterface(xpc::UnwrapReflectorToISupports(src));
+  if (!rule) {
+    return NS_NOINTERFACE;
+  }
+  *ppArg = rule->GetCSSRule();
+  NS_ADDREF(*ppArg);
+  return NS_OK;
+}
+} // namespace dom
+} // namespace mozilla
+
 namespace mozilla {
 namespace css {
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(Rule)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(Rule)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Rule)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY