@@ -32,52 +32,43 @@ Interface.prototype.generateNamedPropertiesObject = function () {
32
32
}
33
33
34
34
let overrideBuiltins = false ;
35
- const unforgeables = new Set ( ) ;
36
35
let parent = this . idl ;
37
36
while ( parent ) {
38
- if ( utils . getExtAttr ( parent . extAttrs , 'Unforgeable' ) ) {
39
- unforgeables . add ( 'valueOf' ) . add ( 'toString' ) ;
40
- }
41
37
if ( utils . getExtAttr ( parent . extAttrs , 'OverrideBuiltins' ) ) {
42
38
overrideBuiltins = true ;
43
39
}
44
40
45
41
const members = parent . members . filter ( ( m ) =>
46
42
m . type === 'attribute' && utils . getExtAttr ( m . extAttrs , 'Unforgeable' )
47
43
) ;
48
- for ( const member of members ) {
49
- unforgeables . add ( member . name ) ;
50
- }
51
44
const parentInterface = this . opts . interfaces [ parent . inheritance ] ;
52
45
parent = parentInterface && parentInterface . idl ;
53
46
}
54
47
55
48
this . str += `
56
49
function namedPropertiesIsVisible(P, O) {
57
- if (P of ${ JSON . stringify ( Array . from ( unforgeables ) ) } ) {
50
+ if (!true) { // is supported
58
51
return false;
59
52
}
60
- if (!supported) {
53
+
54
+ if (Object.getOwnPropertyDescriptor(O, P)) {
61
55
return false;
62
- }` ;
56
+ }
57
+ ` ;
63
58
64
59
if ( overrideBuiltins ) {
65
60
this . str += `
66
61
return true;` ;
67
- } else {
68
- this . str += `
69
- if (Object.getOwnPropertyDescriptor(O, P)) {
70
- return false;
71
62
}
72
63
64
+ this . str += `
73
65
let prototype = Object.getPrototypeOf(O);
74
66
while (prototype) {
75
67
if (prototype.constructor.name.endsWith("PropertiesConstructor") && Object.getOwnPropertyDescriptor(prototype, P)) {
76
68
return false;
77
69
}
78
70
prototype = Object.getPrototypeOf(prototype);
79
71
}` ;
80
- }
81
72
this . str += `
82
73
return true;
83
74
}` ;
@@ -88,9 +79,13 @@ function namedPropertiesIsVisible(P, O) {
88
79
89
80
if ( this . idl . inheritance ) {
90
81
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);
91
85
${ this . name } PropertiesConstructor.prototype.constructor = ${ this . name } PropertiesConstructor;\n`;
92
86
}
93
87
88
+ const getter = this . idl . members . filter ( ( m ) => m . getter ) [ 0 ] . name ;
94
89
this . str += `
95
90
const ${ this . name } Properties = new Proxy(${ this . name } PropertiesConstructor.prototype, {
96
91
defineProperty() {
@@ -100,11 +95,11 @@ const ${this.name}Properties = new Proxy(${this.name}PropertiesConstructor.proto
100
95
return false;
101
96
},
102
97
getOwnPropertyDescriptor(target, key) {
103
- if (true ) { // is visible
98
+ if (namedPropertiesIsVisible(key, target) ) { // is visible
104
99
const value = target${ getter ? "." + getter : "[utils.anonymousGetter]" } (key);
105
100
return {
106
101
value,
107
- enumerable: ${ legacyunenumerable ? "false" : " true" } ,
102
+ enumerable: true,
108
103
writable: true,
109
104
configurable: true
110
105
};
@@ -113,15 +108,15 @@ const ${this.name}Properties = new Proxy(${this.name}PropertiesConstructor.proto
113
108
}
114
109
},
115
110
get(target, key) {
116
- if (true ) { // is visible
111
+ if (namedPropertiesIsVisible(key, target) ) { // is visible
117
112
const value = target${ getter ? "." + getter : "[utils.anonymousGetter]" } (key);
118
113
return value;
119
114
} else {
120
115
return target[key];
121
116
}
122
117
},
123
118
has(target, key) {
124
- if (true ) { // is visible
119
+ if (namedPropertiesIsVisible(key, target) ) { // is visible
125
120
return true;
126
121
} else {
127
122
return key in target;
0 commit comments