diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index 56cae89edb8f..aa5d63db32eb 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -19,10 +19,25 @@ namespace dom { class TabChildGlobal; class ProcessGlobal; } // namespace dom +namespace css { +class ImportRule; +class NameSpaceRule; +class StyleRule; +class MediaRule; +class DocumentRule; +} // namespace css +class ServoStyleRule; +class CSSSupportsRule; } // namespace mozilla class SandboxPrivate; class nsInProcessTabChildGlobal; class nsWindowRoot; +class nsCSSFontFaceRule; +class nsCSSFontFeatureValuesRule; +class nsCSSKeyframeRule; +class nsCSSKeyframesRule; +class nsCSSPageRule; +class nsCSSCounterStyleRule; #define NS_WRAPPERCACHE_IID \ { 0x6f3179a1, 0x36f7, 0x4a5c, \ @@ -272,11 +287,27 @@ protected: } private: + // Friend declarations for things that need to be able to call + // SetIsNotDOMBinding(). The goal is to get rid of all of these, and + // SetIsNotDOMBinding() too. friend class mozilla::dom::TabChildGlobal; friend class mozilla::dom::ProcessGlobal; friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; + friend class mozilla::css::ImportRule; + friend class mozilla::css::NameSpaceRule; + friend class mozilla::css::StyleRule; + friend class mozilla::css::MediaRule; + friend class mozilla::css::DocumentRule; + friend class mozilla::ServoStyleRule; + friend class mozilla::CSSSupportsRule; + friend class nsCSSFontFaceRule; + friend class nsCSSFontFeatureValuesRule; + friend class nsCSSKeyframeRule; + friend class nsCSSKeyframesRule; + friend class nsCSSPageRule; + friend class nsCSSCounterStyleRule; void SetIsNotDOMBinding() { MOZ_ASSERT(!mWrapper && !(GetWrapperFlags() & ~WRAPPER_IS_NOT_DOM_BINDING), diff --git a/layout/style/ImportRule.h b/layout/style/ImportRule.h index a4e30837dc51..3ad8246c94ba 100644 --- a/layout/style/ImportRule.h +++ b/layout/style/ImportRule.h @@ -52,6 +52,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + // nsIDOMCSSRule interface NS_DECL_NSIDOMCSSRULE diff --git a/layout/style/NameSpaceRule.h b/layout/style/NameSpaceRule.h index 20947112eaf9..406938650ab7 100644 --- a/layout/style/NameSpaceRule.h +++ b/layout/style/NameSpaceRule.h @@ -54,6 +54,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + // nsIDOMCSSRule interface NS_DECL_NSIDOMCSSRULE diff --git a/layout/style/Rule.h b/layout/style/Rule.h index 6b5af0954b13..8d9c256d0729 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -12,6 +12,7 @@ #include "mozilla/MemoryReporting.h" #include "nsISupports.h" #include "nsIDOMCSSRule.h" +#include "nsWrapperCache.h" class nsIDocument; struct nsRuleData; @@ -29,7 +30,9 @@ class GroupRule; DECL_STYLE_RULE_INHERIT_NO_DOMRULE \ virtual nsIDOMCSSRule* GetDOMRule() override; -class Rule : public nsISupports { +class Rule : public nsISupports + , public nsWrapperCache +{ protected: Rule(uint32_t aLineNumber, uint32_t aColumnNumber) : mSheet(nullptr), @@ -52,7 +55,7 @@ protected: public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_CLASS(Rule) + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Rule) #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0; diff --git a/layout/style/ServoStyleRule.cpp b/layout/style/ServoStyleRule.cpp index ec436d0e5b97..81a824eacb8d 100644 --- a/layout/style/ServoStyleRule.cpp +++ b/layout/style/ServoStyleRule.cpp @@ -104,6 +104,7 @@ ServoStyleRule::ServoStyleRule(already_AddRefed aRawRule) , mRawRule(aRawRule) , mDecls(Servo_StyleRule_GetStyle(mRawRule).Consume()) { + SetIsNotDOMBinding(); } // QueryInterface implementation for ServoStyleRule @@ -152,6 +153,14 @@ ServoStyleRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return aMallocSizeOf(this); } +/* virtual */ JSObject* +ServoStyleRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + #ifdef DEBUG void ServoStyleRule::List(FILE* out, int32_t aIndent) const diff --git a/layout/style/ServoStyleRule.h b/layout/style/ServoStyleRule.h index 03d8f4d43fe9..54ea09538ab9 100644 --- a/layout/style/ServoStyleRule.h +++ b/layout/style/ServoStyleRule.h @@ -66,6 +66,8 @@ public: already_AddRefed Clone() const final; nsIDOMCSSRule* GetDOMRule() final { return this; } size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; #ifdef DEBUG void List(FILE* out = stdout, int32_t aIndent = 0) const final; #endif diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index d3740f720ba0..97ebcc06ae8e 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -1380,6 +1380,7 @@ StyleRule::StyleRule(nsCSSSelectorList* aSelector, mSelector(aSelector), mDeclaration(aDeclaration) { + SetIsNotDOMBinding(); NS_PRECONDITION(aDeclaration, "must have a declaration"); mDeclaration->SetOwningRule(this); @@ -1391,6 +1392,7 @@ StyleRule::StyleRule(const StyleRule& aCopy) mSelector(aCopy.mSelector ? aCopy.mSelector->Clone() : nullptr), mDeclaration(new Declaration(*aCopy.mDeclaration)) { + SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); // rest is constructed lazily on existing data } @@ -1574,6 +1576,14 @@ StyleRule::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const return n; } +/* virtual */ JSObject* +StyleRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + } // namespace css } // namespace mozilla diff --git a/layout/style/StyleRule.h b/layout/style/StyleRule.h index 392164957ac7..d654ce7ea237 100644 --- a/layout/style/StyleRule.h +++ b/layout/style/StyleRule.h @@ -354,6 +354,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + private: ~StyleRule(); diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 1530648e7104..05f416193cf6 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -57,10 +57,11 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(Rule) NS_IMPL_CYCLE_COLLECTING_RELEASE(Rule) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Rule) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END -NS_IMPL_CYCLE_COLLECTION_0(Rule) +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(Rule) /* virtual */ void Rule::SetStyleSheet(StyleSheet* aSheet) @@ -179,6 +180,7 @@ ImportRule::ImportRule(nsMediaList* aMedia, const nsString& aURLSpec, , mURLSpec(aURLSpec) , mMedia(aMedia) { + SetIsNotDOMBinding(); // XXXbz This is really silly.... the mMedia here will be replaced // with itself if we manage to load a sheet. Which should really // never fail nowadays, in sane cases. @@ -188,6 +190,7 @@ ImportRule::ImportRule(const ImportRule& aCopy) : Rule(aCopy), mURLSpec(aCopy.mURLSpec) { + SetIsNotDOMBinding(); // Whether or not an @import rule has a null sheet is a permanent // property of that @import rule, since it is null only if the target // sheet failed security checks. @@ -357,6 +360,14 @@ ImportRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const // - mChildSheet, because it is measured via CSSStyleSheetInner::mSheets } +/* virtual */ JSObject* +ImportRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + GroupRule::GroupRule(uint32_t aLineNumber, uint32_t aColumnNumber) : Rule(aLineNumber, aColumnNumber) { @@ -588,11 +599,13 @@ GroupRule::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const MediaRule::MediaRule(uint32_t aLineNumber, uint32_t aColumnNumber) : GroupRule(aLineNumber, aColumnNumber) { + SetIsNotDOMBinding(); } MediaRule::MediaRule(const MediaRule& aCopy) : GroupRule(aCopy) { + SetIsNotDOMBinding(); if (aCopy.mMedia) { mMedia = aCopy.mMedia->Clone(); // XXXldb This doesn't really make sense. @@ -803,6 +816,14 @@ MediaRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return n; } +/* virtual */ JSObject* +MediaRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + void MediaRule::AppendConditionText(nsAString& aOutput) { @@ -816,12 +837,14 @@ MediaRule::AppendConditionText(nsAString& aOutput) DocumentRule::DocumentRule(uint32_t aLineNumber, uint32_t aColumnNumber) : GroupRule(aLineNumber, aColumnNumber) { + SetIsNotDOMBinding(); } DocumentRule::DocumentRule(const DocumentRule& aCopy) : GroupRule(aCopy) , mURLs(new URL(*aCopy.mURLs)) { + SetIsNotDOMBinding(); } DocumentRule::~DocumentRule() @@ -1044,6 +1067,14 @@ DocumentRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return n; } +/* virtual */ JSObject* +DocumentRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + void DocumentRule::AppendConditionText(nsAString& aCssText) { @@ -1079,6 +1110,7 @@ NameSpaceRule::NameSpaceRule(nsIAtom* aPrefix, const nsString& aURLSpec, mPrefix(aPrefix), mURLSpec(aURLSpec) { + SetIsNotDOMBinding(); } NameSpaceRule::NameSpaceRule(const NameSpaceRule& aCopy) @@ -1086,6 +1118,7 @@ NameSpaceRule::NameSpaceRule(const NameSpaceRule& aCopy) mPrefix(aCopy.mPrefix), mURLSpec(aCopy.mURLSpec) { + SetIsNotDOMBinding(); } NameSpaceRule::~NameSpaceRule() @@ -1203,6 +1236,13 @@ NameSpaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const // - mURLSpec } +/* virtual */ JSObject* +NameSpaceRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} } // namespace css } // namespace mozilla @@ -1666,6 +1706,13 @@ nsCSSFontFaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const // - mDecl } +/* virtual */ JSObject* +nsCSSFontFaceRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} // ----------------------------------- // nsCSSFontFeatureValuesRule @@ -1905,6 +1952,14 @@ nsCSSFontFeatureValuesRule::SizeOfIncludingThis( return aMallocSizeOf(this); } +/* virtual */ JSObject* +nsCSSFontFeatureValuesRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + // ------------------------------------------- // nsCSSKeyframeStyleDeclaration // @@ -1983,6 +2038,7 @@ nsCSSKeyframeRule::nsCSSKeyframeRule(const nsCSSKeyframeRule& aCopy) , mKeys(aCopy.mKeys) , mDeclaration(new css::Declaration(*aCopy.mDeclaration)) { + SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } @@ -2192,6 +2248,13 @@ nsCSSKeyframeRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const // - mDOMDeclaration } +/* virtual */ JSObject* +nsCSSKeyframeRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} // ------------------------------------------- // nsCSSKeyframesRule @@ -2204,6 +2267,7 @@ nsCSSKeyframesRule::nsCSSKeyframesRule(const nsCSSKeyframesRule& aCopy) : GroupRule(aCopy), mName(aCopy.mName) { + SetIsNotDOMBinding(); } nsCSSKeyframesRule::~nsCSSKeyframesRule() @@ -2443,6 +2507,14 @@ nsCSSKeyframesRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return n; } +/* virtual */ JSObject* +nsCSSKeyframesRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + // ------------------------------------------- // nsCSSPageStyleDeclaration // @@ -2520,6 +2592,7 @@ nsCSSPageRule::nsCSSPageRule(const nsCSSPageRule& aCopy) : Rule(aCopy) , mDeclaration(new css::Declaration(*aCopy.mDeclaration)) { + SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } @@ -2661,6 +2734,14 @@ nsCSSPageRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return aMallocSizeOf(this); } +/* virtual */ JSObject* +nsCSSPageRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + namespace mozilla { CSSSupportsRule::CSSSupportsRule(bool aConditionMet, @@ -2670,6 +2751,7 @@ CSSSupportsRule::CSSSupportsRule(bool aConditionMet, , mUseGroup(aConditionMet) , mCondition(aCondition) { + SetIsNotDOMBinding(); } CSSSupportsRule::~CSSSupportsRule() @@ -2681,6 +2763,7 @@ CSSSupportsRule::CSSSupportsRule(const CSSSupportsRule& aCopy) mUseGroup(aCopy.mUseGroup), mCondition(aCopy.mCondition) { + SetIsNotDOMBinding(); } #ifdef DEBUG @@ -2816,6 +2899,14 @@ CSSSupportsRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return n; } +/* virtual */ JSObject* +CSSSupportsRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + } // namespace mozilla // ------------------------------------------- @@ -2827,6 +2918,7 @@ nsCSSCounterStyleRule::nsCSSCounterStyleRule(const nsCSSCounterStyleRule& aCopy) , mName(aCopy.mName) , mGeneration(aCopy.mGeneration) { + SetIsNotDOMBinding(); for (size_t i = 0; i < ArrayLength(mValues); ++i) { mValues[i] = aCopy.mValues[i]; } @@ -3275,3 +3367,11 @@ nsCSSCounterStyleRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { return aMallocSizeOf(this); } + +/* virtual */ JSObject* +nsCSSCounterStyleRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index 9dc792d8f300..e2dcfcea5eaa 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -95,6 +95,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + protected: void AppendConditionText(nsAString& aOutput); @@ -169,6 +172,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + protected: void AppendConditionText(nsAString& aOutput); @@ -235,11 +241,17 @@ class nsCSSFontFaceRule final : public mozilla::css::Rule, { public: nsCSSFontFaceRule(uint32_t aLineNumber, uint32_t aColumnNumber) - : mozilla::css::Rule(aLineNumber, aColumnNumber) {} + : mozilla::css::Rule(aLineNumber, aColumnNumber) + { + SetIsNotDOMBinding(); + } nsCSSFontFaceRule(const nsCSSFontFaceRule& aCopy) // copy everything except our reference count - : mozilla::css::Rule(aCopy), mDecl(aCopy.mDecl) {} + : mozilla::css::Rule(aCopy), mDecl(aCopy.mDecl) + { + SetIsNotDOMBinding(); + } NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(nsCSSFontFaceRule, @@ -264,6 +276,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + void GetDescriptors(mozilla::CSSFontFaceDescriptors& aDescriptors) const { aDescriptors = mDecl.mDescriptors; } @@ -300,13 +315,19 @@ class nsCSSFontFeatureValuesRule final : public mozilla::css::Rule, { public: nsCSSFontFeatureValuesRule(uint32_t aLineNumber, uint32_t aColumnNumber) - : mozilla::css::Rule(aLineNumber, aColumnNumber) {} + : mozilla::css::Rule(aLineNumber, aColumnNumber) + { + SetIsNotDOMBinding(); + } nsCSSFontFeatureValuesRule(const nsCSSFontFeatureValuesRule& aCopy) // copy everything except our reference count : mozilla::css::Rule(aCopy), mFamilyList(aCopy.mFamilyList), - mFeatureValues(aCopy.mFeatureValues) {} + mFeatureValues(aCopy.mFeatureValues) + { + SetIsNotDOMBinding(); + } NS_DECL_ISUPPORTS_INHERITED @@ -337,6 +358,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + protected: ~nsCSSFontFeatureValuesRule() {} @@ -384,6 +408,7 @@ public: , mKeys(mozilla::Move(aKeys)) , mDeclaration(mozilla::Move(aDeclaration)) { + SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } private: @@ -414,6 +439,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + void DoGetKeyText(nsAString &aKeyText) const; private: @@ -432,6 +460,7 @@ public: : mozilla::css::GroupRule(aLineNumber, aColumnNumber) , mName(aName) { + SetIsNotDOMBinding(); } private: nsCSSKeyframesRule(const nsCSSKeyframesRule& aCopy); @@ -464,6 +493,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + private: uint32_t FindRuleIndexForKey(const nsAString& aKey); @@ -507,6 +539,7 @@ public: : mozilla::css::Rule(aLineNumber, aColumnNumber) , mDeclaration(aDeclaration) { + SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } private: @@ -535,6 +568,10 @@ public: void ChangeDeclaration(mozilla::css::Declaration* aDeclaration); virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + private: RefPtr mDeclaration; // lazily created when needed: @@ -543,8 +580,8 @@ private: namespace mozilla { -class CSSSupportsRule : public css::GroupRule, - public nsIDOMCSSSupportsRule +class CSSSupportsRule final : public css::GroupRule, + public nsIDOMCSSSupportsRule { public: CSSSupportsRule(bool aConditionMet, const nsString& aCondition, @@ -580,6 +617,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + protected: virtual ~CSSSupportsRule(); @@ -599,6 +639,7 @@ public: , mName(aName) , mGeneration(0) { + SetIsNotDOMBinding(); } private: @@ -646,6 +687,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + private: typedef NS_STDCALL_FUNCPROTO(nsresult, Getter, nsCSSCounterStyleRule, GetSymbols, (nsAString&));