(encoding = 'utf-8', options = kEmptyObject)
| 428 | |
| 429 | class TextDecoder { |
| 430 | constructor(encoding = 'utf-8', options = kEmptyObject) { |
| 431 | encoding = `${encoding}`; |
| 432 | validateObject(options, 'options', kValidateObjectAllowObjectsAndNull); |
| 433 | |
| 434 | const enc = getEncodingFromLabel(encoding); |
| 435 | if (enc === undefined) |
| 436 | throw new ERR_ENCODING_NOT_SUPPORTED(encoding); |
| 437 | |
| 438 | let flags = 0; |
| 439 | if (options !== null) { |
| 440 | flags |= options.fatal ? CONVERTER_FLAGS_FATAL : 0; |
| 441 | flags |= options.ignoreBOM ? CONVERTER_FLAGS_IGNORE_BOM : 0; |
| 442 | } |
| 443 | |
| 444 | this[kDecoder] = true; |
| 445 | this[kFlags] = flags; |
| 446 | this[kEncoding] = enc; |
| 447 | this[kIgnoreBOM] = Boolean(options?.ignoreBOM); |
| 448 | this[kFatal] = Boolean(options?.fatal); |
| 449 | this[kUTF8FastPath] = false; |
| 450 | this[kHandle] = undefined; |
| 451 | this[kSingleByte] = undefined; // Does not care about streaming or BOM |
| 452 | this[kChunk] = null; // A copy of previous streaming tail or null |
| 453 | |
| 454 | if (enc === 'utf-8') { |
| 455 | this[kUTF8FastPath] = true; |
| 456 | this[kBOMSeen] = false; |
| 457 | } else if (isSinglebyteEncoding(enc)) { |
| 458 | this[kSingleByte] = createSinglebyteDecoder(enc, this[kFatal]); |
| 459 | } else { |
| 460 | this.#prepareConverter(); // Need to throw early if we don't support the encoding |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | #prepareConverter() { |
| 465 | if (hasIntl) { |
nothing calls this directly
no test coverage detected