DOMParser.parseFromString on strings without a doctype produces a never-shown console warning (and wastes time doing so)
Categories
(Core :: DOM: HTML Parser, defect, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox117 | --- | fixed |
People
(Reporter: mstange, Assigned: smaug)
References
(Blocks 1 open bug)
Details
(Whiteboard: [sp3])
Attachments
(1 file)
We can improve the speedometer3 subtest "TodoMVC-JavaScript-ES5" by 6.7% if we don't report a warning for a missing doctype during DOMParser parsing.
This subtest has recently switched to using DOMParser.parseFromString
, and the string we feed into it is not a full document, it's just a fragment that was formerly passed to the innerHTML
setter. Thus it does not contain a doctype.
You can run the test here: https://shell--speedometer-preview.netlify.app/?suite=TodoMVC-JavaScript-ES5#home
When running the test, I do not see any warnings in the web console. However, the profiler shows time spent reporting a console warning:
https://share.firefox.dev/3DevefZ 1893 samples in nsHtml5DocumentBuilder::SetDocumentMode
https://share.firefox.dev/3XU7NSA 2024 samples in LogMessageRunnable::Run
Together this makes up 6.7% of the sample count on this subtest.
Can we skip the warning during DOMParser.parseFromString
parsing?
Updated•2 years ago
|
Reporter | ||
Comment 1•2 years ago
|
||
void nsHtml5DocumentBuilder::SetDocumentMode(nsHtml5DocumentMode m) {
nsCompatibility mode = eCompatibility_NavQuirks;
const char* errMsgId = nullptr;
switch (m) {
case STANDARDS_MODE:
mode = eCompatibility_FullStandards;
break;
case ALMOST_STANDARDS_MODE:
mode = eCompatibility_AlmostStandards;
errMsgId = "errAlmostStandardsDoctypeVerbose";
break;
case QUIRKS_MODE:
mode = eCompatibility_NavQuirks;
errMsgId = "errQuirkyDoctypeVerbose";
break;
}
mDocument->SetCompatibilityMode(mode);
if (errMsgId) {
nsCOMPtr<nsIURI> docURI = mDocument->GetDocumentURI();
bool isData = false;
docURI->SchemeIs("data", &isData);
bool isHttp = false;
docURI->SchemeIs("http", &isHttp);
bool isHttps = false;
docURI->SchemeIs("https", &isHttps);
nsCOMPtr<nsIPrincipal> principal = mDocument->GetPrincipal();
if (principal->GetIsNullPrincipal() && !isData && !isHttp && !isHttps) {
// Don't normally warn for null principals. It may well be internal
// documents for which the warning is not applicable.
return;
}
nsContentUtils::ReportToConsole(
nsIScriptError::warningFlag, "HTML_PARSER__DOCTYPE"_ns, mDocument,
nsContentUtils::eHTMLPARSER_PROPERTIES, errMsgId);
}
}
Assignee | ||
Comment 2•2 years ago
|
||
I think we should just change https://searchfox.org/mozilla-central/rev/7a4c08f2c3a895c9dc064734ada320f920250c1f/parser/html/nsHtml5DocumentBuilder.cpp#93 to
if (errMsgId && !mDocument->IsLoadedAsData())
Assignee | ||
Updated•2 years ago
|
Assignee | ||
Comment 3•2 years ago
|
||
Updated•2 years ago
|
Comment 5•2 years ago
|
||
bugherder |
Description
•