@@ -31,6 +31,57 @@ Interface.prototype.generateNamedPropertiesObject = function () {
31
31
return ;
32
32
}
33
33
34
+ let overrideBuiltins = false ;
35
+ const unforgeables = new Set ( ) ;
36
+ let parent = this . idl ;
37
+ while ( parent ) {
38
+ if ( utils . getExtAttr ( parent . extAttrs , 'Unforgeable' ) ) {
39
+ unforgeables . add ( 'valueOf' ) . add ( 'toString' ) ;
40
+ }
41
+ if ( utils . getExtAttr ( parent . extAttrs , 'OverrideBuiltins' ) ) {
42
+ overrideBuiltins = true ;
43
+ }
44
+
45
+ const members = parent . members . filter ( ( m ) =>
46
+ m . type === 'attribute' && utils . getExtAttr ( m . extAttrs , 'Unforgeable' )
47
+ ) ;
48
+ for ( const member of members ) {
49
+ unforgeables . add ( member . name ) ;
50
+ }
51
+ const parentInterface = this . opts . interfaces [ parent . inheritance ] ;
52
+ parent = parentInterface && parentInterface . idl ;
53
+ }
54
+
55
+ this . str += `
56
+ function namedPropertiesIsVisible(P, O) {
57
+ if (P of ${ JSON . stringify ( Array . from ( unforgeables ) ) } ) {
58
+ return false;
59
+ }
60
+ if (!supported) {
61
+ return false;
62
+ }` ;
63
+
64
+ if ( overrideBuiltins ) {
65
+ this . str += `
66
+ return true;` ;
67
+ } else {
68
+ this . str += `
69
+ if (Object.getOwnPropertyDescriptor(O, P)) {
70
+ return false;
71
+ }
72
+
73
+ let prototype = Object.getPrototypeOf(O);
74
+ while (prototype) {
75
+ if (prototype.constructor.name.endsWith("PropertiesConstructor") && Object.getOwnPropertyDescriptor(prototype, P)) {
76
+ return false;
77
+ }
78
+ prototype = Object.getPrototypeOf(prototype);
79
+ }` ;
80
+ }
81
+ this . str += `
82
+ return true;
83
+ }` ;
84
+
34
85
this . str += `var ${ this . name } PropertiesConstructor = function () {
35
86
throw new TypeError("Illegal constructor");
36
87
}\n` ;
0 commit comments