diff --git a/lib/encoding.js b/lib/encoding.js index 7a04bf8..a750282 100644 --- a/lib/encoding.js +++ b/lib/encoding.js @@ -274,12 +274,6 @@ if (typeof module !== "undefined" && module.exports) { /** @const */ var finished = -1; - /** @const */ - var error_mode_replacement = false; - - /** @const */ - var error_mode_fatal = true; - /** * @param {boolean} fatal If true, decoding errors raise an exception. * @param {number=} opt_code_point Override the standard fallback code point. @@ -1008,8 +1002,8 @@ if (typeof module !== "undefined" && module.exports) { this._ignoreBOM = false; /** @private @type {boolean} */ this._BOMseen = false; - /** @private @type {boolean} */ - this._error_mode = error_mode_replacement; + /** @private @type {string} */ + this._error_mode = 'replacement'; /** @private @type {boolean} */ this._do_not_flush = false; @@ -1035,7 +1029,7 @@ if (typeof module !== "undefined" && module.exports) { // 5. If options's fatal member is true, set dec's error mode to // fatal. if (Boolean(options['fatal'])) - dec._error_mode = error_mode_fatal; + dec._error_mode = 'fatal'; // 6. If options's ignoreBOM member is true, set dec's ignore BOM // flag. @@ -1045,7 +1039,7 @@ if (typeof module !== "undefined" && module.exports) { // For pre-ES5 runtimes: if (!Object.defineProperty) { this.encoding = dec._encoding.name; - this.fatal = dec._error_mode; + this.fatal = dec._error_mode === 'fatal'; this.ignoreBOM = dec._ignoreBOM; } @@ -1064,7 +1058,7 @@ if (typeof module !== "undefined" && module.exports) { // is fatal, and false otherwise. Object.defineProperty(TextDecoder.prototype, 'fatal', { /** @this {TextDecoder} */ - get: function() { return this._error_mode === error_mode_fatal; } + get: function() { return this._error_mode === 'fatal'; } }); // The ignoreBOM attribute's getter must return true if ignore @@ -1099,7 +1093,8 @@ if (typeof module !== "undefined" && module.exports) { // encoding's decoder, set stream to a new stream, and unset the // BOM seen flag. if (!this._do_not_flush) { - this._decoder = decoders[this._encoding.name]({fatal: this._error_mode}); + this._decoder = decoders[this._encoding.name]({ + fatal: this._error_mode === 'fatal'}); this._BOMseen = false; } @@ -1228,8 +1223,8 @@ if (typeof module !== "undefined" && module.exports) { // Non-standard /** @private @type {boolean} */ this._do_not_flush = false; - /** @private @type {boolean} */ - this._fatal = Boolean(options['fatal']); + /** @private @type {string} */ + this._fatal = Boolean(options['fatal']) ? 'fatal' : 'replacement'; // 1. Let encoding be the result of getting an encoding from utfLabel. var encoding = getEncoding(label); @@ -1283,7 +1278,8 @@ if (typeof module !== "undefined" && module.exports) { // permitted for encoding (i.e. UTF-8, UTF-16) are stateful when // the input is a USVString so streaming is not necessary. if (!this._do_not_flush) - this._encoder = encoders[this._encoding.name]({fatal: this._fatal}); + this._encoder = encoders[this._encoding.name]({ + fatal: this._fatal === 'fatal'}); this._do_not_flush = Boolean(options['stream']); // 1. Convert input to a stream.