Skip to content

Commit fd2c9a0

Browse files
committed
Split out some bits in Interface to the prototype
1 parent b918798 commit fd2c9a0

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

lib/constructs/interface.js

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -502,54 +502,54 @@ class Interface {
502502
}
503503
}
504504

505+
_supportsPropertyIndex(O, index, indexedValue) {
506+
let unsupportedValue = utils.getExtAttr(this.indexedGetter.extAttrs, "WebIDL2JSValueAsUnsupported");
507+
if (unsupportedValue) {
508+
unsupportedValue = unsupportedValue.rhs.value;
509+
}
510+
if (unsupportedValue) {
511+
const func = this.indexedGetter.name !== null ? `.${this.indexedGetter.name}` : "[utils.indexedGet]";
512+
const value = indexedValue || `${O}[impl]${func}(${index})`;
513+
return `${value} !== ${unsupportedValue}`;
514+
}
515+
return `${O}[impl][utils.supportsPropertyIndex](${index})`;
516+
}
517+
518+
_supportsPropertyName(O, P, namedValue) {
519+
let unsupportedValue = utils.getExtAttr(this.namedGetter.extAttrs, "WebIDL2JSValueAsUnsupported");
520+
if (unsupportedValue) {
521+
unsupportedValue = unsupportedValue.rhs.value;
522+
}
523+
if (unsupportedValue) {
524+
const func = this.namedGetter.name !== null ? `.${this.namedGetter.name}` : "[utils.namedGet]";
525+
const value = namedValue || `${O}[impl]${func}(${P})`;
526+
return `${value} !== ${unsupportedValue}`;
527+
}
528+
return `${O}[impl][utils.supportsPropertyName](${P})`;
529+
}
530+
531+
// "named property visibility algorithm"
532+
// If `supports` is true then skip the supportsPropertyName check.
533+
_namedPropertyVisible(P, O, supports = false) {
534+
const conditions = [];
535+
if (!supports) {
536+
conditions.push(this._supportsPropertyName(O, P));
537+
}
538+
if (utils.getExtAttr(this.idl.extAttrs, "OverrideBuiltins")) {
539+
conditions.push(`!utils.hasOwn(${O}, ${P})`);
540+
} else {
541+
// TODO: create a named properties object.
542+
conditions.push(`!(${P} in ${O})`);
543+
}
544+
return conditions.join(" && ");
545+
}
546+
505547
generateLegacyProxy() {
506548
const hasIndexedSetter = this.indexedSetter !== null;
507549
const hasNamedSetter = this.namedSetter !== null;
508550
const hasNamedDeleter = this.namedDeleter !== null;
509551
const overrideBuiltins = Boolean(utils.getExtAttr(this.idl.extAttrs, "OverrideBuiltins"));
510552

511-
const supportsPropertyIndex = (O, index, indexedValue) => {
512-
let unsupportedValue = utils.getExtAttr(this.indexedGetter.extAttrs, "WebIDL2JSValueAsUnsupported");
513-
if (unsupportedValue) {
514-
unsupportedValue = unsupportedValue.rhs.value;
515-
}
516-
if (unsupportedValue) {
517-
const func = this.indexedGetter.name !== null ? `.${this.indexedGetter.name}` : "[utils.indexedGet]";
518-
const value = indexedValue || `${O}[impl]${func}(${index})`;
519-
return `${value} !== ${unsupportedValue}`;
520-
}
521-
return `${O}[impl][utils.supportsPropertyIndex](${index})`;
522-
};
523-
524-
const supportsPropertyName = (O, P, namedValue) => {
525-
let unsupportedValue = utils.getExtAttr(this.namedGetter.extAttrs, "WebIDL2JSValueAsUnsupported");
526-
if (unsupportedValue) {
527-
unsupportedValue = unsupportedValue.rhs.value;
528-
}
529-
if (unsupportedValue) {
530-
const func = this.namedGetter.name !== null ? `.${this.namedGetter.name}` : "[utils.namedGet]";
531-
const value = namedValue || `${O}[impl]${func}(${P})`;
532-
return `${value} !== ${unsupportedValue}`;
533-
}
534-
return `${O}[impl][utils.supportsPropertyName](${P})`;
535-
};
536-
537-
// "named property visibility algorithm"
538-
// If `supports` is true then skip the supportsPropertyName check.
539-
function namedPropertyVisible(P, O, supports = false) {
540-
const conditions = [];
541-
if (!supports) {
542-
conditions.push(supportsPropertyName(O, P));
543-
}
544-
if (overrideBuiltins) {
545-
conditions.push(`!utils.hasOwn(${O}, ${P})`);
546-
} else {
547-
// TODO: create a named properties object.
548-
conditions.push(`!(${P} in ${O})`);
549-
}
550-
return conditions.join(" && ");
551-
}
552-
553553
// "invoke an indexed property setter"
554554
const invokeIndexedSetter = (O, P, V) => {
555555
const arg = this.indexedSetter.arguments[1];
@@ -566,7 +566,7 @@ class Interface {
566566

567567
if (this.indexedSetter.name === null) {
568568
str += `
569-
const creating = !(${supportsPropertyIndex(O, "index")});
569+
const creating = !(${this._supportsPropertyIndex(O, "index")});
570570
if (creating) {
571571
${O}[impl][utils.indexedSetNew](index, indexedValue);
572572
} else {
@@ -597,7 +597,7 @@ class Interface {
597597

598598
if (this.namedSetter.name === null) {
599599
str += `
600-
const creating = !(${supportsPropertyName(O, P)});
600+
const creating = !(${this._supportsPropertyName(O, P)});
601601
if (creating) {
602602
${O}[impl][utils.namedSetNew](${P}, namedValue);
603603
} else {
@@ -677,7 +677,7 @@ class Interface {
677677
if (this.supportsNamedProperties) {
678678
this.str += `
679679
for (const key of target[impl][utils.supportedPropertyNames]) {
680-
if (${namedPropertyVisible("key", "target", true)}) {
680+
if (${this._namedPropertyVisible("key", "target", true)}) {
681681
keys.add(\`\${key}\`);
682682
}
683683
}
@@ -710,10 +710,10 @@ class Interface {
710710
let condition;
711711
if (utils.getExtAttr(this.indexedGetter.extAttrs, "WebIDL2JSValueAsUnsupported")) {
712712
this.str += `const indexedValue = target[impl]${func}(index);`;
713-
condition = supportsPropertyIndex("target", "index", "indexedValue");
713+
condition = this._supportsPropertyIndex("target", "index", "indexedValue");
714714
} else {
715715
preamble = `const indexedValue = target[impl]${func}(index);`;
716-
condition = supportsPropertyIndex("target", "index");
716+
condition = this._supportsPropertyIndex("target", "index");
717717
}
718718

719719
this.str += `
@@ -739,13 +739,13 @@ class Interface {
739739
this.str += `
740740
const namedValue = target[impl]${func}(P);
741741
`;
742-
conditions.push(supportsPropertyName("target", "index", "namedValue"));
743-
conditions.push(namedPropertyVisible("P", "target", true));
742+
conditions.push(this._supportsPropertyName("target", "index", "namedValue"));
743+
conditions.push(this._namedPropertyVisible("P", "target", true));
744744
} else {
745745
preamble = `
746746
const namedValue = target[impl]${func}(P);
747747
`;
748-
conditions.push(namedPropertyVisible("P", "target", false));
748+
conditions.push(this._namedPropertyVisible("P", "target", false));
749749
}
750750
conditions.push("!ignoreNamedProps");
751751
this.str += `
@@ -820,10 +820,10 @@ class Interface {
820820
let condition;
821821
if (utils.getExtAttr(this.indexedGetter.extAttrs, "WebIDL2JSValueAsUnsupported")) {
822822
this.str += `const indexedValue = target[impl]${func}(index);`;
823-
condition = supportsPropertyIndex("target", "index", "indexedValue");
823+
condition = this._supportsPropertyIndex("target", "index", "indexedValue");
824824
} else {
825825
preamble = `const indexedValue = target[impl]${func}(index);`;
826-
condition = supportsPropertyIndex("target", "index");
826+
condition = this._supportsPropertyIndex("target", "index");
827827
}
828828

829829
this.str += `
@@ -922,7 +922,7 @@ class Interface {
922922
if (!hasNamedSetter) {
923923
needFallback = true;
924924
this.str += `
925-
const creating = !(${supportsPropertyName("target", "P")});
925+
const creating = !(${this._supportsPropertyName("target", "P")});
926926
if (!creating) {
927927
return false;
928928
}
@@ -972,13 +972,13 @@ class Interface {
972972
this.str += `
973973
if (utils.isArrayIndexPropName(P)) {
974974
const index = P >>> 0;
975-
return !(${supportsPropertyIndex("target", "index")});
975+
return !(${this._supportsPropertyIndex("target", "index")});
976976
}
977977
`;
978978
}
979979
if (this.supportsNamedProperties && !utils.isGlobal(this.idl)) {
980980
this.str += `
981-
if (${namedPropertyVisible("P", "target")}) {
981+
if (${this._namedPropertyVisible("P", "target")}) {
982982
`;
983983
if (!hasNamedDeleter) {
984984
this.str += `

0 commit comments

Comments
 (0)