Skip to content

Commit

Permalink
src: remove function hasTextDecoder in encoding.js
Browse files Browse the repository at this point in the history
also... return TextDecoder directly from factories

PR-URL: #23625
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
chichiwang authored and addaleax committed Oct 20, 2018
1 parent 3f63297 commit 8b431ad
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions lib/internal/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,22 +341,16 @@ Object.defineProperties(
value: 'TextEncoder'
} });

const { hasConverter, TextDecoder } =
const TextDecoder =
process.binding('config').hasIntl ?
makeTextDecoderICU() :
makeTextDecoderJS();

function hasTextDecoder(encoding = 'utf-8') {
validateArgument(encoding, 'string', 'encoding', 'string');
return hasConverter(getEncodingFromLabel(encoding));
}

function makeTextDecoderICU() {
const {
decode: _decode,
getConverter,
hasConverter
} = process.binding('icu');
} = internalBinding('icu');

class TextDecoder {
constructor(encoding = 'utf-8', options = {}) {
Expand Down Expand Up @@ -409,7 +403,7 @@ function makeTextDecoderICU() {
}
}

return { hasConverter, TextDecoder };
return TextDecoder;
}

function makeTextDecoderJS() {
Expand Down Expand Up @@ -497,7 +491,7 @@ function makeTextDecoderJS() {
}
}

return { hasConverter, TextDecoder };
return TextDecoder;
}

// Mix in some shared properties.
Expand Down Expand Up @@ -552,7 +546,6 @@ function makeTextDecoderJS() {

module.exports = {
getEncodingFromLabel,
hasTextDecoder,
TextDecoder,
TextEncoder
};

0 comments on commit 8b431ad

Please sign in to comment.