Skip to content

Commit

Permalink
[Unscopeable] is now [Unscopable] (jsdom#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zirro authored and TimothyGu committed Nov 25, 2017
1 parent ef2cfe9 commit a0159a3
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion lib/constructs/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
141 changes: 141 additions & 0 deletions test/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6731,6 +6731,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\\";
Expand Down
3 changes: 3 additions & 0 deletions test/cases/Unscopable.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Unscopable {
[Unscopable] attribute boolean unscopableTest;
};

0 comments on commit a0159a3

Please sign in to comment.