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

Commit

Permalink
Store error mode as string
Browse files Browse the repository at this point in the history
  • Loading branch information
inexorabletash committed Feb 10, 2016
1 parent 50fa3a5 commit f62beaf
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions lib/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Expand All @@ -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.
Expand All @@ -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;
}

Expand All @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f62beaf

Please sign in to comment.