@@ -17,6 +17,16 @@ defines:
17
17
18
18
// @ts -check
19
19
20
+ // Capture primordial functions and receiver-uncurried primordial methods that
21
+ // are used in verification but might be destroyed *by* that process itself.
22
+ var __isArray = Array . isArray ;
23
+ var __defineProperty = Object . defineProperty ;
24
+ var __join = Function . prototype . call . bind ( Array . prototype . join ) ;
25
+ var __push = Function . prototype . call . bind ( Array . prototype . push ) ;
26
+ var __hasOwnProperty = Function . prototype . call . bind ( Object . prototype . hasOwnProperty ) ;
27
+ var __propertyIsEnumerable = Function . prototype . call . bind ( Object . prototype . propertyIsEnumerable ) ;
28
+ var nonIndexNumericPropertyName = Math . pow ( 2 , 32 ) - 1 ;
29
+
20
30
/**
21
31
* @param {object } obj
22
32
* @param {string|symbol } name
@@ -46,7 +56,7 @@ function verifyProperty(obj, name, desc, options) {
46
56
}
47
57
48
58
assert (
49
- Object . prototype . hasOwnProperty . call ( obj , name ) ,
59
+ __hasOwnProperty ( obj , name ) ,
50
60
"obj should have an own property " + nameStr
51
61
) ;
52
62
@@ -77,55 +87,56 @@ function verifyProperty(obj, name, desc, options) {
77
87
78
88
var failures = [ ] ;
79
89
80
- if ( Object . prototype . hasOwnProperty . call ( desc , 'value' ) ) {
90
+ if ( __hasOwnProperty ( desc , 'value' ) ) {
81
91
if ( ! isSameValue ( desc . value , originalDesc . value ) ) {
82
- failures . push ( "descriptor value should be " + desc . value ) ;
92
+ __push ( failures , "descriptor value should be " + desc . value ) ;
83
93
}
84
94
if ( ! isSameValue ( desc . value , obj [ name ] ) ) {
85
- failures . push ( "object value should be " + desc . value ) ;
95
+ __push ( failures , "object value should be " + desc . value ) ;
86
96
}
87
97
}
88
98
89
- if ( Object . prototype . hasOwnProperty . call ( desc , 'enumerable' ) ) {
99
+ if ( __hasOwnProperty ( desc , 'enumerable' ) ) {
90
100
if ( desc . enumerable !== originalDesc . enumerable ||
91
101
desc . enumerable !== isEnumerable ( obj , name ) ) {
92
- failures . push ( 'descriptor should ' + ( desc . enumerable ? '' : 'not ' ) + 'be enumerable' ) ;
102
+ __push ( failures , 'descriptor should ' + ( desc . enumerable ? '' : 'not ' ) + 'be enumerable' ) ;
93
103
}
94
104
}
95
105
96
- if ( Object . prototype . hasOwnProperty . call ( desc , 'writable' ) ) {
106
+ // Operations past this point are potentially destructive!
107
+
108
+ if ( __hasOwnProperty ( desc , 'writable' ) ) {
97
109
if ( desc . writable !== originalDesc . writable ||
98
110
desc . writable !== isWritable ( obj , name ) ) {
99
- failures . push ( 'descriptor should ' + ( desc . writable ? '' : 'not ' ) + 'be writable' ) ;
111
+ __push ( failures , 'descriptor should ' + ( desc . writable ? '' : 'not ' ) + 'be writable' ) ;
100
112
}
101
113
}
102
114
103
- if ( Object . prototype . hasOwnProperty . call ( desc , 'configurable' ) ) {
115
+ if ( __hasOwnProperty ( desc , 'configurable' ) ) {
104
116
if ( desc . configurable !== originalDesc . configurable ||
105
117
desc . configurable !== isConfigurable ( obj , name ) ) {
106
- failures . push ( 'descriptor should ' + ( desc . configurable ? '' : 'not ' ) + 'be configurable' ) ;
118
+ __push ( failures , 'descriptor should ' + ( desc . configurable ? '' : 'not ' ) + 'be configurable' ) ;
107
119
}
108
120
}
109
121
110
- assert ( ! failures . length , failures . join ( '; ' ) ) ;
122
+ assert ( ! failures . length , __join ( failures , '; ' ) ) ;
111
123
112
124
if ( options && options . restore ) {
113
- Object . defineProperty ( obj , name , originalDesc ) ;
125
+ __defineProperty ( obj , name , originalDesc ) ;
114
126
}
115
127
116
128
return true ;
117
129
}
118
130
119
131
function isConfigurable ( obj , name ) {
120
- var hasOwnProperty = Object . prototype . hasOwnProperty ;
121
132
try {
122
133
delete obj [ name ] ;
123
134
} catch ( e ) {
124
135
if ( ! ( e instanceof TypeError ) ) {
125
136
throw new Test262Error ( "Expected TypeError, got " + e ) ;
126
137
}
127
138
}
128
- return ! hasOwnProperty . call ( obj , name ) ;
139
+ return ! __hasOwnProperty ( obj , name ) ;
129
140
}
130
141
131
142
function isEnumerable ( obj , name ) {
@@ -143,9 +154,7 @@ function isEnumerable(obj, name) {
143
154
stringCheck = true ;
144
155
}
145
156
146
- return stringCheck &&
147
- Object . prototype . hasOwnProperty . call ( obj , name ) &&
148
- Object . prototype . propertyIsEnumerable . call ( obj , name ) ;
157
+ return stringCheck && __hasOwnProperty ( obj , name ) && __propertyIsEnumerable ( obj , name ) ;
149
158
}
150
159
151
160
function isSameValue ( a , b ) {
@@ -155,16 +164,19 @@ function isSameValue(a, b) {
155
164
return a === b ;
156
165
}
157
166
158
- var __isArray = Array . isArray ;
159
167
function isWritable ( obj , name , verifyProp , value ) {
160
168
var unlikelyValue = __isArray ( obj ) && name === "length" ?
161
- Math . pow ( 2 , 32 ) - 1 :
169
+ nonIndexNumericPropertyName :
162
170
"unlikelyValue" ;
163
171
var newValue = value || unlikelyValue ;
164
- var hadValue = Object . prototype . hasOwnProperty . call ( obj , name ) ;
172
+ var hadValue = __hasOwnProperty ( obj , name ) ;
165
173
var oldValue = obj [ name ] ;
166
174
var writeSucceeded ;
167
175
176
+ if ( arguments . length < 4 && newValue === oldValue ) {
177
+ newValue = newValue + "2" ;
178
+ }
179
+
168
180
try {
169
181
obj [ name ] = newValue ;
170
182
} catch ( e ) {
0 commit comments