@@ -26,6 +26,9 @@ class Interface {
26
26
this . idl = idl ;
27
27
this . name = idl . name ;
28
28
this . factory = Boolean ( utils . getExtAttr ( this . idl . extAttrs , "WebIDL2JSFactory" ) ) ;
29
+ for ( const member of this . idl . members ) {
30
+ member . definingInterface = this . name ;
31
+ }
29
32
30
33
this . str = null ;
31
34
this . opts = opts ;
@@ -50,13 +53,13 @@ class Interface {
50
53
}
51
54
52
55
_analyzeMembers ( ) {
53
- let definingInterface = null ;
56
+ let memberInherited = false ;
54
57
for ( const member of this . inheritedMembers ( ) ) {
55
- if ( member [ 0 ] === inherited ) {
56
- definingInterface = member [ 1 ] ;
58
+ if ( member === inherited ) {
59
+ memberInherited = true ;
57
60
continue ;
58
61
}
59
- if ( ! definingInterface ) {
62
+ if ( ! memberInherited ) {
60
63
let key ;
61
64
switch ( member . type ) {
62
65
case "operation" :
@@ -92,16 +95,16 @@ class Interface {
92
95
case "iterable" :
93
96
if ( this . iterable ) {
94
97
throw new Error ( `Iterable interface ${ this . name } inherits from another iterable interface ` +
95
- `${ definingInterface } ` ) ;
98
+ `${ member . definingInterface } ` ) ;
96
99
}
97
100
break ;
98
101
}
99
102
}
100
103
if ( member . type === "operation" ) {
101
104
if ( member . getter ) {
102
105
let msg = `Invalid getter ${ member . name ? `"${ member . name } " ` : "" } on interface ${ this . name } ` ;
103
- if ( definingInterface ) {
104
- msg += ` (defined in ${ definingInterface } )` ;
106
+ if ( member . definingInterface !== this . name ) {
107
+ msg += ` (defined in ${ member . definingInterface } )` ;
105
108
}
106
109
msg += ": " ;
107
110
if ( member . arguments . length < 1 ||
@@ -124,8 +127,8 @@ class Interface {
124
127
}
125
128
if ( member . setter ) {
126
129
let msg = `Invalid setter ${ member . name ? `"${ member . name } " ` : "" } on interface ${ this . name } ` ;
127
- if ( definingInterface ) {
128
- msg += ` (defined in ${ definingInterface } )` ;
130
+ if ( member . definingInterface !== this . name ) {
131
+ msg += ` (defined in ${ member . definingInterface } )` ;
129
132
}
130
133
msg += ": " ;
131
134
@@ -149,8 +152,8 @@ class Interface {
149
152
}
150
153
if ( member . deleter ) {
151
154
let msg = `Invalid deleter ${ member . name ? `"${ member . name } " ` : "" } on interface ${ this . name } ` ;
152
- if ( definingInterface ) {
153
- msg += ` (defined in ${ definingInterface } )` ;
155
+ if ( member . definingInterface !== this . name ) {
156
+ msg += ` (defined in ${ member . definingInterface } )` ;
154
157
}
155
158
msg += ": " ;
156
159
@@ -168,8 +171,12 @@ class Interface {
168
171
}
169
172
}
170
173
}
171
- if ( ! definingInterface && member . stringifier ) {
172
- const msg = `Invalid stringifier ${ member . name ? `"${ member . name } " ` : "" } on interface ${ this . name } : ` ;
174
+ if ( ! memberInherited && member . stringifier ) {
175
+ let msg = `Invalid stringifier ${ member . name ? `"${ member . name } " ` : "" } on interface ${ this . name } ` ;
176
+ if ( member . definingInterface !== this . name ) {
177
+ msg += ` (defined in ${ member . definingInterface } )` ;
178
+ }
179
+ msg += ": " ;
173
180
if ( member . type === "operation" ) {
174
181
if ( ! member . idlType ) {
175
182
member . idlType = { idlType : "DOMString" } ;
@@ -224,16 +231,16 @@ class Interface {
224
231
forbiddenMembers . add ( n ) ;
225
232
}
226
233
}
227
- definingInterface = null ;
234
+ memberInherited = false ;
228
235
for ( const member of this . inheritedMembers ( ) ) {
229
- if ( member [ 0 ] === inherited ) {
230
- definingInterface = member [ 1 ] ;
236
+ if ( member === inherited ) {
237
+ memberInherited = true ;
231
238
continue ;
232
239
}
233
240
if ( forbiddenMembers . has ( member . name ) || member . name && member . name [ 0 ] === "_" ) {
234
241
let msg = `${ member . name } is forbidden in interface ${ this . name } ` ;
235
- if ( definingInterface ) {
236
- msg += ` (defined in ${ definingInterface } )` ;
242
+ if ( member . definingInterface !== this . name ) {
243
+ msg += ` (defined in ${ member . definingInterface } )` ;
237
244
}
238
245
throw new Error ( msg ) ;
239
246
}
@@ -253,6 +260,23 @@ class Interface {
253
260
}
254
261
255
262
implements ( source ) {
263
+ const iface = this . ctx . interfaces . get ( source ) ;
264
+ if ( ! iface ) {
265
+ if ( this . ctx . options . suppressErrors ) {
266
+ return ;
267
+ }
268
+ throw new Error ( `${ source } interface not found (used as a mixin for ${ this . name } )` ) ;
269
+ }
270
+
271
+ // TODO: are these actually allowed by the spec?
272
+ if ( ! this . ctx . options . suppressErrors ) {
273
+ if ( iface . idl . inheritance ) {
274
+ throw new Error ( `${ source } is used as a mixin for ${ this . name } , but it inherits from another interface` ) ;
275
+ }
276
+ if ( iface . mixins . length > 0 ) {
277
+ throw new Error ( `${ source } is used as a mixin for ${ this . name } , but it mixes in other interfaces` ) ;
278
+ }
279
+ }
256
280
this . mixins . push ( source ) ;
257
281
}
258
282
@@ -374,11 +398,12 @@ class Interface {
374
398
375
399
* inheritedMembers ( ) {
376
400
yield * this . idl . members ;
377
- for ( const iface of [ ...this . mixins , this . idl . inheritance ] ) {
378
- if ( this . ctx . interfaces . has ( iface ) ) {
379
- yield [ inherited , iface ] ;
380
- yield * this . ctx . interfaces . get ( iface ) . inheritedMembers ( ) ;
381
- }
401
+ for ( const mixin of this . mixins ) {
402
+ yield * this . ctx . interfaces . get ( mixin ) . idl . members ;
403
+ }
404
+ if ( this . idl . inheritance && this . ctx . interfaces . has ( this . idl . inheritance ) ) {
405
+ yield inherited ;
406
+ yield * this . ctx . interfaces . get ( this . idl . inheritance ) . inheritedMembers ( ) ;
382
407
}
383
408
}
384
409
@@ -389,11 +414,8 @@ class Interface {
389
414
this . requires . add ( this . idl . inheritance ) ;
390
415
}
391
416
392
- if ( this . mixins . length !== 0 ) {
393
- this . requires . addRaw ( "mixin" , "utils.mixin" ) ;
394
- for ( const mixin of this . mixins ) {
395
- this . requires . add ( mixin ) ;
396
- }
417
+ for ( const mixin of this . mixins ) {
418
+ this . requires . add ( mixin ) ;
397
419
}
398
420
399
421
this . str = `
@@ -406,7 +428,6 @@ class Interface {
406
428
generateMixins ( ) {
407
429
for ( const mixin of this . mixins ) {
408
430
this . str += `
409
- mixin(${ this . name } .prototype, ${ mixin } .interface.prototype);
410
431
${ mixin } .mixedInto.push(${ this . name } );
411
432
` ;
412
433
}
@@ -870,7 +891,7 @@ class Interface {
870
891
if ( this . supportsNamedProperties && ! utils . isGlobal ( this . idl ) ) {
871
892
const unforgeable = new Set ( ) ;
872
893
for ( const m of this . inheritedMembers ( ) ) {
873
- if ( m [ 0 ] === inherited ) {
894
+ if ( m === inherited ) {
874
895
continue ;
875
896
}
876
897
if ( ( m . type === "attribute" || m . type === "operation" ) && ! m . static &&
0 commit comments