Skip to content

Commit 15e36d3

Browse files
committed
Some basic fixes and spec updates
1 parent d5e52b6 commit 15e36d3

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

lib/constructs/interface.js

+14-19
Original file line numberDiff line numberDiff line change
@@ -83,52 +83,43 @@ Interface.prototype.generateNamedPropertiesObject = function () {
8383
}
8484

8585
let overrideBuiltins = false;
86-
const unforgeables = new Set();
8786
let parent = this.idl;
8887
while (parent) {
89-
if (utils.getExtAttr(parent.extAttrs, 'Unforgeable')) {
90-
unforgeables.add('valueOf').add('toString');
91-
}
9288
if (utils.getExtAttr(parent.extAttrs, 'OverrideBuiltins')) {
9389
overrideBuiltins = true;
9490
}
9591

9692
const members = parent.members.filter((m) =>
9793
m.type === 'attribute' && utils.getExtAttr(m.extAttrs, 'Unforgeable')
9894
);
99-
for (const member of members) {
100-
unforgeables.add(member.name);
101-
}
10295
const parentInterface = this.opts.interfaces[parent.inheritance];
10396
parent = parentInterface && parentInterface.idl;
10497
}
10598

10699
this.str += `
107100
function namedPropertiesIsVisible(P, O) {
108-
if (P of ${JSON.stringify(Array.from(unforgeables))}) {
101+
if (!true) { // is supported
109102
return false;
110103
}
111-
if (!supported) {
104+
105+
if (Object.getOwnPropertyDescriptor(O, P)) {
112106
return false;
113-
}`;
107+
}
108+
`;
114109

115110
if (overrideBuiltins) {
116111
this.str += `
117112
return true;`;
118-
} else {
119-
this.str += `
120-
if (Object.getOwnPropertyDescriptor(O, P)) {
121-
return false;
122113
}
123114

115+
this.str += `
124116
let prototype = Object.getPrototypeOf(O);
125117
while (prototype) {
126118
if (prototype.constructor.name.endsWith("PropertiesConstructor") && Object.getOwnPropertyDescriptor(prototype, P)) {
127119
return false;
128120
}
129121
prototype = Object.getPrototypeOf(prototype);
130122
}`;
131-
}
132123
this.str += `
133124
return true;
134125
}`;
@@ -139,9 +130,13 @@ function namedPropertiesIsVisible(P, O) {
139130

140131
if (this.idl.inheritance) {
141132
this.str += `${this.name}PropertiesConstructor.prototype = Object.create(${this.idl.inheritance}.interface.prototype);
133+
${this.name}PropertiesConstructor.prototype.constructor = ${this.name}PropertiesConstructor;\n`;
134+
} else if (utils.getExtAttr(this.idl.extAttrs, 'LegacyArrayClass')) {
135+
this.str += `${this.name}PropertiesConstructor.prototype = Object.create(Array.prototype);
142136
${this.name}PropertiesConstructor.prototype.constructor = ${this.name}PropertiesConstructor;\n`;
143137
}
144138

139+
const getter = this.idl.members.filter((m) => m.getter)[0].name;
145140
this.str += `
146141
const ${this.name}Properties = new Proxy(${this.name}PropertiesConstructor.prototype, {
147142
defineProperty() {
@@ -151,11 +146,11 @@ const ${this.name}Properties = new Proxy(${this.name}PropertiesConstructor.proto
151146
return false;
152147
},
153148
getOwnPropertyDescriptor(target, key) {
154-
if (true) { // is visible
149+
if (namedPropertiesIsVisible(key, target)) { // is visible
155150
const value = target${getter ? "." + getter : "[utils.anonymousGetter]"}(key);
156151
return {
157152
value,
158-
enumerable: ${legacyunenumerable ? "false" : "true"},
153+
enumerable: true,
159154
writable: true,
160155
configurable: true
161156
};
@@ -164,15 +159,15 @@ const ${this.name}Properties = new Proxy(${this.name}PropertiesConstructor.proto
164159
}
165160
},
166161
get(target, key) {
167-
if (true) { // is visible
162+
if (namedPropertiesIsVisible(key, target)) { // is visible
168163
const value = target${getter ? "." + getter : "[utils.anonymousGetter]"}(key);
169164
return value;
170165
} else {
171166
return target[key];
172167
}
173168
},
174169
has(target, key) {
175-
if (true) { // is visible
170+
if (namedPropertiesIsVisible(key, target)) { // is visible
176171
return true;
177172
} else {
178173
return key in target;

0 commit comments

Comments
 (0)