@@ -501,6 +501,9 @@ class Interface {
501
501
generateRequires ( ) {
502
502
this . requires . addRaw ( "impl" , "utils.implSymbol" ) ;
503
503
this . requires . addRaw ( "ctorRegistry" , "utils.ctorRegistrySymbol" ) ;
504
+ this . requires . addRaw ( "wrapperSymbol" , "utils.wrapperSymbol" ) ;
505
+ this . requires . addRaw ( "globalObjectSymbol" , "utils.globalObjectSymbol" ) ;
506
+ this . requires . addRaw ( "createWrapperSymbol" , "utils.createWrapperSymbol" ) ;
504
507
505
508
if ( this . idl . inheritance !== null ) {
506
509
this . requires . add ( this . idl . inheritance ) ;
@@ -1126,7 +1129,9 @@ class Interface {
1126
1129
1127
1130
generateIface ( ) {
1128
1131
this . str += `
1129
- exports.create = function create(globalObject, constructorArgs, privateData) {
1132
+ function createWrapper(implObject) {
1133
+ const globalObject = implObject[globalObjectSymbol];
1134
+
1130
1135
if (globalObject[ctorRegistry] === undefined) {
1131
1136
throw new Error('Internal error: invalid global object');
1132
1137
}
@@ -1136,49 +1141,55 @@ class Interface {
1136
1141
throw new Error('Internal error: constructor ${ this . name } is not installed on the passed global object');
1137
1142
}
1138
1143
1139
- let obj = Object.create(ctor.prototype);
1140
- obj = exports.setup(obj, globalObject, constructorArgs, privateData);
1141
- return obj;
1142
- };
1143
- exports.createImpl = function createImpl(globalObject, constructorArgs, privateData) {
1144
- const obj = exports.create(globalObject, constructorArgs, privateData);
1145
- return utils.implForWrapper(obj);
1146
- };
1147
- exports._internalSetup = function _internalSetup(obj) {
1144
+ let wrapperObject = Object.create(ctor.prototype);
1145
+ exports._internalSetup(wrapperObject);
1148
1146
` ;
1149
1147
1150
- if ( this . idl . inheritance ) {
1148
+ if ( this . isLegacyPlatformObj ) {
1151
1149
this . str += `
1152
- ${ this . idl . inheritance } ._internalSetup(obj );
1150
+ wrapperObject = new Proxy(wrapperObject, proxyHandler );
1153
1151
` ;
1154
1152
}
1155
1153
1156
- this . generateOnInstance ( ) ;
1157
-
1158
1154
this . str += `
1155
+ implObject[wrapperSymbol] = wrapperObject;
1156
+ wrapperObject[impl] = implObject;
1157
+ return wrapperObject;
1159
1158
};
1160
- exports.setup = function setup(obj, globalObject, constructorArgs = [], privateData = {}) {
1161
- privateData.wrapper = obj;
1159
+ exports.create = function create(globalObject, constructorArgs, privateData) {
1160
+ const implObject = exports.createImpl(globalObject, constructorArgs, privateData);
1161
+ return utils.wrapperForImpl(implObject);
1162
+ };
1163
+ exports.createImpl = function createImpl(globalObject, constructorArgs = [], privateData = {}) {
1164
+ const implObject = new Impl.implementation(globalObject, constructorArgs, privateData);
1162
1165
1163
- exports._internalSetup(obj);
1164
- Object.defineProperty(obj, impl, {
1165
- value: new Impl.implementation(globalObject, constructorArgs, privateData),
1166
- configurable: true
1167
- });
1166
+ implObject[wrapperSymbol] = null;
1167
+ implObject[globalObjectSymbol] = globalObject;
1168
+ implObject[createWrapperSymbol] = createWrapper;
1169
+
1170
+ return implObject;
1171
+ };
1172
+ exports.setup = function setup(wrapperObject, globalObject, constructorArgs = [], privateData = {}) {
1173
+ const implObject = exports.createImpl(globalObject, constructorArgs, privateData);
1174
+
1175
+ implObject[wrapperSymbol] = wrapperObject;
1176
+ wrapperObject[impl] = implObject;
1177
+
1178
+ exports._internalSetup(wrapperObject);
1179
+
1180
+ return wrapperObject;
1181
+ };
1182
+ exports._internalSetup = function _internalSetup(obj) {
1168
1183
` ;
1169
1184
1170
- if ( this . isLegacyPlatformObj ) {
1185
+ if ( this . idl . inheritance ) {
1171
1186
this . str += `
1172
- obj = new Proxy (obj, proxyHandler );
1187
+ ${ this . idl . inheritance } ._internalSetup (obj);
1173
1188
` ;
1174
1189
}
1190
+ this . generateOnInstance ( ) ;
1175
1191
1176
1192
this . str += `
1177
- obj[impl][utils.wrapperSymbol] = obj;
1178
- if (Impl.init) {
1179
- Impl.init(obj[impl], privateData);
1180
- }
1181
- return obj;
1182
1193
};
1183
1194
` ;
1184
1195
}
0 commit comments