From 64a7205d8b038687f4d1f74050ad8f51b66b4794 Mon Sep 17 00:00:00 2001 From: droooney Date: Mon, 24 Apr 2017 17:06:30 +0500 Subject: [PATCH 1/3] Add support for Symbol.toStringTag (closes #21). --- lib/constructs/interface.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/constructs/interface.js b/lib/constructs/interface.js index ff2e6368..d16ddcaa 100644 --- a/lib/constructs/interface.js +++ b/lib/constructs/interface.js @@ -393,6 +393,7 @@ Interface.prototype.generateSymbols = function () { this.str += ` ${this.name}.prototype[Symbol.unscopables] = ${JSON.stringify(unscopables, null, ' ')};\n`; } + this.str += `${this.name}.prototype[Symbol.toStringTag] = ${JSON.stringify(this.name)};\n`; }; Interface.prototype.generate = function () { From 3ff14cd2b008f80a01343bb97aaaa4467546df73 Mon Sep 17 00:00:00 2001 From: droooney Date: Tue, 25 Apr 2017 19:34:54 +0500 Subject: [PATCH 2/3] Remove toString in favor of Symbol.toStringTag. --- lib/constructs/interface.js | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/lib/constructs/interface.js b/lib/constructs/interface.js index d16ddcaa..acb92f09 100644 --- a/lib/constructs/interface.js +++ b/lib/constructs/interface.js @@ -357,30 +357,6 @@ Interface.prototype.generateAttributes = function () { } }; -Interface.prototype.generateToString = function () { - let hasToString = false; - for (const member of this.idl.members) { - if (member.stringifier || member.name === "toString") { - hasToString = true; - } - } - if (!hasToString) { - this.str += `\n${this.name}.prototype.toString = function () { - if (this === ${this.name}.prototype) { - return "[object ${this.name}Prototype]"; - }`; - if (this.idl.inheritance) { - this.str += ` - return ${this.idl.inheritance}.interface.prototype.toString.call(this);`; - } else { - this.str += ` - return this[impl].toString();`; - } - this.str += ` -};\n`; - } -}; - Interface.prototype.generateSymbols = function () { const unscopables = {}; for (const member of this.idl.members) { @@ -393,7 +369,7 @@ Interface.prototype.generateSymbols = function () { this.str += ` ${this.name}.prototype[Symbol.unscopables] = ${JSON.stringify(unscopables, null, ' ')};\n`; } - this.str += `${this.name}.prototype[Symbol.toStringTag] = ${JSON.stringify(this.name)};\n`; + this.str += `\n${this.name}.prototype[Symbol.toStringTag] = ${JSON.stringify(this.name)};\n`; }; Interface.prototype.generate = function () { @@ -411,7 +387,6 @@ module.exports = { this.generateMixins(); this.generateOperations(); - this.generateToString(); this.generateAttributes(); this.generateRequires(); From d7d26691f4b9eb78ff4d99e10378f3e911c20082 Mon Sep 17 00:00:00 2001 From: droooney Date: Tue, 25 Apr 2017 19:55:16 +0500 Subject: [PATCH 3/3] Revert toString removal without the toStringTag part. --- lib/constructs/interface.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/constructs/interface.js b/lib/constructs/interface.js index acb92f09..3a7cdecd 100644 --- a/lib/constructs/interface.js +++ b/lib/constructs/interface.js @@ -357,6 +357,27 @@ Interface.prototype.generateAttributes = function () { } }; +Interface.prototype.generateToString = function () { + let hasToString = false; + for (const member of this.idl.members) { + if (member.stringifier || member.name === "toString") { + hasToString = true; + } + } + if (!hasToString) { + this.str += `\n${this.name}.prototype.toString = function () {`; + if (this.idl.inheritance) { + this.str += ` + return ${this.idl.inheritance}.interface.prototype.toString.call(this);`; + } else { + this.str += ` + return this[impl].toString();`; + } + this.str += ` +};\n`; + } +}; + Interface.prototype.generateSymbols = function () { const unscopables = {}; for (const member of this.idl.members) { @@ -387,6 +408,7 @@ module.exports = { this.generateMixins(); this.generateOperations(); + this.generateToString(); this.generateAttributes(); this.generateRequires();