Skip to content

Commit 5858a99

Browse files
committed
Merge branch 'master' into test/rename-generation-test
2 parents ad557c7 + 2ce65bd commit 5858a99

File tree

3 files changed

+135
-1937
lines changed

3 files changed

+135
-1937
lines changed

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,24 +188,18 @@ The example above showed a simplified generated wrapper file with only three exp
188188

189189
### For interfaces
190190

191-
Note that all of the below are still exported for "mixin" interfaces, but only `isImpl()` and `is()` make sense ([#55](https://github.com/jsdom/webidl2js/issues/55)).
192-
193191
#### `isImpl(value)`
194192

195193
Returns a boolean indicating whether _value_ is an instance of the corresponding implementation class.
196194

197195
This is especially useful inside implementation class files, where incoming wrappers will be _unwrapped_, so that you only ever see implementation class instances ("impls").
198196

199-
This also works when used with mixin implementation classes: that is, `generatedModuleForMixin.isImpl(implForMixinTarget)` will be true.
200-
201197
#### `is(value)`
202198

203199
Returns a boolean indicating whether _value_ is an instance of the wrapper class.
204200

205201
This is useful in other parts of your program that are not implementation class files, but instead receive wrapper classes from client code.
206202

207-
This also works when used with mixin wrapper classes: that is, `generatedModuleForMixin.is(wrapperForMixinTarget)` will be true.
208-
209203
#### `convert(value, { context })`
210204

211205
Performs the Web IDL conversion algorithm for this interface, converting _value_ into the correct representation of the interface type suitable for consumption by implementation classes: the corresponding impl.
@@ -259,8 +253,6 @@ A constructor for your implementation class, with signature `(globalObject, cons
259253

260254
If you don't need to do any of these things, the constructor is entirely optional.
261255

262-
Additionally, the constructor should not be provided for mixin classes; it will never be called.
263-
264256
### Methods implementing IDL operations
265257

266258
IDL operations that you wish to implement need to have corresponding methods on the implementation class.

lib/constructs/interface.js

Lines changed: 8 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ class Interface {
7474
this.str = null;
7575
this.opts = opts;
7676
this.requires = new utils.RequiresMap(ctx);
77-
this.implemented = [];
7877
this.included = [];
7978

8079
this.constructorOperations = [];
@@ -270,8 +269,7 @@ class Interface {
270269
}
271270
};
272271

273-
const seen = new Set([this.name]);
274-
for (const member of this.members(seen)) {
272+
for (const member of this.members()) {
275273
let key;
276274
switch (member.type) {
277275
case "constructor":
@@ -348,7 +346,7 @@ class Interface {
348346
this.stringifier = member;
349347
}
350348
}
351-
for (const member of this.inheritedMembers(seen)) {
349+
for (const member of this.inheritedMembers()) {
352350
if (this.iterable && member.type === "iterable") {
353351
throw new Error(`Iterable interface ${this.name} inherits from another iterable interface ` +
354352
`${member.definingInterface}`);
@@ -452,21 +450,9 @@ class Interface {
452450
}
453451
}
454452

455-
// https://heycam.github.io/webidl/#dfn-consequential-interfaces
456-
* consequentialInterfaces(seen = new Set([this.name]), root = this.name) {
457-
for (const iface of this.implemented) {
458-
if (seen.has(iface)) {
459-
throw new Error(`${root} has a dependency cycle`);
460-
}
461-
seen.add(iface);
462-
yield* this.ctx.interfaces.get(iface).allInterfaces(seen);
463-
}
464-
}
465-
466453
// All interfaces an object of this interface implements.
467454
* allInterfaces(seen = new Set([this.name]), root = this.name) {
468455
yield this.name;
469-
yield* this.consequentialInterfaces(seen, root);
470456
if (this.idl.inheritance && this.ctx.interfaces.has(this.idl.inheritance)) {
471457
if (seen.has(this.idl.inheritance)) {
472458
throw new Error(`${root} has an inheritance cycle`);
@@ -476,19 +462,16 @@ class Interface {
476462
}
477463
}
478464

479-
// Members that will be visible on this interface's prototype object, i.e. members from this
480-
// interface and its consequential interfaces.
481-
* members(seen = new Set([this.name]), root = this.name) {
465+
// Members that will be own properties of this interface's prototype object,
466+
// i.e. members from this interface and its mixins.
467+
* members() {
482468
yield* this.idl.members;
483469
for (const mixin of this.included) {
484470
yield* this.ctx.interfaceMixins.get(mixin).idl.members;
485471
}
486-
for (const iface of this.consequentialInterfaces(seen, root)) {
487-
yield* this.ctx.interfaces.get(iface).idl.members;
488-
}
489472
}
490473

491-
// Members from this interface's inherited interfaces and their consequential interfaces.
474+
// Members inherited from this interface's prototype chain.
492475
* inheritedMembers(seen = new Set([this.name]), root = this.name) {
493476
if (this.idl.inheritance && this.ctx.interfaces.has(this.idl.inheritance)) {
494477
if (seen.has(this.idl.inheritance)) {
@@ -516,60 +499,20 @@ class Interface {
516499
this.requires.add(this.idl.inheritance);
517500
}
518501

519-
for (const iface of this.consequentialInterfaces()) {
520-
this.requires.add(iface);
521-
}
522-
523502
this.str = `
524503
${this.requires.generate()}
525504
526505
${this.str}
527506
`;
528507
}
529508

530-
generateMixins() {
531-
for (const iface of this.consequentialInterfaces()) {
532-
this.str += `
533-
${iface}._mixedIntoPredicates.push(exports.is);
534-
`;
535-
}
536-
}
537-
538509
generateExport() {
539510
this.str += `
540-
/**
541-
* When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\`
542-
* method into this array. It allows objects that directly implements *those* interfaces to be recognized as
543-
* implementing this mixin interface.
544-
*/
545-
exports._mixedIntoPredicates = [];
546511
exports.is = function is(obj) {
547-
if (obj) {
548-
if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) {
549-
return true;
550-
}
551-
for (const isMixedInto of exports._mixedIntoPredicates) {
552-
if (isMixedInto(obj)) {
553-
return true;
554-
}
555-
}
556-
}
557-
return false;
512+
return utils.isObject(obj) && utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation;
558513
};
559514
exports.isImpl = function isImpl(obj) {
560-
if (obj) {
561-
if (obj instanceof Impl.implementation) {
562-
return true;
563-
}
564-
565-
const wrapper = utils.wrapperForImpl(obj);
566-
for (const isMixedInto of exports._mixedIntoPredicates) {
567-
if (isMixedInto(wrapper)) {
568-
return true;
569-
}
570-
}
571-
}
572-
return false;
515+
return utils.isObject(obj) && obj instanceof Impl.implementation;
573516
};
574517
exports.convert = function convert(obj, { context = "The provided value" } = {}) {
575518
if (exports.is(obj)) {
@@ -1551,7 +1494,6 @@ class Interface {
15511494
this.generateLegacyProxyHandler();
15521495
}
15531496

1554-
this.generateMixins();
15551497
this.generateRequires();
15561498
}
15571499

0 commit comments

Comments
 (0)