Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2020-05-17 20:07:04 +0300
committerRuben Bridgewater <ruben@bridgewater.de>2020-05-25 20:20:48 +0300
commite24731cb70386899a746da59fcc2bb68df3545ff (patch)
tree3428b89f73aaa2f4e9186d3bd2f631c6349a787b /lib/internal/encoding.js
parent2f00ca42bff04773bd787ec70ba83027f22442eb (diff)
util: fix inspection of class instance prototypes
To achieve this, some internal custom inspect functions had to be changed. They relied upon the former behavior. Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de> PR-URL: https://github.com/nodejs/node/pull/33449 Fixes: https://github.com/nodejs/node/issues/33419 Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'lib/internal/encoding.js')
-rw-r--r--lib/internal/encoding.js91
1 files changed, 45 insertions, 46 deletions
diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js
index befc4f811b2..de0a1b7cc79 100644
--- a/lib/internal/encoding.js
+++ b/lib/internal/encoding.js
@@ -514,54 +514,53 @@ function makeTextDecoderJS() {
}
// Mix in some shared properties.
-{
- ObjectDefineProperties(
- TextDecoder.prototype,
- ObjectGetOwnPropertyDescriptors({
- get encoding() {
- validateDecoder(this);
- return this[kEncoding];
- },
-
- get fatal() {
- validateDecoder(this);
- return (this[kFlags] & CONVERTER_FLAGS_FATAL) === CONVERTER_FLAGS_FATAL;
- },
-
- get ignoreBOM() {
- validateDecoder(this);
- return (this[kFlags] & CONVERTER_FLAGS_IGNORE_BOM) ===
- CONVERTER_FLAGS_IGNORE_BOM;
- },
-
- [inspect](depth, opts) {
- validateDecoder(this);
- if (typeof depth === 'number' && depth < 0)
- return this;
- const ctor = getConstructorOf(this);
- const obj = ObjectCreate({
- constructor: ctor === null ? TextDecoder : ctor
- });
- obj.encoding = this.encoding;
- obj.fatal = this.fatal;
- obj.ignoreBOM = this.ignoreBOM;
- if (opts.showHidden) {
- obj[kFlags] = this[kFlags];
- obj[kHandle] = this[kHandle];
- }
- // Lazy to avoid circular dependency
- return require('internal/util/inspect').inspect(obj, opts);
+ObjectDefineProperties(
+ TextDecoder.prototype,
+ ObjectGetOwnPropertyDescriptors({
+ get encoding() {
+ validateDecoder(this);
+ return this[kEncoding];
+ },
+
+ get fatal() {
+ validateDecoder(this);
+ return (this[kFlags] & CONVERTER_FLAGS_FATAL) === CONVERTER_FLAGS_FATAL;
+ },
+
+ get ignoreBOM() {
+ validateDecoder(this);
+ return (this[kFlags] & CONVERTER_FLAGS_IGNORE_BOM) ===
+ CONVERTER_FLAGS_IGNORE_BOM;
+ },
+
+ [inspect](depth, opts) {
+ validateDecoder(this);
+ if (typeof depth === 'number' && depth < 0)
+ return this;
+ const constructor = getConstructorOf(this) || TextDecoder;
+ const obj = ObjectCreate({ constructor });
+ obj.encoding = this.encoding;
+ obj.fatal = this.fatal;
+ obj.ignoreBOM = this.ignoreBOM;
+ if (opts.showHidden) {
+ obj[kFlags] = this[kFlags];
+ obj[kHandle] = this[kHandle];
}
- }));
- ObjectDefineProperties(TextDecoder.prototype, {
- decode: { enumerable: true },
- [inspect]: { enumerable: false },
- [SymbolToStringTag]: {
- configurable: true,
- value: 'TextDecoder'
+ // Lazy to avoid circular dependency
+ const { inspect } = require('internal/util/inspect');
+ return `${constructor.name} ${inspect(obj)}`;
}
- });
-}
+ })
+);
+
+ObjectDefineProperties(TextDecoder.prototype, {
+ decode: { enumerable: true },
+ [inspect]: { enumerable: false },
+ [SymbolToStringTag]: {
+ configurable: true,
+ value: 'TextDecoder'
+ }
+});
module.exports = {
getEncodingFromLabel,