1
0
mirror of https://github.com/roytam1/UXP.git synced 2026-05-26 13:58:49 +00:00

Bug 1422197 - Add fast path to get DocGroup in binding code for [CEReactions]

Tag #1375
This commit is contained in:
Matt A. Tobin
2020-04-17 07:29:57 -04:00
committed by Roy Tam
parent fc8fcfc039
commit ca09afd0b0
30 changed files with 206 additions and 44 deletions
+6
View File
@@ -453,6 +453,12 @@ nsISupports* CustomElementRegistry::GetParentObject() const
return mWindow;
}
DocGroup*
CustomElementRegistry::GetDocGroup() const
{
return mWindow ? mWindow->GetDocGroup() : nullptr;
}
static const char* kLifeCycleCallbackNames[] = {
"connectedCallback",
"disconnectedCallback",
+3
View File
@@ -27,6 +27,7 @@ struct CustomElementData;
struct ElementDefinitionOptions;
class CallbackFunction;
class CustomElementReaction;
class DocGroup;
class Function;
class Promise;
@@ -513,6 +514,8 @@ private:
public:
nsISupports* GetParentObject() const;
DocGroup* GetDocGroup() const;
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
void Define(const nsAString& aName, Function& aFunctionConstructor,
+6
View File
@@ -524,3 +524,9 @@ nsDOMAttributeMap::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return NamedNodeMapBinding::Wrap(aCx, this, aGivenProto);
}
DocGroup*
nsDOMAttributeMap::GetDocGroup() const
{
return mContent ? mContent->OwnerDoc()->GetDocGroup() : nullptr;
}
+7
View File
@@ -22,6 +22,11 @@
class nsIAtom;
class nsIDocument;
namespace mozilla {
namespace dom {
class DocGroup;
} // namespace dom
} // namespace mozilla
/**
* Structure used as a key for caching Attrs in nsDOMAttributeMap's mAttributeCache.
@@ -87,6 +92,7 @@ class nsDOMAttributeMap final : public nsIDOMMozNamedAttrMap
{
public:
typedef mozilla::dom::Attr Attr;
typedef mozilla::dom::DocGroup DocGroup;
typedef mozilla::dom::Element Element;
typedef mozilla::ErrorResult ErrorResult;
@@ -135,6 +141,7 @@ public:
return mContent;
}
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
DocGroup* GetDocGroup() const;
// WebIDL
Attr* GetNamedItem(const nsAString& aAttrName);
+6
View File
@@ -366,6 +366,12 @@ nsDOMTokenList::Stringify(nsAString& aResult)
mElement->GetAttr(kNameSpaceID_None, mAttrAtom, aResult);
}
DocGroup*
nsDOMTokenList::GetDocGroup() const
{
return mElement ? mElement->OwnerDoc()->GetDocGroup() : nullptr;
}
JSObject*
nsDOMTokenList::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
{
+6 -1
View File
@@ -22,7 +22,9 @@
namespace mozilla {
class ErrorResult;
namespace dom {
class DocGroup;
} // namespace dom
} // namespace mozilla
class nsAttrValue;
@@ -35,6 +37,7 @@ class nsDOMTokenList : public nsISupports,
{
protected:
typedef mozilla::dom::Element Element;
typedef mozilla::dom::DocGroup DocGroup;
typedef nsWhitespaceTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>
WhitespaceTokenizer;
@@ -52,6 +55,8 @@ public:
return mElement;
}
DocGroup* GetDocGroup() const;
uint32_t Length();
void Item(uint32_t aIndex, nsAString& aResult)
{
+6
View File
@@ -3132,3 +3132,9 @@ nsINode::IsStyledByServo() const
return OwnerDoc()->IsStyledByServo();
}
#endif
DocGroup*
nsINode::GetDocGroup() const
{
return OwnerDoc()->GetDocGroup();
}
+7
View File
@@ -72,6 +72,7 @@ inline bool IsSpaceCharacter(char aChar) {
class AccessibleNode;
struct BoxQuadOptions;
struct ConvertCoordinateOptions;
class DocGroup;
class DOMPoint;
class DOMQuad;
class DOMRectReadOnly;
@@ -299,6 +300,7 @@ class nsINode : public mozilla::dom::EventTarget
public:
typedef mozilla::dom::BoxQuadOptions BoxQuadOptions;
typedef mozilla::dom::ConvertCoordinateOptions ConvertCoordinateOptions;
typedef mozilla::dom::DocGroup DocGroup;
typedef mozilla::dom::DOMPoint DOMPoint;
typedef mozilla::dom::DOMPointInit DOMPointInit;
typedef mozilla::dom::DOMQuad DOMQuad;
@@ -613,6 +615,11 @@ public:
return mNodeInfo->NamespaceID() == aNamespace;
}
/**
* Returns the DocGroup of the "node document" of this node.
*/
DocGroup* GetDocGroup() const;
/**
* Print a debugger friendly descriptor of this element. This will describe
* the position of this element in the document.
+6
View File
@@ -49,6 +49,12 @@ nsRange::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
return RangeBinding::Wrap(aCx, this, aGivenProto);
}
DocGroup*
nsRange::GetDocGroup() const
{
return mOwner ? mOwner->GetDocGroup() : nullptr;
}
/******************************************************
* stack based utilty class for managing monitor
******************************************************/
+3
View File
@@ -26,6 +26,7 @@ namespace mozilla {
class ErrorResult;
namespace dom {
struct ClientRectsAndTexts;
class DocGroup;
class DocumentFragment;
class DOMRect;
class DOMRectList;
@@ -38,6 +39,7 @@ class nsRange final : public nsIDOMRange,
public nsWrapperCache
{
typedef mozilla::ErrorResult ErrorResult;
typedef mozilla::dom::DocGroup DocGroup;
typedef mozilla::dom::DOMRect DOMRect;
typedef mozilla::dom::DOMRectList DOMRectList;
@@ -280,6 +282,7 @@ public:
nsINode* GetParentObject() const { return mOwner; }
virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override final;
DocGroup* GetDocGroup() const;
private:
// no copy's or assigns
-22
View File
@@ -3406,28 +3406,6 @@ GetDesiredProto(JSContext* aCx, const JS::CallArgs& aCallArgs,
return true;
}
CustomElementReactionsStack*
GetCustomElementReactionsStack(JS::Handle<JSObject*> aObj)
{
// This might not be the right object, if there are wrappers. Unwrap if we can.
JSObject* obj = js::CheckedUnwrap(aObj);
if (!obj) {
return nullptr;
}
nsGlobalWindow* window = xpc::WindowGlobalOrNull(obj);
if (!window) {
return nullptr;
}
DocGroup* docGroup = window->AsInner()->GetDocGroup();
if (!docGroup) {
return nullptr;
}
return docGroup->CustomElementReactionsStack();
}
// https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor
already_AddRefed<nsGenericHTMLElement>
CreateHTMLElement(const GlobalObject& aGlobal, const JS::CallArgs& aCallArgs,
-6
View File
@@ -3422,12 +3422,6 @@ bool
GetDesiredProto(JSContext* aCx, const JS::CallArgs& aCallArgs,
JS::MutableHandle<JSObject*> aDesiredProto);
// Get the CustomElementReactionsStack for the docgroup of the global
// of the underlying object of aObj. This can be null if aObj can't
// be CheckUnwrapped, or if the global of the result has no docgroup
// (e.g. because it's not a Window global).
CustomElementReactionsStack*
GetCustomElementReactionsStack(JS::Handle<JSObject*> aObj);
// This function is expected to be called from the constructor function for an
// HTML element interface; the global/callargs need to be whatever was passed to
// that constructor function.
+33 -13
View File
@@ -7680,14 +7680,14 @@ class CGPerSignatureCall(CGThing):
if (idlNode.getExtendedAttribute('CEReactions') is not None and
not getter):
cgThings.append(CGGeneric(fill(
cgThings.append(CGGeneric(dedent(
"""
CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(${obj});
Maybe<AutoCEReaction> ceReaction;
if (reactionsStack) {
ceReaction.emplace(reactionsStack, cx);
Maybe<AutoCEReaction> ceReaction;
DocGroup* docGroup = self->GetDocGroup();
if (docGroup) {
ceReaction.emplace(docGroup->CustomElementReactionsStack(), cx);
}
""", obj=objectName)))
""")))
# If this is a method that was generated by a maplike/setlike
# interface, use the maplike/setlike generator to fill in the body.
@@ -13786,6 +13786,8 @@ class CGForwardDeclarations(CGWrapper):
builder.add(d.nativeType + "Atoms", isStruct=True)
for t in getTypesFromDescriptor(d):
builder.forwardDeclareForType(t, config)
if d.hasCEReactions():
builder.addInMozillaDom("DocGroup")
for d in dictionaries:
if len(d.members) > 0:
@@ -13857,18 +13859,15 @@ class CGBindingRoot(CGThing):
iface = desc.interface
return any(m.getExtendedAttribute("Deprecated") for m in iface.members + [iface])
def descriptorHasCEReactions(desc):
iface = desc.interface
return any(m.getExtendedAttribute("CEReactions") for m in iface.members + [iface])
bindingHeaders["nsIDocument.h"] = any(
descriptorDeprecated(d) for d in descriptors)
bindingHeaders["mozilla/Preferences.h"] = any(
descriptorRequiresPreferences(d) for d in descriptors)
bindingHeaders["mozilla/dom/DOMJSProxyHandler.h"] = any(
d.concrete and d.proxy for d in descriptors)
bindingHeaders["mozilla/dom/CustomElementRegistry.h"] = any(
descriptorHasCEReactions(d) for d in descriptors)
hasCEReactions = any(d.hasCEReactions() for d in descriptors)
bindingHeaders["mozilla/dom/CustomElementRegistry.h"] = hasCEReactions
bindingHeaders["mozilla/dom/DocGroup.h"] = hasCEReactions
def descriptorHasChromeOnly(desc):
ctor = desc.interface.ctor()
@@ -14704,6 +14703,12 @@ class CGBindingImplClass(CGClass):
breakAfterReturnDecl=" ",
override=descriptor.wrapperCache,
body=self.getWrapObjectBody()))
if descriptor.hasCEReactions():
self.methodDecls.insert(0,
ClassMethod("GetDocGroup", "DocGroup*", [],
const=True,
breakAfterReturnDecl=" ",
body=self.getGetDocGroupBody()))
if wantGetParent:
self.methodDecls.insert(0,
ClassMethod("GetParentObject",
@@ -14724,6 +14729,9 @@ class CGBindingImplClass(CGClass):
def getGetParentObjectBody(self):
return None
def getGetDocGroupBody(self):
return None
def deps(self):
return self._deps
@@ -14863,6 +14871,8 @@ class CGExampleRoot(CGThing):
self.root = CGNamespace.build(["mozilla", "dom"], self.root)
builder = ForwardDeclarationBuilder()
if descriptor.hasCEReactions():
builder.addInMozillaDom("DocGroup")
for member in descriptor.interface.members:
if not member.isAttr() and not member.isMethod():
continue
@@ -15174,7 +15184,7 @@ class CGJSImplClass(CGBindingImplClass):
private:
RefPtr<${jsImplName}> mImpl;
nsCOMPtr<nsISupports> mParent;
nsCOMPtr<nsIGlobalObject> mParent;
""",
isupportsDecl=isupportsDecl,
@@ -15253,6 +15263,16 @@ class CGJSImplClass(CGBindingImplClass):
def getGetParentObjectBody(self):
return "return mParent;\n"
def getGetDocGroupBody(self):
return dedent(
"""
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mParent);
if (!window) {
return nullptr;
}
return window->GetDocGroup();
""")
def getCreateFromExistingBody(self):
# XXXbz we could try to get parts of this (e.g. the argument
# conversions) auto-generated by somehow creating an IDLMethod and
+3
View File
@@ -631,6 +631,9 @@ class Descriptor(DescriptorProvider):
not self.interface.isExposedInWindow()) or
self.interface.isExposedInSomeButNotAllWorkers())
def hasCEReactions(self):
return any(m.getExtendedAttribute("CEReactions") for m in self.interface.members)
def isExposedConditionally(self):
return (self.interface.isExposedConditionally() or
self.interface.isExposedInSomeButNotAllWorkers())
+5 -2
View File
@@ -21,6 +21,7 @@
// this one for it, for ParentDict. Hopefully it won't begin to rely on it in more fundamental ways.
namespace mozilla {
namespace dom {
class DocGroup;
class TestExternalInterface;
class Promise;
} // namespace dom
@@ -46,8 +47,9 @@ public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_RENAMED_INTERFACE_IID)
NS_DECL_ISUPPORTS
// We need a GetParentObject to make binding codegen happy
// We need a GetParentObject and GetDocGroup to make binding codegen happy
virtual nsISupports* GetParentObject();
DocGroup* GetDocGroup() const;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsRenamedInterface, NS_RENAMED_INTERFACE_IID)
@@ -64,8 +66,9 @@ public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_INDIRECTLY_IMPLEMENTED_INTERFACE_IID)
NS_DECL_ISUPPORTS
// We need a GetParentObject to make binding codegen happy
// We need a GetParentObject and GetDocGroup to make binding codegen happy
virtual nsISupports* GetParentObject();
DocGroup* GetDocGroup() const;
bool IndirectlyImplementedProperty();
void IndirectlyImplementedProperty(bool);
+6
View File
@@ -239,6 +239,12 @@ HTMLOptionsCollection::GetParentObject()
return mSelect;
}
DocGroup*
HTMLOptionsCollection::GetDocGroup() const
{
return mSelect ? mSelect->GetDocGroup() : nullptr;
}
NS_IMETHODIMP
HTMLOptionsCollection::NamedItem(const nsAString& aName,
nsIDOMNode** aReturn)
+2
View File
@@ -23,6 +23,7 @@ class nsIDOMHTMLOptionElement;
namespace mozilla {
namespace dom {
class DocGroup;
class HTMLElementOrLong;
class HTMLOptionElementOrHTMLOptGroupElement;
class HTMLSelectElement;
@@ -62,6 +63,7 @@ public:
virtual Element* GetElementAt(uint32_t aIndex) override;
virtual nsINode* GetParentObject() override;
DocGroup* GetDocGroup() const;
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(HTMLOptionsCollection,
nsIHTMLCollection)
+6
View File
@@ -62,6 +62,12 @@ nsDOMStringMap::~nsDOMStringMap()
}
}
DocGroup*
nsDOMStringMap::GetDocGroup() const
{
return mElement ? mElement->GetDocGroup() : nullptr;
}
/* virtual */
JSObject*
nsDOMStringMap::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
+5
View File
@@ -16,6 +16,9 @@
namespace mozilla {
class ErrorResult;
namespace dom {
class DocGroup;
} // namespace dom
} // namespace mozilla
class nsDOMStringMap : public nsStubMutationObserver,
@@ -32,6 +35,8 @@ public:
return mElement;
}
mozilla::dom::DocGroup* GetDocGroup() const;
explicit nsDOMStringMap(mozilla::dom::Element* aElement);
// WebIDL API
+5
View File
@@ -1284,6 +1284,11 @@ txMozillaXSLTProcessor::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenP
return XSLTProcessorBinding::Wrap(aCx, this, aGivenProto);
}
DocGroup*
txMozillaXSLTProcessor::GetDocGroup() const
{
return mStylesheetDocument ? mStylesheetDocument->GetDocGroup() : nullptr;
}
/* static */ already_AddRefed<txMozillaXSLTProcessor>
txMozillaXSLTProcessor::Constructor(const GlobalObject& aGlobal,
+3
View File
@@ -29,6 +29,7 @@ class txIGlobalParameter;
namespace mozilla {
namespace dom {
class DocGroup;
class Document;
class DocumentFragment;
class GlobalObject;
@@ -103,6 +104,8 @@ public:
return mOwner;
}
mozilla::dom::DocGroup* GetDocGroup() const;
static already_AddRefed<txMozillaXSLTProcessor>
Constructor(const mozilla::dom::GlobalObject& aGlobal,
mozilla::ErrorResult& aRv);
+4
View File
@@ -31,6 +31,9 @@ class nsHTMLCopyEncoder;
namespace mozilla {
class ErrorResult;
struct AutoPrepareFocusRange;
namespace dom {
class DocGroup;
} // namespace dom
} // namespace mozilla
struct RangeData
@@ -73,6 +76,7 @@ public:
nsresult EndBatchChangesInternal(int16_t aReason = nsISelectionListener::NO_REASON);
nsIDocument* GetParentObject() const;
DocGroup* GetDocGroup() const;
// utility methods for scrolling the selection into view
nsPresContext* GetPresContext() const;
+12
View File
@@ -3521,6 +3521,18 @@ Selection::GetParentObject() const
return nullptr;
}
DocGroup*
Selection::GetDocGroup() const
{
nsIPresShell* shell = GetPresShell();
if (!shell) {
return nullptr;
}
nsIDocument* doc = shell->GetDocument();
return doc ? doc->GetDocGroup() : nullptr;
}
NS_IMPL_CYCLE_COLLECTION_CLASS(Selection)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Selection)
+10
View File
@@ -1078,6 +1078,16 @@ public:
return mRule ? mRule->GetDocument() : nullptr;
}
virtual DocGroup* GetDocGroup() const override
{
if (!mRule) {
return nullptr;
}
nsIDocument* document = mRule->GetDocument();
return document ? document->GetDocGroup() : nullptr;
}
friend class css::DOMCSSStyleRule;
protected:
+29
View File
@@ -1515,6 +1515,13 @@ nsCSSFontFaceStyleDecl::GetParentObject()
return ContainingRule()->GetDocument();
}
DocGroup*
nsCSSFontFaceStyleDecl::GetDocGroup() const
{
nsIDocument* document = ContainingRule()->GetDocument();
return document ? document->GetDocGroup() : nullptr;
}
JSObject*
nsCSSFontFaceStyleDecl::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
{
@@ -1991,6 +1998,17 @@ nsCSSKeyframeStyleDeclaration::GetParentObject()
return mRule ? mRule->GetDocument() : nullptr;
}
DocGroup*
nsCSSKeyframeStyleDeclaration::GetDocGroup() const
{
if (!mRule) {
return nullptr;
}
nsIDocument* document = mRule->GetDocument();
return document ? document->GetDocGroup() : nullptr;
}
// -------------------------------------------
// nsCSSKeyframeRule
//
@@ -2538,6 +2556,17 @@ nsCSSPageStyleDeclaration::GetParentObject()
return mRule ? mRule->GetDocument() : nullptr;
}
DocGroup*
nsCSSPageStyleDeclaration::GetDocGroup() const
{
if (!mRule) {
return nullptr;
}
nsIDocument* document = mRule->GetDocument();
return document ? document->GetDocGroup() : nullptr;
}
// -------------------------------------------
// nsCSSPageRule
//
+8
View File
@@ -39,6 +39,11 @@ class nsMediaList;
namespace mozilla {
namespace dom {
class DocGroup;
class DocGroup;
} // namespace dom
class ErrorResult;
namespace css {
@@ -209,6 +214,7 @@ public:
using nsICSSDeclaration::GetPropertyCSSValue;
virtual nsINode *GetParentObject() override;
virtual mozilla::dom::DocGroup* GetDocGroup() const override;
virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) override;
nsresult GetPropertyValue(nsCSSFontDesc aFontDescID,
@@ -366,6 +372,7 @@ public:
nsICSSDeclaration)
virtual nsINode* GetParentObject() override;
virtual mozilla::dom::DocGroup* GetDocGroup() const override;
protected:
virtual ~nsCSSKeyframeStyleDeclaration();
@@ -496,6 +503,7 @@ public:
nsICSSDeclaration)
virtual nsINode *GetParentObject() override;
virtual mozilla::dom::DocGroup* GetDocGroup() const override;
protected:
virtual ~nsCSSPageStyleDeclaration();
+6
View File
@@ -27,6 +27,7 @@
namespace mozilla {
namespace dom {
class DocGroup;
class Element;
} // namespace dom
struct ComputedGridTrackInfo;
@@ -84,6 +85,11 @@ public:
return mElement;
}
virtual mozilla::dom::DocGroup* GetDocGroup() const override
{
return mElement ? mElement->GetDocGroup() : nullptr;
}
static already_AddRefed<nsStyleContext>
GetStyleContextForElement(mozilla::dom::Element* aElement, nsIAtom* aPseudo,
nsIPresShell* aPresShell,
+6
View File
@@ -178,6 +178,12 @@ nsDOMCSSAttributeDeclaration::GetParentObject()
return mElement;
}
/* virtual */ DocGroup*
nsDOMCSSAttributeDeclaration::GetDocGroup() const
{
return mElement ? mElement->OwnerDoc()->GetDocGroup() : nullptr;
}
NS_IMETHODIMP
nsDOMCSSAttributeDeclaration::SetPropertyValue(const nsCSSPropertyID aPropID,
const nsAString& aValue)
+1
View File
@@ -35,6 +35,7 @@ public:
NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent) override;
virtual nsINode* GetParentObject() override;
virtual DocGroup* GetDocGroup() const override;
NS_IMETHOD SetPropertyValue(const nsCSSPropertyID aPropID,
const nsAString& aValue) override;
+6
View File
@@ -31,6 +31,11 @@
#include "nsCOMPtr.h"
class nsINode;
namespace mozilla {
namespace dom {
class DocGroup;
} // namespace dom
} // namespace mozilla
// dbeabbfa-6cb3-4f5c-aec2-dd558d9d681f
#define NS_ICSSDECLARATION_IID \
@@ -62,6 +67,7 @@ public:
const nsAString& aValue) = 0;
virtual nsINode *GetParentObject() = 0;
virtual mozilla::dom::DocGroup* GetDocGroup() const = 0;
// Also have to declare all the nsIDOMCSSStyleDeclaration methods,
// since we want to be able to call them from the WebIDL versions.