From ccd627978d2ba0ae1edf8368f1ddbae66105d3e9 Mon Sep 17 00:00:00 2001 From: Zirro Date: Sat, 25 Nov 2017 16:20:29 +0100 Subject: [PATCH] [Unscopeable] is now [Unscopable] Changed in https://github.com/heycam/webidl/issues/103 --- README.md | 2 +- lib/constructs/interface.js | 2 +- test/__snapshots__/test.js.snap | 141 ++++++++++++++++++++++++++++++++ test/cases/Unscopable.webidl | 3 + 4 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 test/cases/Unscopable.webidl diff --git a/README.md b/README.md index f466819d..3bd63632 100644 --- a/README.md +++ b/README.md @@ -350,7 +350,7 @@ webidl2js is implementing an ever-growing subset of the Web IDL specification. S - `[SameObject]` (automatic caching) - `[TreatNullAs]` - `[Unforgeable]` -- `[Unscopeable]` +- `[Unscopable]` Notable missing features include: diff --git a/lib/constructs/interface.js b/lib/constructs/interface.js index 9f713ceb..0665c6c7 100644 --- a/lib/constructs/interface.js +++ b/lib/constructs/interface.js @@ -1221,7 +1221,7 @@ class Interface { generateSymbols() { const unscopables = Object.create(null); for (const member of this.idl.members) { - if (utils.getExtAttr(member.extAttrs, "Unscopeable")) { + if (utils.getExtAttr(member.extAttrs, "Unscopable")) { unscopables[member.name] = true; } } diff --git a/test/__snapshots__/test.js.snap b/test/__snapshots__/test.js.snap index 1e603224..e66b26cc 100644 --- a/test/__snapshots__/test.js.snap +++ b/test/__snapshots__/test.js.snap @@ -6465,6 +6465,147 @@ const Impl = require(\\"../implementations/UnforgeableMap.js\\"); " `; +exports[`Unscopable.webidl 1`] = ` +"\\"use strict\\"; + +const conversions = require(\\"webidl-conversions\\"); +const utils = require(\\"./utils.js\\"); + +const impl = utils.implSymbol; + +function Unscopable() { + throw new TypeError(\\"Illegal constructor\\"); +} + +Object.defineProperty(Unscopable, \\"prototype\\", { + value: Unscopable.prototype, + writable: false, + enumerable: false, + configurable: false +}); + +Object.defineProperty(Unscopable.prototype, \\"unscopableTest\\", { + get() { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + return this[impl][\\"unscopableTest\\"]; + }, + + set(V) { + if (!this || !module.exports.is(this)) { + throw new TypeError(\\"Illegal invocation\\"); + } + + V = conversions[\\"boolean\\"](V, { + context: \\"Failed to set the 'unscopableTest' property on 'Unscopable': The provided value\\" + }); + + this[impl][\\"unscopableTest\\"] = V; + }, + + enumerable: true, + configurable: true +}); + +Object.defineProperty(Unscopable.prototype, Symbol.unscopables, { + value: { + unscopableTest: true + }, + writable: false, + enumerable: false, + configurable: true +}); + +Object.defineProperty(Unscopable.prototype, Symbol.toStringTag, { + value: \\"Unscopable\\", + writable: false, + enumerable: false, + configurable: true +}); + +const iface = { + // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\` + // method into this array. It allows objects that directly implements *those* interfaces to be recognized as + // implementing this mixin interface. + _mixedIntoPredicates: [], + is(obj) { + if (obj) { + if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) { + return true; + } + for (const isMixedInto of module.exports._mixedIntoPredicates) { + if (isMixedInto(obj)) { + return true; + } + } + } + return false; + }, + isImpl(obj) { + if (obj) { + if (obj instanceof Impl.implementation) { + return true; + } + + const wrapper = utils.wrapperForImpl(obj); + for (const isMixedInto of module.exports._mixedIntoPredicates) { + if (isMixedInto(wrapper)) { + return true; + } + } + } + return false; + }, + convert(obj, { context = \\"The provided value\\" } = {}) { + if (module.exports.is(obj)) { + return utils.implForWrapper(obj); + } + throw new TypeError(\`\${context} is not of type 'Unscopable'.\`); + }, + + create(constructorArgs, privateData) { + let obj = Object.create(Unscopable.prototype); + obj = this.setup(obj, constructorArgs, privateData); + return obj; + }, + createImpl(constructorArgs, privateData) { + let obj = Object.create(Unscopable.prototype); + obj = this.setup(obj, constructorArgs, privateData); + return utils.implForWrapper(obj); + }, + _internalSetup(obj) {}, + setup(obj, constructorArgs, privateData) { + if (!privateData) privateData = {}; + + privateData.wrapper = obj; + + this._internalSetup(obj); + Object.defineProperty(obj, impl, { + value: new Impl.implementation(constructorArgs, privateData), + writable: false, + enumerable: false, + configurable: true + }); + + obj[impl][utils.wrapperSymbol] = obj; + if (Impl.init) { + Impl.init(obj[impl], privateData); + } + return obj; + }, + interface: Unscopable, + expose: { + Window: { Unscopable } + } +}; // iface +module.exports = iface; + +const Impl = require(\\"../implementations/Unscopable.js\\"); +" +`; + exports[`Variadic.webidl 1`] = ` "\\"use strict\\"; diff --git a/test/cases/Unscopable.webidl b/test/cases/Unscopable.webidl new file mode 100644 index 00000000..a103a9b7 --- /dev/null +++ b/test/cases/Unscopable.webidl @@ -0,0 +1,3 @@ +interface Unscopable { + [Unscopable] attribute boolean unscopableTest; +};