@@ -83,52 +83,43 @@ Interface.prototype.generateNamedPropertiesObject = function () {
83
83
}
84
84
85
85
let overrideBuiltins = false ;
86
- const unforgeables = new Set ( ) ;
87
86
let parent = this . idl ;
88
87
while ( parent ) {
89
- if ( utils . getExtAttr ( parent . extAttrs , 'Unforgeable' ) ) {
90
- unforgeables . add ( 'valueOf' ) . add ( 'toString' ) ;
91
- }
92
88
if ( utils . getExtAttr ( parent . extAttrs , 'OverrideBuiltins' ) ) {
93
89
overrideBuiltins = true ;
94
90
}
95
91
96
92
const members = parent . members . filter ( ( m ) =>
97
93
m . type === 'attribute' && utils . getExtAttr ( m . extAttrs , 'Unforgeable' )
98
94
) ;
99
- for ( const member of members ) {
100
- unforgeables . add ( member . name ) ;
101
- }
102
95
const parentInterface = this . opts . interfaces [ parent . inheritance ] ;
103
96
parent = parentInterface && parentInterface . idl ;
104
97
}
105
98
106
99
this . str += `
107
100
function namedPropertiesIsVisible(P, O) {
108
- if (P of ${ JSON . stringify ( Array . from ( unforgeables ) ) } ) {
101
+ if (!true) { // is supported
109
102
return false;
110
103
}
111
- if (!supported) {
104
+
105
+ if (Object.getOwnPropertyDescriptor(O, P)) {
112
106
return false;
113
- }` ;
107
+ }
108
+ ` ;
114
109
115
110
if ( overrideBuiltins ) {
116
111
this . str += `
117
112
return true;` ;
118
- } else {
119
- this . str += `
120
- if (Object.getOwnPropertyDescriptor(O, P)) {
121
- return false;
122
113
}
123
114
115
+ this . str += `
124
116
let prototype = Object.getPrototypeOf(O);
125
117
while (prototype) {
126
118
if (prototype.constructor.name.endsWith("PropertiesConstructor") && Object.getOwnPropertyDescriptor(prototype, P)) {
127
119
return false;
128
120
}
129
121
prototype = Object.getPrototypeOf(prototype);
130
122
}` ;
131
- }
132
123
this . str += `
133
124
return true;
134
125
}` ;
@@ -139,9 +130,13 @@ function namedPropertiesIsVisible(P, O) {
139
130
140
131
if ( this . idl . inheritance ) {
141
132
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);
142
136
${ this . name } PropertiesConstructor.prototype.constructor = ${ this . name } PropertiesConstructor;\n`;
143
137
}
144
138
139
+ const getter = this . idl . members . filter ( ( m ) => m . getter ) [ 0 ] . name ;
145
140
this . str += `
146
141
const ${ this . name } Properties = new Proxy(${ this . name } PropertiesConstructor.prototype, {
147
142
defineProperty() {
@@ -151,11 +146,11 @@ const ${this.name}Properties = new Proxy(${this.name}PropertiesConstructor.proto
151
146
return false;
152
147
},
153
148
getOwnPropertyDescriptor(target, key) {
154
- if (true ) { // is visible
149
+ if (namedPropertiesIsVisible(key, target) ) { // is visible
155
150
const value = target${ getter ? "." + getter : "[utils.anonymousGetter]" } (key);
156
151
return {
157
152
value,
158
- enumerable: ${ legacyunenumerable ? "false" : " true" } ,
153
+ enumerable: true,
159
154
writable: true,
160
155
configurable: true
161
156
};
@@ -164,15 +159,15 @@ const ${this.name}Properties = new Proxy(${this.name}PropertiesConstructor.proto
164
159
}
165
160
},
166
161
get(target, key) {
167
- if (true ) { // is visible
162
+ if (namedPropertiesIsVisible(key, target) ) { // is visible
168
163
const value = target${ getter ? "." + getter : "[utils.anonymousGetter]" } (key);
169
164
return value;
170
165
} else {
171
166
return target[key];
172
167
}
173
168
},
174
169
has(target, key) {
175
- if (true ) { // is visible
170
+ if (namedPropertiesIsVisible(key, target) ) { // is visible
176
171
return true;
177
172
} else {
178
173
return key in target;
0 commit comments