Skip to content

Commit

Permalink
Add support for [LegacyArrayClass]
Browse files Browse the repository at this point in the history
  • Loading branch information
Zirro authored and domenic committed Aug 20, 2017
1 parent 4c53388 commit cacfcca
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/constructs/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ class Interface {
Object.setPrototypeOf(${this.name}.prototype, ${this.idl.inheritance}.interface.prototype);
Object.setPrototypeOf(${this.name}, ${this.idl.inheritance}.interface);
`;
} else if (utils.getExtAttr(this.idl.extAttrs, "LegacyArrayClass")) {
this.str += `
Object.setPrototypeOf(${this.name}.prototype, Array.prototype);
`;
}

this.str += `
Expand Down
119 changes: 119 additions & 0 deletions test/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,125 @@ const Impl = require(\\"../implementations/Factory.js\\");
"
`;

exports[`LegacyArrayClass.idl 1`] = `
"\\"use strict\\";
const conversions = require(\\"webidl-conversions\\");
const utils = require(\\"./utils.js\\");
const impl = utils.implSymbol;
function LegacyArrayClass() {
throw new TypeError(\\"Illegal constructor\\");
}
Object.setPrototypeOf(LegacyArrayClass.prototype, Array.prototype);
Object.defineProperty(LegacyArrayClass, \\"prototype\\", {
value: LegacyArrayClass.prototype,
writable: false,
enumerable: false,
configurable: false
});
Object.defineProperty(LegacyArrayClass.prototype, \\"length\\", {
get() {
if (!this || !module.exports.is(this)) {
throw new TypeError(\\"Illegal invocation\\");
}
return this[impl][\\"length\\"];
},
enumerable: true,
configurable: true
});
Object.defineProperty(LegacyArrayClass.prototype, Symbol.toStringTag, {
value: \\"LegacyArrayClass\\",
writable: false,
enumerable: false,
configurable: true
});
const iface = {
mixedInto: [],
is(obj) {
if (obj) {
if (obj[impl] instanceof Impl.implementation) {
return true;
}
for (let i = 0; i < module.exports.mixedInto.length; ++i) {
if (obj instanceof module.exports.mixedInto[i]) {
return true;
}
}
}
return false;
},
isImpl(obj) {
if (obj) {
if (obj instanceof Impl.implementation) {
return true;
}
const wrapper = utils.wrapperForImpl(obj);
for (let i = 0; i < module.exports.mixedInto.length; ++i) {
if (wrapper instanceof module.exports.mixedInto[i]) {
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 'LegacyArrayClass'.\`);
},
create(constructorArgs, privateData) {
let obj = Object.create(LegacyArrayClass.prototype);
obj = this.setup(obj, constructorArgs, privateData);
return obj;
},
createImpl(constructorArgs, privateData) {
let obj = Object.create(LegacyArrayClass.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: LegacyArrayClass,
expose: {
Window: { LegacyArrayClass }
}
}; // iface
module.exports = iface;
const Impl = require(\\"../implementations/LegacyArrayClass.js\\");
"
`;

exports[`PromiseTypes.idl 1`] = `
"\\"use strict\\";
Expand Down
4 changes: 4 additions & 0 deletions test/cases/LegacyArrayClass.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[LegacyArrayClass]
interface LegacyArrayClass {
readonly attribute unsigned long length;
};

0 comments on commit cacfcca

Please sign in to comment.