@@ -32,52 +32,43 @@ Interface.prototype.generateNamedPropertiesObject = function () {
3232 }
3333
3434 let overrideBuiltins = false ;
35- const unforgeables = new Set ( ) ;
3635 let parent = this . idl ;
3736 while ( parent ) {
38- if ( utils . getExtAttr ( parent . extAttrs , 'Unforgeable' ) ) {
39- unforgeables . add ( 'valueOf' ) . add ( 'toString' ) ;
40- }
4137 if ( utils . getExtAttr ( parent . extAttrs , 'OverrideBuiltins' ) ) {
4238 overrideBuiltins = true ;
4339 }
4440
4541 const members = parent . members . filter ( ( m ) =>
4642 m . type === 'attribute' && utils . getExtAttr ( m . extAttrs , 'Unforgeable' )
4743 ) ;
48- for ( const member of members ) {
49- unforgeables . add ( member . name ) ;
50- }
5144 const parentInterface = this . opts . interfaces [ parent . inheritance ] ;
5245 parent = parentInterface && parentInterface . idl ;
5346 }
5447
5548 this . str += `
5649function namedPropertiesIsVisible(P, O) {
57- if (P of ${ JSON . stringify ( Array . from ( unforgeables ) ) } ) {
50+ if (!true) { // is supported
5851 return false;
5952 }
60- if (!supported) {
53+
54+ if (Object.getOwnPropertyDescriptor(O, P)) {
6155 return false;
62- }` ;
56+ }
57+ ` ;
6358
6459 if ( overrideBuiltins ) {
6560 this . str += `
6661 return true;` ;
67- } else {
68- this . str += `
69- if (Object.getOwnPropertyDescriptor(O, P)) {
70- return false;
7162 }
7263
64+ this . str += `
7365 let prototype = Object.getPrototypeOf(O);
7466 while (prototype) {
7567 if (prototype.constructor.name.endsWith("PropertiesConstructor") && Object.getOwnPropertyDescriptor(prototype, P)) {
7668 return false;
7769 }
7870 prototype = Object.getPrototypeOf(prototype);
7971 }` ;
80- }
8172 this . str += `
8273 return true;
8374}` ;
@@ -88,9 +79,13 @@ function namedPropertiesIsVisible(P, O) {
8879
8980 if ( this . idl . inheritance ) {
9081 this . str += `${ this . name } PropertiesConstructor.prototype = Object.create(${ this . idl . inheritance } .interface.prototype);
82+ ${ this . name } PropertiesConstructor.prototype.constructor = ${ this . name } PropertiesConstructor;\n`;
83+ } else if ( utils . getExtAttr ( this . idl . extAttrs , 'LegacyArrayClass' ) ) {
84+ this . str += `${ this . name } PropertiesConstructor.prototype = Object.create(Array.prototype);
9185${ this . name } PropertiesConstructor.prototype.constructor = ${ this . name } PropertiesConstructor;\n`;
9286 }
9387
88+ const getter = this . idl . members . filter ( ( m ) => m . getter ) [ 0 ] . name ;
9489 this . str += `
9590const ${ this . name } Properties = new Proxy(${ this . name } PropertiesConstructor.prototype, {
9691 defineProperty() {
@@ -100,11 +95,11 @@ const ${this.name}Properties = new Proxy(${this.name}PropertiesConstructor.proto
10095 return false;
10196 },
10297 getOwnPropertyDescriptor(target, key) {
103- if (true ) { // is visible
98+ if (namedPropertiesIsVisible(key, target) ) { // is visible
10499 const value = target${ getter ? "." + getter : "[utils.anonymousGetter]" } (key);
105100 return {
106101 value,
107- enumerable: ${ legacyunenumerable ? "false" : " true" } ,
102+ enumerable: true,
108103 writable: true,
109104 configurable: true
110105 };
@@ -113,15 +108,15 @@ const ${this.name}Properties = new Proxy(${this.name}PropertiesConstructor.proto
113108 }
114109 },
115110 get(target, key) {
116- if (true ) { // is visible
111+ if (namedPropertiesIsVisible(key, target) ) { // is visible
117112 const value = target${ getter ? "." + getter : "[utils.anonymousGetter]" } (key);
118113 return value;
119114 } else {
120115 return target[key];
121116 }
122117 },
123118 has(target, key) {
124- if (true ) { // is visible
119+ if (namedPropertiesIsVisible(key, target) ) { // is visible
125120 return true;
126121 } else {
127122 return key in target;
0 commit comments