diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index f058bfa14b..3b5a5a1f17 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -74,7 +74,6 @@ // includes needed for the prototype chain interfaces #include "nsIDOMCSSKeyframeRule.h" #include "nsIDOMCSSKeyframesRule.h" -#include "nsIDOMCSSImportRule.h" #include "nsIDOMCSSMediaRule.h" #include "nsIDOMCSSFontFaceRule.h" #include "nsIDOMCSSMozDocumentRule.h" @@ -192,9 +191,6 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CLASSINFO_DATA(CSSStyleRule, nsCSSRuleSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSImportRule, nsCSSRuleSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CLASSINFO_DATA(CSSMediaRule, nsCSSRuleSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) @@ -525,11 +521,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSStyleRule) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSImportRule, nsIDOMCSSImportRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSImportRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSMediaRule, nsIDOMCSSMediaRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMediaRule) diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index 12ae10ffc2..90dbb32a72 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -9,7 +9,6 @@ DOMCI_CLASS(DOMConstructor) // CSS classes DOMCI_CLASS(CSSStyleRule) -DOMCI_CLASS(CSSImportRule) DOMCI_CLASS(CSSMediaRule) // XUL classes diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index ed1cfa8650..eb366e8baa 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -19,7 +19,6 @@ class TabChildGlobal; class ProcessGlobal; } // namespace dom namespace css { -class ImportRule; class StyleRule; class MediaRule; class DocumentRule; @@ -292,7 +291,6 @@ private: friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; - friend class mozilla::css::ImportRule; friend class mozilla::css::StyleRule; friend class mozilla::css::MediaRule; friend class mozilla::css::DocumentRule; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 0e16cc78d9..08387439c7 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -197,6 +197,10 @@ DOMInterfaces = { 'nativeType': 'nsDOMCSSDeclaration' }, +'CSSImportRule': { + 'nativeType': 'mozilla::css::ImportRule', +}, + 'CSSLexer': { 'wrapperCache': False }, diff --git a/dom/webidl/CSSImportRule.webidl b/dom/webidl/CSSImportRule.webidl new file mode 100644 index 0000000000..7d3f17c794 --- /dev/null +++ b/dom/webidl/CSSImportRule.webidl @@ -0,0 +1,17 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://drafts.csswg.org/cssom/#cssimportrule + */ + +// https://drafts.csswg.org/cssom/#cssimportrule +interface CSSImportRule : CSSRule { + readonly attribute DOMString href; + [SameObject, PutForwards=mediaText] readonly attribute MediaList media; + // Per spec, the .styleSheet is never null, but in our implementation it can + // be. See . + [SameObject] readonly attribute CSSStyleSheet? styleSheet; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 3f3ee0d50e..820af99089 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -90,6 +90,7 @@ WEBIDL_FILES = [ 'CSPReport.webidl', 'CSS.webidl', 'CSSAnimation.webidl', + 'CSSImportRule.webidl', 'CSSLexer.webidl', 'CSSNamespaceRule.webidl', 'CSSPrimitiveValue.webidl', diff --git a/js/xpconnect/tests/chrome/test_weakmaps.xul b/js/xpconnect/tests/chrome/test_weakmaps.xul index e741a41c6c..9301b7b5d4 100644 --- a/js/xpconnect/tests/chrome/test_weakmaps.xul +++ b/js/xpconnect/tests/chrome/test_weakmaps.xul @@ -214,28 +214,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=668855 make_live_map(); - let unpreservable_native_key = function () { - // We only allow natives that support wrapper preservation to be used as weak - // map keys. We should be able to try to add unpreservable natives as keys without - // crashing (bug 711616), but we should throw an error (bug 761620). - - let dummy_test_map = new WeakMap; - - let rule_fail = false; - let got_rule = false; - try { - var rule = document.styleSheets[0].cssRules[0]; - got_rule = true; - dummy_test_map.set(rule, 1); - } catch (e) { - rule_fail = true; - } - ok(got_rule, "Got the CSS rule"); - ok(rule_fail, "Using a CSS rule as a weak map key should produce an exception because it can't be wrapper preserved."); - - } - - unpreservable_native_key(); + // We're out of ideas for unpreservable natives, now that just about + // everything is on webidl, so just don't test those. /* set up for running precise GC/CC then checking the results */ diff --git a/layout/style/ImportRule.h b/layout/style/ImportRule.h index dd12e65b3c..077349d017 100644 --- a/layout/style/ImportRule.h +++ b/layout/style/ImportRule.h @@ -20,6 +20,7 @@ class nsString; namespace mozilla { class CSSStyleSheet; +class StyleSheet; namespace css { @@ -61,6 +62,9 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + // The XPCOM GetHref is fine, since it never fails. + nsMediaList* Media() const { return mMedia; } + StyleSheet* GetStyleSheet() const; private: nsString mURLSpec; diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 1c746c7645..a754ee48c0 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -34,6 +34,7 @@ #include "nsDOMClassInfoID.h" #include "mozilla/dom/CSSStyleDeclarationBinding.h" #include "mozilla/dom/CSSNamespaceRuleBinding.h" +#include "mozilla/dom/CSSImportRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -242,7 +243,7 @@ ImportRule::ImportRule(nsMediaList* aMedia, const nsString& aURLSpec, , mURLSpec(aURLSpec) , mMedia(aMedia) { - SetIsNotDOMBinding(); + MOZ_ASSERT(aMedia); // 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. @@ -252,7 +253,6 @@ 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. @@ -284,7 +284,6 @@ ImportRule::IsCCLeaf() const // QueryInterface implementation for ImportRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ImportRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSImportRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSImportRule) NS_INTERFACE_MAP_END_INHERITING(Rule) NS_IMPL_CYCLE_COLLECTION_CLASS(ImportRule) @@ -373,6 +372,12 @@ ImportRule::GetCssTextImpl(nsAString& aCssText) const aCssText.Append(';'); } +StyleSheet* +ImportRule::GetStyleSheet() const +{ + return mChildSheet; +} + NS_IMETHODIMP ImportRule::GetHref(nsAString & aHref) { @@ -385,7 +390,7 @@ ImportRule::GetMedia(nsIDOMMediaList * *aMedia) { NS_ENSURE_ARG_POINTER(aMedia); - NS_IF_ADDREF(*aMedia = mMedia); + NS_ADDREF(*aMedia = mMedia); return NS_OK; } @@ -416,8 +421,7 @@ ImportRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const ImportRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSImportRuleBinding::Wrap(aCx, this, aGivenProto); } GroupRule::GroupRule(uint32_t aLineNumber, uint32_t aColumnNumber)