Skip to content

Commit

Permalink
update constructor name
Browse files Browse the repository at this point in the history
  • Loading branch information
pmdartus committed Oct 22, 2019
1 parent c8ca6cb commit f62a3b5
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 217 deletions.
22 changes: 10 additions & 12 deletions lib/constructs/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ class Interface {
this.ctx = ctx;
this.idl = idl;
this.name = idl.name;
this.sharedConstructorName = `Shared${this.name}`;

for (const member of this.idl.members) {
member.definingInterface = this.name;
}
Expand Down Expand Up @@ -1407,15 +1405,15 @@ class Interface {
}

generateInstall() {
const { idl, name, sharedConstructorName } = this;
const { idl, name } = this;

this.str += `
install(globalObject) {
`;

const ctor = this.getConstructor();
this.str += `
const ${name} = function(${formatArgs(ctor.argNames)}) {
const ctor = function ${name}(${formatArgs(ctor.argNames)}) {
${ctor.body}
};
`;
Expand All @@ -1426,7 +1424,7 @@ class Interface {
];
if (staticPropertyNames.length) {
this.str += `
Object.defineProperties(${name}, {
Object.defineProperties(ctor, {
`;

for (const staticProperty of staticPropertyNames) {
Expand All @@ -1436,7 +1434,7 @@ class Interface {
propertyKey.replace("[", "").replace("]", "") :
`"${propertyKey}"`;

this.str += `${propertyKey}: Object.getOwnPropertyDescriptor(${sharedConstructorName}, ${propertyValue}),\n`;
this.str += `${propertyKey}: Object.getOwnPropertyDescriptor(${name}, ${propertyValue}),\n`;
}

this.str += `
Expand Down Expand Up @@ -1464,14 +1462,14 @@ class Interface {
// newly created constructor.
this.str += `
Object.defineProperties(proto, {
...Object.getOwnPropertyDescriptors(${sharedConstructorName}.prototype),
...Object.getOwnPropertyDescriptors(${name}.prototype),
constructor: {
writable: true,
configurable: true,
value: ${name}
value: ctor
}
});
Object.defineProperty(${name}, "prototype", {
Object.defineProperty(ctor, "prototype", {
writable: false,
value: proto
});
Expand All @@ -1483,12 +1481,12 @@ class Interface {
if (globalObject[ctorRegistry] === undefined) {
globalObject[ctorRegistry] = {};
}
globalObject[ctorRegistry]["${name}"] = ${name};
globalObject[ctorRegistry]["${name}"] = ctor;
Object.defineProperty(globalObject, "${name}", {
configurable: true,
writable: true,
value: ${name}
value: ctor
});
},
`;
Expand All @@ -1497,7 +1495,7 @@ class Interface {
generate() {
this.generateIterator();

this.str += `class ${this.sharedConstructorName} {`;
this.str += `class ${this.name} {`;

this.generateOffInstanceMethods();

Expand Down
Loading

0 comments on commit f62a3b5

Please sign in to comment.