@@ -1333,6 +1333,10 @@ dictionary TextDecoderOptions {
1333
1333
boolean ignoreBOM = false;
1334
1334
};
1335
1335
1336
+ dictionary TextDecoderOptionsWithLabel : TextDecoderOptions {
1337
+ DOMString label = "utf-8";
1338
+ };
1339
+
1336
1340
dictionary TextDecodeOptions {
1337
1341
boolean stream = false;
1338
1342
};
@@ -1341,6 +1345,8 @@ dictionary TextDecodeOptions {
1341
1345
interface TextDecoder {
1342
1346
constructor(optional DOMString label = "utf-8", optional TextDecoderOptions options = {});
1343
1347
1348
+ static USVString decode(optional [AllowShared] BufferSource input, optional TextDecoderOptionsWithLabel options = {});
1349
+
1344
1350
USVString decode(optional [AllowShared] BufferSource input, optional TextDecodeOptions options = {});
1345
1351
};
1346
1352
TextDecoder includes TextDecoderCommon;
@@ -1351,13 +1357,17 @@ TextDecoder includes TextDecoderCommon;
1351
1357
initially false.
1352
1358
1353
1359
<dl class=domintro>
1360
+ <dt> {{TextDecoder}} . <a method for=TextDecoder lt=decode()>decode([<var>input</var> [, <var>options</var>]])</a> </code>
1361
+ <dd>
1362
+ <p> Returns the result of running <a for=TextDecoderCommon>encoding</a> 's <a for=/>decoder</a> .
1363
+ <p> If <var> options</var> ["{{TextDecoderOptionsWithLabel/label}}"] is either not a <a>label</a> or
1364
+ is a <a>label</a> for <a>replacement</a> , <a>throws</a> a {{RangeError}} .
1365
+
1354
1366
<dt><code><var> decoder</var> = new <a constructor for=TextDecoder lt=TextDecoder()>TextDecoder([<var>label</var> = "utf-8" [, <var>options</var>]])</a> </code>
1355
1367
<dd>
1356
1368
<p> Returns a new {{TextDecoder}} object.
1357
- <p> If <var> label</var> is either not a <a>label</a> or is a
1358
- <a>label</a> for <a>replacement</a> ,
1359
- <a>throws</a> a
1360
- {{RangeError}} .
1369
+ <p> If <var> label</var> is either not a <a>label</a> or is a <a>label</a> for <a>replacement</a> ,
1370
+ <a>throws</a> a {{RangeError}} .
1361
1371
1362
1372
<dt><code><var> decoder</var> . <a attribute for=TextDecoderCommon>encoding</a> </code>
1363
1373
<dd><p> Returns <a for=TextDecoderCommon>encoding</a> 's <a>name</a> , lowercased.
@@ -1389,40 +1399,41 @@ string += decoder.decode(); // end-of-queue</code></pre>
1389
1399
<a>throws</a> a {{TypeError}} .
1390
1400
</dl>
1391
1401
1392
- <p> The
1393
- <dfn constructor for=TextDecoder lt="TextDecoder(label, options)" id=dom-textdecoder><code>new TextDecoder( <var>label</var>, <var>options </var>)</code></dfn>
1394
- constructor steps are :
1402
+ <p> To <dfn>initialize</dfn> a {{TextDecoder}} <var> decoder </var> ,
1403
+ <a>DOMString</a> <var> label</var> , an optional <var> fatal </var> flag, and an optional
1404
+ <var> ignoreBOM </var> flag, run these steps :
1395
1405
1396
1406
<ol>
1397
1407
<li><p> Let <var> encoding</var> be the result of <a>getting an encoding</a> from <var> label</var> .
1398
1408
1399
1409
<li><p> If <var> encoding</var> is failure or <a>replacement</a> , then <a>throw</a> a {{RangeError}} .
1400
1410
1401
- <li><p> Set <a>this </a> 's <a for=TextDecoderCommon>encoding</a> to <var> encoding</var> .
1411
+ <li><p> Set <a>decoder </a> 's <a for=TextDecoderCommon>encoding</a> to <var> encoding</var> .
1402
1412
1403
- <li><p> If <var> options </var> ["{{TextDecoderOptions/fatal}}"] is true , then set <a>this </a> 's
1413
+ <li><p> If <var> fatal </var> is set , then set <a>decoder </a> 's
1404
1414
<a for=TextDecoderCommon>error mode</a> to "<code> fatal</code> ".
1405
1415
1406
- <li><p> Set <a>this </a> 's <a for=TextDecoderCommon>ignore BOM</a> to
1407
- <var> options </var> ["{{TextDecoderOptions/ignoreBOM}}"] .
1416
+ <li><p> Set <a>decoder </a> 's <a for=TextDecoderCommon>ignore BOM</a> to
1417
+ <code> true </code> if < var>ignoreBOM </var> if is set, <code> false </code> otherwise .
1408
1418
</ol>
1409
1419
1410
- <p> The <dfn method for=TextDecoder><code> decode(<var> input</var >, <var>options </var>)</code></dfn>
1411
- method steps are :
1420
+ <p> To <dfn> decode an input</dfn > , given a {{TextDecoder}} <var> decoderObject </var> , a
1421
+ <a>BufferSource</a> <var> input </var> , and an optional <var> stream </var> flag, run these steps :
1412
1422
1413
1423
<ol>
1414
- <li><p> If <a>this</a> 's <a for=TextDecoder>do not flush</a> is false, then set <a>this</a>' s
1415
- <a for=TextDecoderCommon>decoder</a> to a new instance of <a>this</a> 's
1416
- <a for=TextDecoderCommon>encoding</a> 's <a for=/>decoder</a>, <a>this</a>' s
1417
- <a for=TextDecoderCommon>I/O queue</a> to the <a for=/>I/O queue</a> of bytes
1418
- « <a>end-of-queue</a> », and <a>this</a> 's <a for=TextDecoderCommon>BOM seen</a> to false.
1424
+ <li><p> If <var> decoderObject</var> 's <a for=TextDecoder>do not flush</a> is false, then set
1425
+ <var> decoderObject</var> 's <a for=TextDecoderCommon>decoder</a> to a new instance of
1426
+ <var> decoderObject</var> 's <a for=TextDecoderCommon>encoding</a>' s <a for=/>decoder</a> ,
1427
+ <var> decoderObject</var> 's <a for=TextDecoderCommon>I/O queue</a> to the <a for=/>I/O queue</a> of
1428
+ bytes « <a>end-of-queue</a> », and <var> decoderObject</var> 's <a for=TextDecoderCommon>BOM seen</a>
1429
+ to false.
1419
1430
1420
- <li><p> Set <a>this</a > 's <a for=TextDecoder>do not flush</a> to
1421
- <var> options </var> ["{{TextDecodeOptions/stream}}"] .
1431
+ <li><p> Set <var> decoderObject </var > 's <a for=TextDecoder>do not flush</a> to <code> true </code> if
1432
+ <var> stream </var> if is set, <code> false </code> otherwise .
1422
1433
1423
1434
<li>
1424
1435
<p> If <var> input</var> is given, then <a>push</a> a
1425
- <a lt="get a copy of the buffer source">copy of</a> <var> input</var> to <a>this </a> 's
1436
+ <a lt="get a copy of the buffer source">copy of</a> <var> input</var> to <a>decoder </a> 's
1426
1437
<a for=TextDecoderCommon>I/O queue</a> .
1427
1438
1428
1439
<p class=note> Implementations are strongly encouraged to use an implementation strategy that
@@ -1441,36 +1452,72 @@ method steps are:
1441
1452
<p> While true:
1442
1453
1443
1454
<ol>
1444
- <li><p> Let <var> item</var> be the result of <a>reading</a> from <a>this</a > 's
1455
+ <li><p> Let <var> item</var> be the result of <a>reading</a> from <var> decoderObject </var > 's
1445
1456
<a for=TextDecoderCommon>I/O queue</a> .
1446
1457
1447
1458
<li>
1448
- <p> If <var> item</var> is <a>end-of-queue</a> and <a>this</a > 's
1459
+ <p> If <var> item</var> is <a>end-of-queue</a> and <var> decoderObject </var > 's
1449
1460
<a for=TextDecoder>do not flush</a> is true, then return the result of running
1450
- <a>serialize I/O queue</a> with <a>this</a > and <var> output</var> .
1461
+ <a>serialize I/O queue</a> with <var> decoderObject </var > and <var> output</var> .
1451
1462
1452
1463
<p class=note> The way streaming works is to not handle <a>end-of-queue</a> here when
1453
- <a>this</a> 's <a for=TextDecoder>do not flush</a> is true and to not set it to false. That way
1454
- in a subsequent invocation <a>this</a> 's <a for=TextDecoderCommon>decoder</a> is not set anew in
1455
- the first step of the algorithm and its state is preserved.
1464
+ <var> decoderObject</var> 's <a for=TextDecoder>do not flush</a> is true and to not set it to
1465
+ false. That way in a subsequent invocation <var> decoderObject</var> 's
1466
+ <a for=TextDecoderCommon>decoder</a> is not set anew in the first step of the algorithm and its
1467
+ state is preserved.
1456
1468
1457
1469
<li>
1458
1470
<p> Otherwise:
1459
1471
1460
1472
<ol>
1461
1473
<li><p> Let <var> result</var> be the result of <a>processing an item</a> with <var> item</var> ,
1462
- <a>this</a > 's <a for=TextDecoderCommon>decoder</a>, <a>this</a >' s
1463
- <a for=TextDecoderCommon>I/O queue</a> , <var> output</var> , and <a>this</a > 's
1474
+ <var> decoderObject </var >'s <a for=TextDecoderCommon>decoder</a>, <var>decoderObject</var >' s
1475
+ <a for=TextDecoderCommon>I/O queue</a> , <var> output</var> , and <var> decoderObject </var > 's
1464
1476
<a for=TextDecoderCommon>error mode</a> .
1465
1477
1466
1478
<li><p> If <var> result</var> is <a>finished</a> , then return the result of running
1467
- <a>serialize I/O queue</a> with <a>this</a > and <var> output</var> .
1479
+ <a>serialize I/O queue</a> with <var> decoderObject </var > and <var> output</var> .
1468
1480
1469
1481
<li><p> Otherwise, if <var> result</var> is <a>error</a> , <a>throw</a> a {{TypeError}} .
1470
1482
</ol>
1471
1483
</ol>
1472
1484
</ol>
1473
1485
1486
+ <p> The
1487
+ <dfn constructor for=TextDecoder lt="TextDecoder(label, options)" id=dom-textdecoder><code>new TextDecoder(<var>label</var>, <var>options</var>)</code></dfn>
1488
+ constructor steps are:
1489
+
1490
+ <ol>
1491
+ <li><p> Run the <a>initialize a TextDecoder</a> steps on <a>this</a> with <var> label</var> , the
1492
+ fatal flag set if <var> options</var> ["{{TextDecoderOptions/fatal}}"] is <code> true</code> , and the
1493
+ ignoreBOM flag set if <var> options</var> ["{{TextDecoderOptions/ignoreBOM}}"] is <code> true</code> .
1494
+ </ol>
1495
+
1496
+ <p> The static
1497
+ <dfn method for=TextDecoder><code>decode(<var>input</var>, <var>options</var>)</code></dfn> method
1498
+ steps are:
1499
+
1500
+ <ol>
1501
+ <li><p> Let <var> decoderObject</var> be a new <a>TextDecoder</a> object.
1502
+
1503
+ <li><p> Run the <a>initialize a TextDecoder</a> steps on <var> decoderObject</var> with
1504
+ <var> options</var> ["{{TextDecoderOptionsWithLabel/label}}"] , the fatal flag set if
1505
+ <var> options</var> ["{{TextDecoderOptions/fatal}}"] is <code> true</code> , and the ignoreBOM flag set
1506
+ if <var> options</var> ["{{TextDecoderOptions/ignoreBOM}}"] is <code> true</code> .
1507
+
1508
+ <li><p> Return the result of running the <a>decode an input</a> steps with <a>decoderObject</a> ,
1509
+ <var> input</var> .
1510
+ </ol>
1511
+
1512
+ <p> The <dfn method for=TextDecoder><code>decode(<var>input</var>, <var>options</var>)</code></dfn>
1513
+ method steps are:
1514
+
1515
+ <ol>
1516
+ <li><p> Return the result of running the <a>decode an input</a> steps with <a>this</a> ,
1517
+ <var> input</var> , and the <code> stream</code> flag set if
1518
+ <var> options</var> ["{{TextDecoderOptions/stream}}"] is <code> true</code> .
1519
+ </ol>
1520
+
1474
1521
<h3 id=interface-mixin-textencodercommon>Interface mixin {{TextEncoderCommon}}</h3>
1475
1522
1476
1523
<pre class=idl>
@@ -1498,6 +1545,9 @@ dictionary TextEncoderEncodeIntoResult {
1498
1545
interface TextEncoder {
1499
1546
constructor();
1500
1547
1548
+ [NewObject] static Uint8Array encode(optional USVString input = "");
1549
+ static TextEncoderEncodeIntoResult encodeInto(USVString source, [AllowShared] Uint8Array destination);
1550
+
1501
1551
[NewObject] Uint8Array encode(optional USVString input = "");
1502
1552
TextEncoderEncodeIntoResult encodeInto(USVString source, [AllowShared] Uint8Array destination);
1503
1553
};
@@ -1511,6 +1561,16 @@ requires buffering of scalar values.
1511
1561
<hr>
1512
1562
1513
1563
<dl class=domintro>
1564
+ <dt> {{TextEncoder}} . <a method for=TextEncoder lt=encode()>encode([<var>input</var> = ""])</a> </code>
1565
+ <dd><p> Returns the result of running <a>UTF-8</a> 's <a for=/>encoder</a> on input.
1566
+
1567
+ <dt> {{TextEncoder}} . <a method=for=TextEncoder lt="encodeInto(source, destination)">encodeInto(<var>source</var>, <var>destination</var>)</a> </code>
1568
+ <dd><p> Runs the <a>UTF-8 encoder</a> on <var> source</var> , stores the result of that operation into
1569
+ <var> destination</var> , and returns the progress made as an object wherein
1570
+ {{TextEncoderEncodeIntoResult/read}} is the number of converted <a>code units</a> of
1571
+ <var> source</var> and {{TextEncoderEncodeIntoResult/written}} is the number of bytes modified in
1572
+ <var> destination</var> .
1573
+
1514
1574
<dt><code><var> encoder</var> = new <a constructor for=TextEncoder>TextEncoder()</a> </code>
1515
1575
<dd><p> Returns a new {{TextEncoder}} object.
1516
1576
@@ -1528,11 +1588,7 @@ requires buffering of scalar values.
1528
1588
<var> destination</var> .
1529
1589
</dl>
1530
1590
1531
- <p> The
1532
- <dfn constructor for=TextEncoder lt=TextEncoder() id=dom-textencoder><code>new TextEncoder()</code></dfn>
1533
- constructor steps are to do nothing.
1534
-
1535
- <p> The <dfn method for=TextEncoder><code>encode(<var>input</var>)</code></dfn> method steps are:
1591
+ <p> To <a>encode an input</a> given a <a>USVString</a> <var> input</var> , run the following steps:
1536
1592
1537
1593
<ol>
1538
1594
<li><p> <a for="to I/O queue">Convert</a> <var> input</var> to an <a for=/>I/O queue</a> of scalar
@@ -1563,9 +1619,8 @@ constructor steps are to do nothing.
1563
1619
</ol>
1564
1620
</ol>
1565
1621
1566
- <p> The
1567
- <dfn method for=TextEncoder><code>encodeInto(<var>source</var>, <var>destination</var>)</code></dfn>
1568
- method steps are:
1622
+ <p> To <a>encode a source into a destination</a> given a <a>USVString</a> <var> source</var> , and a
1623
+ <a>BufferSource</a> <var> destination</var> , run the following steps:
1569
1624
1570
1625
<ol>
1571
1626
<li><p> Let <var> read</var> be 0.
@@ -1627,6 +1682,41 @@ method steps are:
1627
1682
"{{TextEncoderEncodeIntoResult/written}} " → <var> written</var> ]».
1628
1683
</ol>
1629
1684
1685
+ <p> The
1686
+ <dfn constructor for=TextEncoder lt=TextEncoder() id=dom-textencoder><code>new TextEncoder()</code></dfn>
1687
+ constructor steps are to do nothing.
1688
+
1689
+ <p> The static <dfn method for=TextEncoder><code>encode(<var>input</var>)</code></dfn> method steps
1690
+ are:
1691
+
1692
+ <ol>
1693
+ <li><p> Return the result of running the <a>encode an input</a> steps with <var> input</var> .
1694
+ </ol>
1695
+
1696
+ <p> The <dfn method for=TextEncoder><code>encode(<var>input</var>)</code></dfn> method steps are:
1697
+
1698
+ <ol>
1699
+ <li><p> Return the result of running the <a>encode an input</a> steps with <var> input</var> .
1700
+ </ol>
1701
+
1702
+ <p> The static
1703
+ <dfn method for=TextEncoder><code>encodeInto(<var>source</var>, <var>destination</var>)</code></dfn>
1704
+ method steps are:
1705
+
1706
+ <ol>
1707
+ <li><p> Return the result of running the <a>encode a source into a destination</a> steps with
1708
+ <var> source</var> and <var> destination</var> .
1709
+ </ol>
1710
+
1711
+ <p> The
1712
+ <dfn method for=TextEncoder><code>encodeInto(<var>source</var>, <var>destination</var>)</code></dfn>
1713
+ method steps are:
1714
+
1715
+ <ol>
1716
+ <li><p> Return the result of running the <a>encode a source into a destination</a> steps with
1717
+ <var> source</var> and <var> destination</var> .
1718
+ </ol>
1719
+
1630
1720
<div class=example id=example-textencoder-encodeinto>
1631
1721
<p> The <a method=for=TextEncoder lt="encodeInto(source, destination)">encodeInto()</a> method can
1632
1722
be used to encode a string into an existing {{ArrayBuffer}} object. Various details below are left
0 commit comments