Skip to content

Commit

Permalink
Add testcase for [Reflect] (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zirro authored and TimothyGu committed Nov 25, 2017
1 parent 9d0d9cf commit ef2cfe9
Show file tree
Hide file tree
Showing 2 changed files with 275 additions and 0 deletions.
266 changes: 266 additions & 0 deletions test/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,272 @@ const Impl = require(\\"../implementations/PromiseTypes.js\\");
"
`;
exports[`Reflect.webidl 1`] = `
"\\"use strict\\";
const conversions = require(\\"webidl-conversions\\");
const utils = require(\\"./utils.js\\");
const impl = utils.implSymbol;
function Reflect() {
throw new TypeError(\\"Illegal constructor\\");
}
Object.defineProperty(Reflect, \\"prototype\\", {
value: Reflect.prototype,
writable: false,
enumerable: false,
configurable: false
});
Object.defineProperty(Reflect.prototype, \\"ReflectedBoolean\\", {
get() {
if (!this || !module.exports.is(this)) {
throw new TypeError(\\"Illegal invocation\\");
}
return this.hasAttribute(\\"ReflectedBoolean\\");
},
set(V) {
if (!this || !module.exports.is(this)) {
throw new TypeError(\\"Illegal invocation\\");
}
V = conversions[\\"boolean\\"](V, {
context: \\"Failed to set the 'ReflectedBoolean' property on 'Reflect': The provided value\\"
});
if (V) {
this.setAttribute(\\"ReflectedBoolean\\", \\"\\");
} else {
this.removeAttribute(\\"ReflectedBoolean\\");
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(Reflect.prototype, \\"ReflectedDOMString\\", {
get() {
if (!this || !module.exports.is(this)) {
throw new TypeError(\\"Illegal invocation\\");
}
const value = this.getAttribute(\\"ReflectedDOMString\\");
return value === null ? \\"\\" : value;
},
set(V) {
if (!this || !module.exports.is(this)) {
throw new TypeError(\\"Illegal invocation\\");
}
V = conversions[\\"DOMString\\"](V, {
context: \\"Failed to set the 'ReflectedDOMString' property on 'Reflect': The provided value\\"
});
this.setAttribute(\\"ReflectedDOMString\\", V);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Reflect.prototype, \\"ReflectedLong\\", {
get() {
if (!this || !module.exports.is(this)) {
throw new TypeError(\\"Illegal invocation\\");
}
const value = parseInt(this.getAttribute(\\"ReflectedLong\\"));
return isNaN(value) || value < -2147483648 || value > 2147483647 ? 0 : value;
},
set(V) {
if (!this || !module.exports.is(this)) {
throw new TypeError(\\"Illegal invocation\\");
}
V = conversions[\\"long\\"](V, {
context: \\"Failed to set the 'ReflectedLong' property on 'Reflect': The provided value\\"
});
this.setAttribute(\\"ReflectedLong\\", String(V));
},
enumerable: true,
configurable: true
});
Object.defineProperty(Reflect.prototype, \\"ReflectedUnsignedLong\\", {
get() {
if (!this || !module.exports.is(this)) {
throw new TypeError(\\"Illegal invocation\\");
}
const value = parseInt(this.getAttribute(\\"ReflectedUnsignedLong\\"));
return isNaN(value) || value < 0 || value > 2147483647 ? 0 : value;
},
set(V) {
if (!this || !module.exports.is(this)) {
throw new TypeError(\\"Illegal invocation\\");
}
V = conversions[\\"unsigned long\\"](V, {
context: \\"Failed to set the 'ReflectedUnsignedLong' property on 'Reflect': The provided value\\"
});
this.setAttribute(\\"ReflectedUnsignedLong\\", String(V > 2147483647 ? 0 : V));
},
enumerable: true,
configurable: true
});
Object.defineProperty(Reflect.prototype, \\"ReflectionTest\\", {
get() {
if (!this || !module.exports.is(this)) {
throw new TypeError(\\"Illegal invocation\\");
}
const value = this.getAttribute(\\"reflection\\");
return value === null ? \\"\\" : value;
},
set(V) {
if (!this || !module.exports.is(this)) {
throw new TypeError(\\"Illegal invocation\\");
}
V = conversions[\\"DOMString\\"](V, {
context: \\"Failed to set the 'ReflectionTest' property on 'Reflect': The provided value\\"
});
this.setAttribute(\\"reflection\\", V);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Reflect.prototype, \\"withUnderscore\\", {
get() {
if (!this || !module.exports.is(this)) {
throw new TypeError(\\"Illegal invocation\\");
}
const value = this.getAttribute(\\"with-underscore\\");
return value === null ? \\"\\" : value;
},
set(V) {
if (!this || !module.exports.is(this)) {
throw new TypeError(\\"Illegal invocation\\");
}
V = conversions[\\"DOMString\\"](V, {
context: \\"Failed to set the 'withUnderscore' property on 'Reflect': The provided value\\"
});
this.setAttribute(\\"with-underscore\\", V);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Reflect.prototype, Symbol.toStringTag, {
value: \\"Reflect\\",
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 'Reflect'.\`);
},
create(constructorArgs, privateData) {
let obj = Object.create(Reflect.prototype);
obj = this.setup(obj, constructorArgs, privateData);
return obj;
},
createImpl(constructorArgs, privateData) {
let obj = Object.create(Reflect.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: Reflect,
expose: {
Window: { Reflect }
}
}; // iface
module.exports = iface;
const Impl = require(\\"../implementations/Reflect.js\\");
"
`;
exports[`RequestDestination.webidl 1`] = `
"\\"use strict\\";
Expand Down
9 changes: 9 additions & 0 deletions test/cases/Reflect.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
interface Reflect {
[Reflect] attribute boolean ReflectedBoolean;
[FooBar, Reflect] attribute DOMString ReflectedDOMString;
[Reflect, FooBar] attribute long ReflectedLong;
[Reflect] attribute unsigned long ReflectedUnsignedLong;

[FooBar, Reflect=reflection] attribute DOMString ReflectionTest;
[Reflect=with_underscore, FooBar] attribute DOMString withUnderscore;
};

0 comments on commit ef2cfe9

Please sign in to comment.