diff --git a/dom/base/CustomElementRegistry.h b/dom/base/CustomElementRegistry.h index ff181d488544b..72174be12be0a 100644 --- a/dom/base/CustomElementRegistry.h +++ b/dom/base/CustomElementRegistry.h @@ -480,15 +480,24 @@ class CustomElementRegistry final : public nsISupports, class MOZ_RAII AutoCEReaction final { public: - explicit AutoCEReaction(CustomElementReactionsStack* aReactionsStack) - : mReactionsStack(aReactionsStack) { + // JSContext is allowed to be a nullptr if we are guaranteeing that we're + // not doing something that might throw but not finish reporting a JS + // exception during the lifetime of the AutoCEReaction. + AutoCEReaction(CustomElementReactionsStack* aReactionsStack, JSContext* aCx) + : mReactionsStack(aReactionsStack) + , mCx(aCx) { mReactionsStack->CreateAndPushElementQueue(); } ~AutoCEReaction() { + Maybe ases; + if (mCx) { + ases.emplace(mCx); + } mReactionsStack->PopAndInvokeElementQueue(); } private: RefPtr mReactionsStack; + JSContext* mCx; }; } // namespace dom diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index dc6c918c3073f..bb14e4a3ebf81 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -6510,7 +6510,8 @@ nsDocument::RegisterElement(JSContext* aCx, const nsAString& aType, return; } - AutoCEReaction ceReaction(this->GetDocGroup()->CustomElementReactionsStack()); + AutoCEReaction ceReaction(this->GetDocGroup()->CustomElementReactionsStack(), + aCx); // Unconditionally convert TYPE to lowercase. nsAutoString lcType; nsContentUtils::ASCIIToLower(aType, lcType); diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 8ed0203c10e84..b2330c179d7f1 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -7865,7 +7865,7 @@ def __init__(self, returnType, arguments, nativeMethodName, static, if (CustomElementRegistry::IsCustomElementEnabled()) { CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(${obj}); if (reactionsStack) { - ceReaction.emplace(reactionsStack); + ceReaction.emplace(reactionsStack, cx); } } """, obj=objectName))) diff --git a/parser/html/nsHtml5TreeOperation.cpp b/parser/html/nsHtml5TreeOperation.cpp index a01576d5e38a5..70cb78eb12f7d 100644 --- a/parser/html/nsHtml5TreeOperation.cpp +++ b/parser/html/nsHtml5TreeOperation.cpp @@ -428,7 +428,8 @@ nsHtml5TreeOperation::CreateHTMLElement( nsAutoMicroTask mt; } dom::AutoCEReaction - autoCEReaction(document->GetDocGroup()->CustomElementReactionsStack()); + autoCEReaction(document->GetDocGroup()->CustomElementReactionsStack(), + nullptr); nsCOMPtr newElement; NS_NewHTMLElement(getter_AddRefs(newElement), nodeInfo.forget(), diff --git a/testing/web-platform/meta/MANIFEST.json b/testing/web-platform/meta/MANIFEST.json index 4a85c60992447..41c7c60e66b75 100644 --- a/testing/web-platform/meta/MANIFEST.json +++ b/testing/web-platform/meta/MANIFEST.json @@ -312868,6 +312868,12 @@ {} ] ], + "custom-elements/reactions/with-exceptions.html": [ + [ + "/custom-elements/reactions/with-exceptions.html", + {} + ] + ], "custom-elements/upgrading.html": [ [ "/custom-elements/upgrading.html", @@ -533823,6 +533829,10 @@ "e966b6c608ee9b4183e040b8be7adb2b73722c7b", "support" ], + "custom-elements/reactions/with-exceptions.html": [ + "b72ee82a3d98c61683e62c4834f54269898e12d5", + "testharness" + ], "custom-elements/resources/custom-elements-helpers.js": [ "accaee861d319e0caf00356521479dc5951ac162", "support" diff --git a/testing/web-platform/tests/custom-elements/reactions/with-exceptions.html b/testing/web-platform/tests/custom-elements/reactions/with-exceptions.html new file mode 100644 index 0000000000000..82e0f59c93022 --- /dev/null +++ b/testing/web-platform/tests/custom-elements/reactions/with-exceptions.html @@ -0,0 +1,31 @@ + + +Custom Elements: CEReactions interaction with exceptions + + + + + + + + +
+ +