@@ -519,63 +519,65 @@ class Interface {
519
519
generateMixins ( ) {
520
520
for ( const iface of this . consequentialInterfaces ( ) ) {
521
521
this . str += `
522
- ${ iface } ._mixedIntoPredicates.push(module. exports.is);
522
+ ${ iface } ._mixedIntoPredicates.push(exports.is);
523
523
` ;
524
524
}
525
525
}
526
526
527
527
generateExport ( ) {
528
528
this . str += `
529
- // When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\`
530
- // method into this array. It allows objects that directly implements *those* interfaces to be recognized as
531
- // implementing this mixin interface.
532
- _mixedIntoPredicates: [],
533
- is(obj) {
529
+ /**
530
+ * When an interface-module that implements this interface as a mixin is loaded, it will append its own \`.is()\`
531
+ * method into this array. It allows objects that directly implements *those* interfaces to be recognized as
532
+ * implementing this mixin interface.
533
+ */
534
+ exports._mixedIntoPredicates = [];
535
+ exports.is = function is(obj) {
534
536
if (obj) {
535
537
if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) {
536
538
return true;
537
539
}
538
- for (const isMixedInto of module. exports._mixedIntoPredicates) {
540
+ for (const isMixedInto of exports._mixedIntoPredicates) {
539
541
if (isMixedInto(obj)) {
540
542
return true;
541
543
}
542
544
}
543
545
}
544
546
return false;
545
- },
546
- isImpl(obj) {
547
+ };
548
+ exports.isImpl = function isImpl(obj) {
547
549
if (obj) {
548
550
if (obj instanceof Impl.implementation) {
549
551
return true;
550
552
}
551
553
552
554
const wrapper = utils.wrapperForImpl(obj);
553
- for (const isMixedInto of module. exports._mixedIntoPredicates) {
555
+ for (const isMixedInto of exports._mixedIntoPredicates) {
554
556
if (isMixedInto(wrapper)) {
555
557
return true;
556
558
}
557
559
}
558
560
}
559
561
return false;
560
- },
561
- convert(obj, { context = "The provided value" } = {}) {
562
- if (module. exports.is(obj)) {
562
+ };
563
+ exports.convert = function convert(obj, { context = "The provided value" } = {}) {
564
+ if (exports.is(obj)) {
563
565
return utils.implForWrapper(obj);
564
566
}
565
567
throw new TypeError(\`\${context} is not of type '${ this . name } '.\`);
566
- },
568
+ };
567
569
` ;
568
570
569
571
if ( this . iterable && this . iterable . isPair ) {
570
572
this . str += `
571
- createDefaultIterator(target, kind) {
573
+ exports.createDefaultIterator = function createDefaultIterator(target, kind) {
572
574
const iterator = Object.create(IteratorPrototype);
573
575
Object.defineProperty(iterator, utils.iterInternalSymbol, {
574
576
value: { target, kind, index: 0 },
575
577
configurable: true
576
578
});
577
579
return iterator;
578
- },
580
+ };
579
581
` ;
580
582
}
581
583
}
@@ -1098,7 +1100,7 @@ class Interface {
1098
1100
1099
1101
generateIface ( ) {
1100
1102
this . str += `
1101
- create(globalObject, constructorArgs, privateData) {
1103
+ exports.create = function create(globalObject, constructorArgs, privateData) {
1102
1104
if (globalObject[ctorRegistry] === undefined) {
1103
1105
throw new Error('Internal error: invalid global object');
1104
1106
}
@@ -1109,14 +1111,14 @@ class Interface {
1109
1111
}
1110
1112
1111
1113
let obj = Object.create(ctor.prototype);
1112
- obj = iface .setup(obj, globalObject, constructorArgs, privateData);
1114
+ obj = exports .setup(obj, globalObject, constructorArgs, privateData);
1113
1115
return obj;
1114
- },
1115
- createImpl(globalObject, constructorArgs, privateData) {
1116
- const obj = iface .create(globalObject, constructorArgs, privateData);
1116
+ };
1117
+ exports.createImpl = function createImpl(globalObject, constructorArgs, privateData) {
1118
+ const obj = exports .create(globalObject, constructorArgs, privateData);
1117
1119
return utils.implForWrapper(obj);
1118
- },
1119
- _internalSetup(obj) {
1120
+ };
1121
+ exports._internalSetup = function _internalSetup(obj) {
1120
1122
` ;
1121
1123
1122
1124
if ( this . idl . inheritance ) {
@@ -1128,11 +1130,11 @@ class Interface {
1128
1130
this . generateOnInstance ( ) ;
1129
1131
1130
1132
this . str += `
1131
- },
1132
- setup(obj, globalObject, constructorArgs = [], privateData = {}) {
1133
+ };
1134
+ exports.setup = function setup(obj, globalObject, constructorArgs = [], privateData = {}) {
1133
1135
privateData.wrapper = obj;
1134
1136
1135
- iface ._internalSetup(obj);
1137
+ exports ._internalSetup(obj);
1136
1138
Object.defineProperty(obj, impl, {
1137
1139
value: new Impl.implementation(globalObject, constructorArgs, privateData),
1138
1140
configurable: true
@@ -1149,7 +1151,7 @@ class Interface {
1149
1151
Impl.init(obj[impl], privateData);
1150
1152
}
1151
1153
return obj;
1152
- },
1154
+ };
1153
1155
` ;
1154
1156
}
1155
1157
@@ -1180,7 +1182,7 @@ class Interface {
1180
1182
1181
1183
body = `
1182
1184
${ conversions . body }
1183
- return iface .setup(${ formatArgs ( setupArgs ) } );
1185
+ return exports .setup(${ formatArgs ( setupArgs ) } );
1184
1186
` ;
1185
1187
} else {
1186
1188
body = `
@@ -1414,7 +1416,7 @@ class Interface {
1414
1416
const { idl, name } = this ;
1415
1417
1416
1418
this . str += `
1417
- install(globalObject) {
1419
+ exports.install = function install(globalObject) {
1418
1420
` ;
1419
1421
1420
1422
if ( idl . inheritance ) {
@@ -1444,26 +1446,17 @@ class Interface {
1444
1446
writable: true,
1445
1447
value: ${ name }
1446
1448
});
1447
- },
1449
+ };
1448
1450
` ;
1449
1451
}
1450
1452
1451
1453
generate ( ) {
1452
1454
this . generateIterator ( ) ;
1453
1455
1454
- this . str += `
1455
- const iface = {
1456
- ` ;
1457
-
1458
1456
this . generateExport ( ) ;
1459
1457
this . generateIface ( ) ;
1460
1458
this . generateInstall ( ) ;
1461
1459
1462
- this . str += `
1463
- }; // iface
1464
- module.exports = iface;
1465
- ` ;
1466
-
1467
1460
this . generateMixins ( ) ;
1468
1461
this . generateRequires ( ) ;
1469
1462
}
0 commit comments