diff --git a/encoding.bs b/encoding.bs index a91e225..fe2d136 100644 --- a/encoding.bs +++ b/encoding.bs @@ -1333,6 +1333,10 @@ dictionary TextDecoderOptions { boolean ignoreBOM = false; }; +dictionary TextDecoderOptionsWithLabel : TextDecoderOptions { + DOMString label = "utf-8"; +}; + dictionary TextDecodeOptions { boolean stream = false; }; @@ -1341,6 +1345,8 @@ dictionary TextDecodeOptions { interface TextDecoder { constructor(optional DOMString label = "utf-8", optional TextDecoderOptions options = {}); + static USVString decode(optional [AllowShared] BufferSource input, optional TextDecoderOptionsWithLabel options = {}); + USVString decode(optional [AllowShared] BufferSource input, optional TextDecodeOptions options = {}); }; TextDecoder includes TextDecoderCommon; @@ -1351,13 +1357,17 @@ TextDecoder includes TextDecoderCommon; initially false.
Returns the result of running encoding's decoder. +
If options["{{TextDecoderOptionsWithLabel/label}}"] is either not a label or + is a label for replacement, throws a {{RangeError}}. +
decoder = new TextDecoder([label = "utf-8" [, options]])
Returns a new {{TextDecoder}} object. -
If label is either not a label or is a - label for replacement, - throws a - {{RangeError}}. +
If label is either not a label or is a label for replacement, + throws a {{RangeError}}.
decoder . encoding
Returns encoding's name, lowercased. @@ -1389,40 +1399,41 @@ string += decoder.decode(); // end-of-queue throws a {{TypeError}}.
The
-new TextDecoder(label, options)
-constructor steps are:
+
To initialize a {{TextDecoder}} decoder, +DOMString label, an optional fatal flag, and an optional +ignoreBOM flag, run these steps:
Let encoding be the result of getting an encoding from label.
If encoding is failure or replacement, then throw a {{RangeError}}. -
If options["{{TextDecoderOptions/fatal}}"] is true, then set this's +
If fatal is set, then set decoder's
error mode to "fatal
".
-
Set this's ignore BOM to - options["{{TextDecoderOptions/ignoreBOM}}"]. +
Set decoder's ignore BOM to
+ true
if ignoreBOM if is set, false
otherwise.
The decode(input, options)
-method steps are:
+
To decode an input, given a {{TextDecoder}} decoderObject, a +BufferSource input, and an optional stream flag, run these steps:
If this's do not flush is false, then set this's - decoder to a new instance of this's - encoding's decoder, this's - I/O queue to the I/O queue of bytes - « end-of-queue », and this's BOM seen to false. +
If decoderObject's do not flush is false, then set + decoderObject's decoder to a new instance of + decoderObject's encoding's decoder, + decoderObject's I/O queue to the I/O queue of + bytes « end-of-queue », and decoderObject's BOM seen + to false. -
Set this's do not flush to - options["{{TextDecodeOptions/stream}}"]. +
Set decoderObject's do not flush to true
if
+ stream if is set, false
otherwise.
If input is given, then push a - copy of input to this's + copy of input to decoder's I/O queue.
Implementations are strongly encouraged to use an implementation strategy that @@ -1441,36 +1452,72 @@ method steps are:
While true:
Let item be the result of reading from decoderObject's I/O queue.
If item is end-of-queue and this's +
If item is end-of-queue and decoderObject's do not flush is true, then return the result of running - serialize I/O queue with this and output. + serialize I/O queue with decoderObject and output.
The way streaming works is to not handle end-of-queue here when - this's do not flush is true and to not set it to false. That way - in a subsequent invocation this's decoder is not set anew in - the first step of the algorithm and its state is preserved. + decoderObject's do not flush is true and to not set it to + false. That way in a subsequent invocation decoderObject's + decoder is not set anew in the first step of the algorithm and its + state is preserved.
Otherwise:
Let result be the result of processing an item with item, - this's decoder, this's - I/O queue, output, and this's + decoderObject's decoder, decoderObject's + I/O queue, output, and decoderObject's error mode.
If result is finished, then return the result of running - serialize I/O queue with this and output. + serialize I/O queue with decoderObject and output.
The
+new TextDecoder(label, options)
+constructor steps are:
+
+
Run the initialize a TextDecoder steps on this with label, the
+ fatal flag set if options["{{TextDecoderOptions/fatal}}"] is true
, and the
+ ignoreBOM flag set if options["{{TextDecoderOptions/ignoreBOM}}"] is true
.
+
The static
+decode(input, options)
method
+steps are:
+
+
Let decoderObject be a new TextDecoder object. + +
Run the initialize a TextDecoder steps on decoderObject with
+ options["{{TextDecoderOptionsWithLabel/label}}"], the fatal flag set if
+ options["{{TextDecoderOptions/fatal}}"] is true
, and the ignoreBOM flag set
+ if options["{{TextDecoderOptions/ignoreBOM}}"] is true
.
+
+
Return the result of running the decode an input steps with decoderObject, + input. +
The decode(input, options)
+method steps are:
+
+
Return the result of running the decode an input steps with this,
+ input, and the stream
flag set if
+ options["{{TextDecoderOptions/stream}}"] is true
.
+
@@ -1498,6 +1545,9 @@ dictionary TextEncoderEncodeIntoResult { interface TextEncoder { constructor(); + [NewObject] static Uint8Array encode(optional USVString input = ""); + static TextEncoderEncodeIntoResult encodeInto(USVString source, [AllowShared] Uint8Array destination); + [NewObject] Uint8Array encode(optional USVString input = ""); TextEncoderEncodeIntoResult encodeInto(USVString source, [AllowShared] Uint8Array destination); }; @@ -1511,6 +1561,16 @@ requires buffering of scalar values.
Runs the UTF-8 encoder on source, stores the result of that operation into + destination, and returns the progress made as an object wherein + {{TextEncoderEncodeIntoResult/read}} is the number of converted code units of + source and {{TextEncoderEncodeIntoResult/written}} is the number of bytes modified in + destination. +
encoder = new TextEncoder()
Returns a new {{TextEncoder}} object. @@ -1528,11 +1588,7 @@ requires buffering of scalar values. destination.
The
-new TextEncoder()
-constructor steps are to do nothing.
-
-
The encode(input)
method steps are:
+
To encode an input given a USVString input, run the following steps:
-The
-encodeInto(source, destination)
-method steps are:
+
To encode a source into a destination given a USVString source, and a +BufferSource destination, run the following steps:
Let read be 0. @@ -1627,6 +1682,41 @@ method steps are: "{{TextEncoderEncodeIntoResult/written}}" → written ]».
The
+new TextEncoder()
+constructor steps are to do nothing.
+
+
The static encode(input)
method steps
+are:
+
+
Return the result of running the encode an input steps with input. +
The encode(input)
method steps are:
+
+
Return the result of running the encode an input steps with input. +
The static
+encodeInto(source, destination)
+method steps are:
+
+
Return the result of running the encode a source into a destination steps with + source and destination. +
The
+encodeInto(source, destination)
+method steps are:
+
+
Return the result of running the encode a source into a destination steps with + source and destination. +
The encodeInto() method can be used to encode a string into an existing {{ArrayBuffer}} object. Various details below are left