mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-22 23:27:30 +09:00
Bug 1378079 - Part 2: Introduce throw-on-dynamic-markup-insertion counter.
Per spec, document objects have a throw-on-dynamic-markup-insertion counter, which is used in conjunction with the create an element for the token algorithm to prevent custom element constructors from being able to use document.open(), document.close(), and document.write() when they are invoked by the parser. Tag UXP Issue #1344
This commit is contained in:
parent
efcb40fb3d
commit
a3b5d98af7
3 changed files with 54 additions and 1 deletions
|
|
@ -1329,7 +1329,8 @@ nsIDocument::nsIDocument()
|
||||||
mFrameRequestCallbacksScheduled(false),
|
mFrameRequestCallbacksScheduled(false),
|
||||||
mBidiOptions(IBMBIDI_DEFAULT_BIDI_OPTIONS),
|
mBidiOptions(IBMBIDI_DEFAULT_BIDI_OPTIONS),
|
||||||
mPartID(0),
|
mPartID(0),
|
||||||
mUserHasInteracted(false)
|
mUserHasInteracted(false),
|
||||||
|
mThrowOnDynamicMarkupInsertionCounter(0)
|
||||||
{
|
{
|
||||||
SetIsInDocument();
|
SetIsInDocument();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2879,6 +2879,22 @@ public:
|
||||||
virtual void ScheduleIntersectionObserverNotification() = 0;
|
virtual void ScheduleIntersectionObserverNotification() = 0;
|
||||||
virtual void NotifyIntersectionObservers() = 0;
|
virtual void NotifyIntersectionObservers() = 0;
|
||||||
|
|
||||||
|
bool ShouldThrowOnDynamicMarkupInsertion()
|
||||||
|
{
|
||||||
|
return mThrowOnDynamicMarkupInsertionCounter;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IncrementThrowOnDynamicMarkupInsertionCounter()
|
||||||
|
{
|
||||||
|
++mThrowOnDynamicMarkupInsertionCounter;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DecrementThrowOnDynamicMarkupInsertionCounter()
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(mThrowOnDynamicMarkupInsertionCounter);
|
||||||
|
--mThrowOnDynamicMarkupInsertionCounter;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool GetUseCounter(mozilla::UseCounter aUseCounter)
|
bool GetUseCounter(mozilla::UseCounter aUseCounter)
|
||||||
{
|
{
|
||||||
|
|
@ -3326,6 +3342,11 @@ protected:
|
||||||
|
|
||||||
uint32_t mBlockDOMContentLoaded;
|
uint32_t mBlockDOMContentLoaded;
|
||||||
|
|
||||||
|
// Used in conjunction with the create-an-element-for-the-token algorithm to
|
||||||
|
// prevent custom element constructors from being able to use document.open(),
|
||||||
|
// document.close(), and document.write() when they are invoked by the parser.
|
||||||
|
uint32_t mThrowOnDynamicMarkupInsertionCounter;
|
||||||
|
|
||||||
// Our live MediaQueryLists
|
// Our live MediaQueryLists
|
||||||
PRCList mDOMMediaQueryLists;
|
PRCList mDOMMediaQueryLists;
|
||||||
|
|
||||||
|
|
@ -3399,6 +3420,23 @@ private:
|
||||||
uint32_t mMicroTaskLevel;
|
uint32_t mMicroTaskLevel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MOZ_RAII AutoSetThrowOnDynamicMarkupInsertionCounter final {
|
||||||
|
public:
|
||||||
|
explicit AutoSetThrowOnDynamicMarkupInsertionCounter(
|
||||||
|
nsIDocument* aDocument)
|
||||||
|
: mDocument(aDocument)
|
||||||
|
{
|
||||||
|
mDocument->IncrementThrowOnDynamicMarkupInsertionCounter();
|
||||||
|
}
|
||||||
|
|
||||||
|
~AutoSetThrowOnDynamicMarkupInsertionCounter() {
|
||||||
|
mDocument->DecrementThrowOnDynamicMarkupInsertionCounter();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
nsIDocument* mDocument;
|
||||||
|
};
|
||||||
|
|
||||||
// XXX These belong somewhere else
|
// XXX These belong somewhere else
|
||||||
nsresult
|
nsresult
|
||||||
NS_NewHTMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData = false);
|
NS_NewHTMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData = false);
|
||||||
|
|
|
||||||
|
|
@ -1401,6 +1401,11 @@ nsHTMLDocument::Open(JSContext* cx,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ShouldThrowOnDynamicMarkupInsertion()) {
|
||||||
|
aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
// Set up the content type for insertion
|
// Set up the content type for insertion
|
||||||
nsAutoCString contentType;
|
nsAutoCString contentType;
|
||||||
contentType.AssignLiteral("text/html");
|
contentType.AssignLiteral("text/html");
|
||||||
|
|
@ -1608,6 +1613,11 @@ nsHTMLDocument::Close(ErrorResult& rv)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ShouldThrowOnDynamicMarkupInsertion()) {
|
||||||
|
rv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!mParser || !mParser->IsScriptCreated()) {
|
if (!mParser || !mParser->IsScriptCreated()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1683,6 +1693,10 @@ nsHTMLDocument::WriteCommon(JSContext *cx,
|
||||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ShouldThrowOnDynamicMarkupInsertion()) {
|
||||||
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
if (mParserAborted) {
|
if (mParserAborted) {
|
||||||
// Hixie says aborting the parser doesn't undefine the insertion point.
|
// Hixie says aborting the parser doesn't undefine the insertion point.
|
||||||
// However, since we null out mParser in that case, we track the
|
// However, since we null out mParser in that case, we track the
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue