Skip to content

Commit

Permalink
match spec re: FastTextEncoder
Browse files Browse the repository at this point in the history
  • Loading branch information
samthor committed Mar 6, 2020
1 parent 71650ca commit d8685e5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions text.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ if (scope['TextEncoder'] && scope['TextDecoder']) {
return false;
}

// used for FastTextDecoder
const validUtfLabels = ['utf-8', 'utf8', 'unicode-1-1-utf-8'];

/**
* @constructor
* @param {string=} utfLabel
*/
function FastTextEncoder(utfLabel='utf-8') {
if (utfLabel !== 'utf-8' && utfLabel !== 'utf8') {
throw new RangeError(
`Failed to construct 'TextEncoder': The encoding label provided ('${utfLabel}') is invalid.`);
}
function FastTextEncoder() {
// This does not accept an encoding, and always uses UTF-8:
// https://www.w3.org/TR/encoding/#dom-textencoder
}

Object.defineProperty(FastTextEncoder.prototype, 'encoding', {value: 'utf-8'});
Expand Down Expand Up @@ -116,7 +116,7 @@ FastTextEncoder.prototype.encode = function(string, options={stream: false}) {
* @param {{fatal: boolean}=} options
*/
function FastTextDecoder(utfLabel='utf-8', options={fatal: false}) {
if (utfLabel !== 'utf-8' && utfLabel !== 'utf8') {
if (validUtfLabels.indexOf(utfLabel.toLowerCase()) == -1) {
throw new RangeError(
`Failed to construct 'TextDecoder': The encoding label provided ('${utfLabel}') is invalid.`);
}
Expand Down

0 comments on commit d8685e5

Please sign in to comment.