Skip to content

Commit 108f608

Browse files
committed
refactor: Rename imported symbols
1 parent 2a2a099 commit 108f608

File tree

6 files changed

+999
-1062
lines changed

6 files changed

+999
-1062
lines changed

lib/constructs/attribute.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ class Attribute {
2828
throw new TypeError("Illegal invocation");
2929
}
3030
`;
31-
let getterBody = `return utils.tryWrapperForImpl(esValue[impl]["${this.idl.name}"]);`;
32-
let setterBody = `esValue[impl]["${this.idl.name}"] = V;`;
31+
let getterBody = `return utils.tryWrapperForImpl(esValue[implSymbol]["${this.idl.name}"]);`;
32+
let setterBody = `esValue[implSymbol]["${this.idl.name}"] = V;`;
3333
if (conversions[this.idl.idlType.idlType]) {
34-
getterBody = `return esValue[impl]["${this.idl.name}"];`;
34+
getterBody = `return esValue[implSymbol]["${this.idl.name}"];`;
3535
}
3636

3737
const addMethod = this.static ?

lib/constructs/interface.js

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ class Interface {
413413
value: function next() {
414414
const internal = this[utils.iterInternalSymbol];
415415
const { target, kind, index } = internal;
416-
const values = Array.from(target[impl]);
416+
const values = Array.from(target[implSymbol]);
417417
const len = values.length;
418418
if (index >= len) {
419419
return { value: undefined, done: true };
@@ -492,8 +492,7 @@ class Interface {
492492
}
493493

494494
generateRequires() {
495-
this.requires.addRaw("impl", "utils.implSymbol");
496-
this.requires.addRaw("ctorRegistry", "utils.ctorRegistrySymbol");
495+
this.requires.addRaw(`{ implSymbol, ctorRegistrySymbol }`, "utils");
497496

498497
if (this.idl.inheritance !== null) {
499498
this.requires.add(this.idl.inheritance);
@@ -509,7 +508,7 @@ class Interface {
509508
generateExport() {
510509
this.str += `
511510
exports.is = function is(obj) {
512-
return utils.isObject(obj) && utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation;
511+
return utils.isObject(obj) && utils.hasOwn(obj, impl) && obj[implSymbol] instanceof Impl.implementation;
513512
};
514513
exports.isImpl = function isImpl(obj) {
515514
return utils.isObject(obj) && obj instanceof Impl.implementation;
@@ -549,10 +548,10 @@ class Interface {
549548
}
550549
if (unsupportedValue) {
551550
const func = this.indexedGetter.name ? `.${this.indexedGetter.name}` : "[utils.indexedGet]";
552-
const value = indexedValue || `${O}[impl]${func}(${index})`;
551+
const value = indexedValue || `${O}[implSymbol]${func}(${index})`;
553552
return `${value} !== ${unsupportedValue}`;
554553
}
555-
return `${O}[impl][utils.supportsPropertyIndex](${index})`;
554+
return `${O}[implSymbol][utils.supportsPropertyIndex](${index})`;
556555
};
557556

558557
const supportsPropertyName = (O, P, namedValue) => {
@@ -562,10 +561,10 @@ class Interface {
562561
}
563562
if (unsupportedValue) {
564563
const func = this.namedGetter.name ? `.${this.namedGetter.name}` : "[utils.namedGet]";
565-
const value = namedValue || `${O}[impl]${func}(${P})`;
564+
const value = namedValue || `${O}[implSymbol]${func}(${P})`;
566565
return `${value} !== ${unsupportedValue}`;
567566
}
568-
return `${O}[impl][utils.supportsPropertyName](${P})`;
567+
return `${O}[implSymbol][utils.supportsPropertyName](${P})`;
569568
};
570569

571570
// "named property visibility algorithm"
@@ -603,14 +602,14 @@ class Interface {
603602
invocation = `
604603
const creating = !(${supportsPropertyIndex(O, "index")});
605604
if (creating) {
606-
${O}[impl][utils.indexedSetNew](index, indexedValue);
605+
${O}[implSymbol][utils.indexedSetNew](index, indexedValue);
607606
} else {
608-
${O}[impl][utils.indexedSetExisting](index, indexedValue);
607+
${O}[implSymbol][utils.indexedSetExisting](index, indexedValue);
609608
}
610609
`;
611610
} else {
612611
invocation = `
613-
${O}[impl].${this.indexedSetter.name}(index, indexedValue);
612+
${O}[implSymbol].${this.indexedSetter.name}(index, indexedValue);
614613
`;
615614
}
616615

@@ -641,14 +640,14 @@ class Interface {
641640
invocation = `
642641
const creating = !(${supportsPropertyName(O, P)});
643642
if (creating) {
644-
${O}[impl][utils.namedSetNew](${P}, namedValue);
643+
${O}[implSymbol][utils.namedSetNew](${P}, namedValue);
645644
} else {
646-
${O}[impl][utils.namedSetExisting](${P}, namedValue);
645+
${O}[implSymbol][utils.namedSetExisting](${P}, namedValue);
647646
}
648647
`;
649648
} else {
650649
invocation = `
651-
${O}[impl].${this.namedSetter.name}(${P}, namedValue);
650+
${O}[implSymbol].${this.namedSetter.name}(${P}, namedValue);
652651
`;
653652
}
654653

@@ -729,14 +728,14 @@ class Interface {
729728
`;
730729
if (this.supportsIndexedProperties) {
731730
this.str += `
732-
for (const key of target[impl][utils.supportedPropertyIndices]) {
731+
for (const key of target[implSymbol][utils.supportedPropertyIndices]) {
733732
keys.add(\`\${key}\`);
734733
}
735734
`;
736735
}
737736
if (this.supportsNamedProperties) {
738737
this.str += `
739-
for (const key of target[impl][utils.supportedPropertyNames]) {
738+
for (const key of target[implSymbol][utils.supportedPropertyNames]) {
740739
if (${namedPropertyVisible("key", "target", true)}) {
741740
keys.add(\`\${key}\`);
742741
}
@@ -769,10 +768,10 @@ class Interface {
769768
let preamble = "";
770769
let condition;
771770
if (utils.getExtAttr(this.indexedGetter.extAttrs, "WebIDL2JSValueAsUnsupported")) {
772-
this.str += `const indexedValue = target[impl]${func}(index);`;
771+
this.str += `const indexedValue = target[implSymbol]${func}(index);`;
773772
condition = supportsPropertyIndex("target", "index", "indexedValue");
774773
} else {
775-
preamble = `const indexedValue = target[impl]${func}(index);`;
774+
preamble = `const indexedValue = target[implSymbol]${func}(index);`;
776775
condition = supportsPropertyIndex("target", "index");
777776
}
778777

@@ -797,13 +796,13 @@ class Interface {
797796
const conditions = [];
798797
if (utils.getExtAttr(this.namedGetter.extAttrs, "WebIDL2JSValueAsUnsupported")) {
799798
this.str += `
800-
const namedValue = target[impl]${func}(P);
799+
const namedValue = target[implSymbol]${func}(P);
801800
`;
802801
conditions.push(supportsPropertyName("target", "index", "namedValue"));
803802
conditions.push(namedPropertyVisible("P", "target", true));
804803
} else {
805804
preamble = `
806-
const namedValue = target[impl]${func}(P);
805+
const namedValue = target[implSymbol]${func}(P);
807806
`;
808807
conditions.push(namedPropertyVisible("P", "target", false));
809808
}
@@ -885,10 +884,10 @@ class Interface {
885884
let preamble = "";
886885
let condition;
887886
if (utils.getExtAttr(this.indexedGetter.extAttrs, "WebIDL2JSValueAsUnsupported")) {
888-
this.str += `const indexedValue = target[impl]${func}(index);`;
887+
this.str += `const indexedValue = target[implSymbol]${func}(index);`;
889888
condition = supportsPropertyIndex("target", "index", "indexedValue");
890889
} else {
891-
preamble = `const indexedValue = target[impl]${func}(index);`;
890+
preamble = `const indexedValue = target[implSymbol]${func}(index);`;
892891
condition = supportsPropertyIndex("target", "index");
893892
}
894893

@@ -1070,11 +1069,11 @@ class Interface {
10701069

10711070
if (this.namedDeleter.idlType.idlType === "bool") {
10721071
invocation = `
1073-
return target[impl]${func}(P);
1072+
return target[implSymbol]${func}(P);
10741073
`;
10751074
} else {
10761075
invocation = `
1077-
target[impl]${func}(P);
1076+
target[implSymbol]${func}(P);
10781077
return true;
10791078
`;
10801079
}
@@ -1111,11 +1110,11 @@ class Interface {
11111110
generateIface() {
11121111
this.str += `
11131112
exports.create = function create(globalObject, constructorArgs, privateData) {
1114-
if (globalObject[ctorRegistry] === undefined) {
1113+
if (globalObject[ctorRegistrySymbol] === undefined) {
11151114
throw new Error('Internal error: invalid global object');
11161115
}
11171116
1118-
const ctor = globalObject[ctorRegistry]["${this.name}"];
1117+
const ctor = globalObject[ctorRegistrySymbol]["${this.name}"];
11191118
if (ctor === undefined) {
11201119
throw new Error('Internal error: constructor ${this.name} is not installed on the passed global object');
11211120
}
@@ -1171,9 +1170,9 @@ class Interface {
11711170
}
11721171

11731172
this.str += `
1174-
obj[impl][utils.wrapperSymbol] = obj;
1173+
obj[implSymbol][utils.wrapperSymbol] = obj;
11751174
if (Impl.init) {
1176-
Impl.init(obj[impl], privateData);
1175+
Impl.init(obj[implSymbol], privateData);
11771176
}
11781177
return obj;
11791178
};
@@ -1467,10 +1466,10 @@ class Interface {
14671466
this.generateOffInstanceAfterClass();
14681467

14691468
this.str += `
1470-
if (globalObject[ctorRegistry] === undefined) {
1471-
globalObject[ctorRegistry] = Object.create(null);
1469+
if (globalObject[ctorRegistrySymbol] === undefined) {
1470+
globalObject[ctorRegistrySymbol] = Object.create(null);
14721471
}
1473-
globalObject[ctorRegistry][interfaceName] = ${name};
1472+
globalObject[ctorRegistrySymbol][interfaceName] = ${name};
14741473
14751474
Object.defineProperty(globalObject, interfaceName, {
14761475
configurable: true,

lib/constructs/iterable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ class Iterable {
4747
"as parameter 1 is not a function.");
4848
}
4949
const thisArg = arguments[1];
50-
let pairs = Array.from(this[impl]);
50+
let pairs = Array.from(this[implSymbol]);
5151
let i = 0;
5252
while (i < pairs.length) {
5353
const [key, value] = pairs[i].map(utils.tryWrapperForImpl);
5454
callback.call(thisArg, value, key, this);
55-
pairs = Array.from(this[impl]);
55+
pairs = Array.from(this[implSymbol]);
5656
i++;
5757
}
5858
`);

lib/constructs/operation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Operation {
6969
`;
7070
}
7171

72-
const callOn = this.static ? "Impl.implementation" : `esValue[impl]`;
72+
const callOn = this.static ? "Impl.implementation" : `esValue[implSymbol]`;
7373
// In case of stringifiers, use the named implementation function rather than hardcoded "toString".
7474
// All overloads will have the same name, so pick the first one.
7575
const implFunc = this.idls[0].name || this.name;

lib/reflector.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
module.exports.boolean = {
44
get(objName, attrName) {
5-
return `return this[impl].hasAttributeNS(null, "${attrName}");`;
5+
return `return this[implSymbol].hasAttributeNS(null, "${attrName}");`;
66
},
77
set(objName, attrName) {
88
return `
99
if (V) {
10-
this[impl].setAttributeNS(null, "${attrName}", "");
10+
this[implSymbol].setAttributeNS(null, "${attrName}", "");
1111
} else {
12-
this[impl].removeAttributeNS(null, "${attrName}");
12+
this[implSymbol].removeAttributeNS(null, "${attrName}");
1313
}
1414
`;
1515
}
@@ -18,35 +18,35 @@ module.exports.boolean = {
1818
module.exports.DOMString = {
1919
get(objName, attrName) {
2020
return `
21-
const value = this[impl].getAttributeNS(null, "${attrName}");
21+
const value = this[implSymbol].getAttributeNS(null, "${attrName}");
2222
return value === null ? "" : value;
2323
`;
2424
},
2525
set(objName, attrName) {
26-
return `this[impl].setAttributeNS(null, "${attrName}", V);`;
26+
return `this[implSymbol].setAttributeNS(null, "${attrName}", V);`;
2727
}
2828
};
2929

3030
module.exports.long = {
3131
get(objName, attrName) {
3232
return `
33-
const value = parseInt(this[impl].getAttributeNS(null, "${attrName}"));
33+
const value = parseInt(this[implSymbol].getAttributeNS(null, "${attrName}"));
3434
return isNaN(value) || value < -2147483648 || value > 2147483647 ? 0 : value
3535
`;
3636
},
3737
set(objName, attrName) {
38-
return `this[impl].setAttributeNS(null, "${attrName}", String(V));`;
38+
return `this[implSymbol].setAttributeNS(null, "${attrName}", String(V));`;
3939
}
4040
};
4141

4242
module.exports["unsigned long"] = {
4343
get(objName, attrName) {
4444
return `
45-
const value = parseInt(this[impl].getAttributeNS(null, "${attrName}"));
45+
const value = parseInt(this[implSymbol].getAttributeNS(null, "${attrName}"));
4646
return isNaN(value) || value < 0 || value > 2147483647 ? 0 : value
4747
`;
4848
},
4949
set(objName, attrName) {
50-
return `this[impl].setAttributeNS(null, "${attrName}", String(V > 2147483647 ? 0 : V));`;
50+
return `this[implSymbol].setAttributeNS(null, "${attrName}", String(V > 2147483647 ? 0 : V));`;
5151
}
5252
};

0 commit comments

Comments
 (0)