Skip to content

Commit 5263610

Browse files
authored
Update DOMParser type (#839)
1 parent 74a8f80 commit 5263610

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

baselines/dom.generated.d.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3923,7 +3923,16 @@ declare var DOMMatrixReadOnly: {
39233923

39243924
/** Provides the ability to parse XML or HTML source code from a string into a DOM Document. */
39253925
interface DOMParser {
3926-
parseFromString(str: string, type: SupportedType): Document;
3926+
/**
3927+
* Parses string using either the HTML or XML parser, according to type, and returns the resulting Document. type can be "text/html" (which will invoke the HTML parser), or any of "text/xml", "application/xml", "application/xhtml+xml", or "image/svg+xml" (which will invoke the XML parser).
3928+
*
3929+
* For the XML parser, if string can be parsed, then the returned Document will contain elements describing the resulting error.
3930+
*
3931+
* Note that script elements are not evaluated during parsing, and the resulting document's encoding will always be UTF-8.
3932+
*
3933+
* Values other than the above for type will cause a TypeError exception to be thrown.
3934+
*/
3935+
parseFromString(string: string, type: DOMParserSupportedType): Document;
39273936
}
39283937

39293938
declare var DOMParser: {
@@ -19922,6 +19931,7 @@ type ColorSpaceConversion = "default" | "none";
1992219931
type CompositeOperation = "accumulate" | "add" | "replace";
1992319932
type CompositeOperationOrAuto = "accumulate" | "add" | "auto" | "replace";
1992419933
type CredentialMediationRequirement = "optional" | "required" | "silent";
19934+
type DOMParserSupportedType = "application/xhtml+xml" | "application/xml" | "image/svg+xml" | "text/html" | "text/xml";
1992519935
type DirectionSetting = "" | "lr" | "rl";
1992619936
type DisplayCaptureSurfaceType = "application" | "browser" | "monitor" | "window";
1992719937
type DistanceModelType = "exponential" | "inverse" | "linear";
@@ -20022,7 +20032,6 @@ type ServiceWorkerState = "activated" | "activating" | "installed" | "installing
2002220032
type ServiceWorkerUpdateViaCache = "all" | "imports" | "none";
2002320033
type ShadowRootMode = "closed" | "open";
2002420034
type SpeechSynthesisErrorCode = "audio-busy" | "audio-hardware" | "canceled" | "interrupted" | "invalid-argument" | "language-unavailable" | "network" | "not-allowed" | "synthesis-failed" | "synthesis-unavailable" | "text-too-long" | "voice-unavailable";
20025-
type SupportedType = "application/xhtml+xml" | "application/xml" | "image/svg+xml" | "text/html" | "text/xml";
2002620035
type TextTrackKind = "captions" | "chapters" | "descriptions" | "metadata" | "subtitles";
2002720036
type TextTrackMode = "disabled" | "hidden" | "showing";
2002820037
type TouchType = "direct" | "stylus";

inputfiles/idl/DOM Parsing and Serialization.widl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
[Exposed=Window]
2-
interface DOMParser {
3-
constructor();
4-
[NewObject] Document parseFromString(DOMString str, SupportedType type);
5-
};
6-
7-
enum SupportedType {
8-
"text/html",
9-
"text/xml",
10-
"application/xml",
11-
"application/xhtml+xml",
12-
"image/svg+xml"
13-
};
14-
151
[Exposed=Window]
162
interface XMLSerializer {
173
constructor();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"document-open": "Causes the Document to be replaced in-place, as if it was a new Document object, but reusing the previous object, which is then returned.\n\nThe resulting Document has an HTML parser associated with it, which can be given data to parse using document.write().\n\nThe method has no effect if the Document is still being parsed.\n\nThrows an \"InvalidStateError\" DOMException if the Document is an XML document.\n\nThrows an \"InvalidStateError\" DOMException if the parser is currently executing a custom element constructor.",
3+
"document-close": "Closes the input stream that was opened by the document.open() method.\n\nThrows an \"InvalidStateError\" DOMException if the Document is an XML document.\n\nThrows an \"InvalidStateError\" DOMException if the parser is currently executing a custom element constructor.",
4+
"document-write": "In general, adds the given string(s) to the Document's input stream.\n\nThis method has very idiosyncratic behavior. In some cases, this method can affect the state of the HTML parser while the parser is running, resulting in a DOM that does not correspond to the source of the document (e.g. if the string written is the string \"<plaintext>\" or \"<!--\"). In other cases, the call can clear the current page first, as if document.open() had been called. In yet more cases, the method is simply ignored, or throws an exception. Users agents are explicitly allowed to avoid executing script elements inserted via this method. And to make matters even worse, the exact behavior of this method can in some cases be dependent on network latency, which can lead to failures that are very hard to debug. For all these reasons, use of this method is strongly discouraged.\n\nThrows an \"InvalidStateError\" DOMException when invoked on XML documents.\n\nThrows an \"InvalidStateError\" DOMException if the parser is currently executing a custom element constructor.",
5+
"document-writeln": "Adds the given string(s) to the Document's input stream, followed by a newline character. If necessary, calls the open() method implicitly first.\n\nThrows an \"InvalidStateError\" DOMException when invoked on XML documents.\n\nThrows an \"InvalidStateError\" DOMException if the parser is currently executing a custom element constructor.",
6+
"domparser-constructor": "Constructs a new DOMParser object.",
7+
"domparser-parsefromstring": "Parses string using either the HTML or XML parser, according to type, and returns the resulting Document. type can be \"text/html\" (which will invoke the HTML parser), or any of \"text/xml\", \"application/xml\", \"application/xhtml+xml\", or \"image/svg+xml\" (which will invoke the XML parser).\n\nFor the XML parser, if string can be parsed, then the returned Document will contain elements describing the resulting error.\n\nNote that script elements are not evaluated during parsing, and the resulting document's encoding will always be UTF-8.\n\nValues other than the above for type will cause a TypeError exception to be thrown."
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Exposed=Window]
2+
interface DOMParser {
3+
constructor();
4+
5+
[NewObject] Document parseFromString(DOMString string, DOMParserSupportedType type);
6+
};
7+
8+
enum DOMParserSupportedType {
9+
"text/html",
10+
"text/xml",
11+
"application/xml",
12+
"application/xhtml+xml",
13+
"image/svg+xml"
14+
};

inputfiles/idlSources.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@
260260
"url": "https://html.spec.whatwg.org/multipage/dnd.html",
261261
"title": "HTML - Drag and drop"
262262
},
263+
{
264+
"url": "https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html",
265+
"title": "HTML - Dynamic markup insertion"
266+
},
263267
{
264268
"url": "https://html.spec.whatwg.org/multipage/edits.html",
265269
"title": "HTML - Edits"

0 commit comments

Comments
 (0)