Skip to content
This repository has been archived by the owner on Sep 28, 2018. It is now read-only.

Commit

Permalink
Track spec grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
inexorabletash committed Feb 10, 2016
1 parent 9fc6b56 commit 5716244
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions lib/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,12 @@ if (typeof module !== "undefined" && module.exports) {
}

/**
* @param {*} item The item to look for in the list.
* @param {!Array.<*>} list The list to check.
* @return {boolean} True if the item appears in the list.
* @param {!Array.<*>} array The array to check.
* @param {*} item The item to look for in the array.
* @return {boolean} True if the item appears in the array.
*/
function isOneOf(item, list) {
return list.indexOf(item) !== -1;
}

/**
* @param {*} item The item to look for in the list.
* @param {!Array.<*>} list The list to check.
* @return {boolean} True if the item does not appear in the list.
*/
function isNoneOf(item, list) {
return list.indexOf(item) === -1;
function includes(array, item) {
return array.indexOf(item) !== -1;
}

var floor = Math.floor;
Expand Down Expand Up @@ -1174,7 +1165,7 @@ if (typeof module !== "undefined" && module.exports) {

// 2. If encoding is UTF-8, UTF-16BE, or UTF-16LE, and ignore
// BOM flag and BOM seen flag are unset, run these subsubsteps:
if (isOneOf(this._encoding.name, ['UTF-8', 'UTF-16LE', 'UTF-16BE']) &&
if (includes(['UTF-8', 'UTF-16LE', 'UTF-16BE'], this._encoding.name) &&
!this._ignoreBOM && !this._BOMseen) {
if (stream.length > 0 && stream[0] === 0xFEFF) {
// 1. If token is U+FEFF, set BOM seen flag.
Expand Down Expand Up @@ -1228,10 +1219,10 @@ if (typeof module !== "undefined" && module.exports) {
// 1. Let encoding be the result of getting an encoding from utfLabel.
var encoding = getEncoding(label);

// 2. If encoding is failure, or is none of utf-8, utf-16be, and
// utf-16le, throw a RangeError.
// 2. If encoding is failure, or is not UTF-8, UTF-16BE, or
// UTF-16LE, throw a RangeError.
if (encoding === null || encoding.name === 'replacement' ||
(isNoneOf(encoding.name, ['UTF-8','UTF-16LE', 'UTF-16BE']) &&
(!includes(['UTF-8','UTF-16LE', 'UTF-16BE'], encoding.name) &&
!Boolean(options['NONSTANDARD_allowLegacyEncoding'])))
throw RangeError('Unknown encoding: ' + label);
if (!encoders[encoding.name]) {
Expand Down

0 comments on commit 5716244

Please sign in to comment.