@@ -149,6 +149,8 @@ function testPrimitiveWrappers(primitiveValue, hint, test) {
149149}
150150
151151function testCoercibleToPrimitiveWithMethod ( hint , method , test ) {
152+ var supportsToPrimitive = typeof Symbol !== "undefined" && ! ! Symbol . toPrimitive ;
153+
152154 var methodNames ;
153155 if ( hint === "number" ) {
154156 methodNames = [ "valueOf" , "toString" ] ;
@@ -158,11 +160,13 @@ function testCoercibleToPrimitiveWithMethod(hint, method, test) {
158160 throw new Test262Error ( ) ;
159161 }
160162 // precedence order
161- test ( {
162- [ Symbol . toPrimitive ] : method ,
163- [ methodNames [ 0 ] ] : function ( ) { throw new Test262Error ( ) ; } ,
164- [ methodNames [ 1 ] ] : function ( ) { throw new Test262Error ( ) ; } ,
165- } ) ;
163+ if ( supportsToPrimitive ) {
164+ test ( {
165+ [ Symbol . toPrimitive ] : method ,
166+ [ methodNames [ 0 ] ] : function ( ) { throw new Test262Error ( ) ; } ,
167+ [ methodNames [ 1 ] ] : function ( ) { throw new Test262Error ( ) ; } ,
168+ } ) ;
169+ }
166170 test ( {
167171 [ methodNames [ 0 ] ] : method ,
168172 [ methodNames [ 1 ] ] : function ( ) { throw new Test262Error ( ) ; } ,
@@ -178,16 +182,18 @@ function testCoercibleToPrimitiveWithMethod(hint, method, test) {
178182 }
179183
180184 // GetMethod: if func is undefined or null, return undefined.
181- test ( {
182- [ Symbol . toPrimitive ] : undefined ,
183- [ methodNames [ 0 ] ] : method ,
184- [ methodNames [ 1 ] ] : method ,
185- } ) ;
186- test ( {
187- [ Symbol . toPrimitive ] : null ,
188- [ methodNames [ 0 ] ] : method ,
189- [ methodNames [ 1 ] ] : method ,
190- } ) ;
185+ if ( supportsToPrimitive ) {
186+ test ( {
187+ [ Symbol . toPrimitive ] : undefined ,
188+ [ methodNames [ 0 ] ] : method ,
189+ [ methodNames [ 1 ] ] : method ,
190+ } ) ;
191+ test ( {
192+ [ Symbol . toPrimitive ] : null ,
193+ [ methodNames [ 0 ] ] : method ,
194+ [ methodNames [ 1 ] ] : method ,
195+ } ) ;
196+ }
191197
192198 // if methodNames[0] is not callable, fallback to methodNames[1]
193199 test ( {
@@ -253,7 +259,9 @@ function testNotCoercibleToNumber(test) {
253259 }
254260
255261 // ToNumber: Symbol -> TypeError
256- testPrimitiveValue ( Symbol ( "1" ) ) ;
262+ if ( typeof Symbol !== "undefined" ) {
263+ testPrimitiveValue ( Symbol ( "1" ) ) ;
264+ }
257265
258266 if ( typeof BigInt !== "undefined" ) {
259267 // ToNumber: BigInt -> TypeError
@@ -265,18 +273,22 @@ function testNotCoercibleToNumber(test) {
265273}
266274
267275function testNotCoercibleToPrimitive ( hint , test ) {
276+ var supportsToPrimitive = typeof Symbol !== "undefined" && ! ! Symbol . toPrimitive ;
277+
268278 function MyError ( ) { }
269279
270280 // ToPrimitive: input[@@toPrimitive ] is not callable (and non-null)
271- test ( TypeError , { [ Symbol . toPrimitive ] : 1 } ) ;
272- test ( TypeError , { [ Symbol . toPrimitive ] : { } } ) ;
281+ if ( supportsToPrimitive ) {
282+ test ( TypeError , { [ Symbol . toPrimitive ] : 1 } ) ;
283+ test ( TypeError , { [ Symbol . toPrimitive ] : { } } ) ;
273284
274- // ToPrimitive: input[@@toPrimitive ] returns object
275- test ( TypeError , { [ Symbol . toPrimitive ] : function ( ) { return Object ( 1 ) ; } } ) ;
276- test ( TypeError , { [ Symbol . toPrimitive ] : function ( ) { return { } ; } } ) ;
285+ // ToPrimitive: input[@@toPrimitive ] returns object
286+ test ( TypeError , { [ Symbol . toPrimitive ] : function ( ) { return Object ( 1 ) ; } } ) ;
287+ test ( TypeError , { [ Symbol . toPrimitive ] : function ( ) { return { } ; } } ) ;
277288
278- // ToPrimitive: input[@@toPrimitive ] throws
279- test ( MyError , { [ Symbol . toPrimitive ] : function ( ) { throw new MyError ( ) ; } } ) ;
289+ // ToPrimitive: input[@@toPrimitive ] throws
290+ test ( MyError , { [ Symbol . toPrimitive ] : function ( ) { throw new MyError ( ) ; } } ) ;
291+ }
280292
281293 // OrdinaryToPrimitive: method throws
282294 testCoercibleToPrimitiveWithMethod ( hint , function ( ) {
@@ -341,7 +353,9 @@ function testNotCoercibleToString(test) {
341353 }
342354
343355 // Symbol -> TypeError
344- testPrimitiveValue ( Symbol ( "1" ) ) ;
356+ if ( typeof Symbol !== "undefined" ) {
357+ testPrimitiveValue ( Symbol ( "1" ) ) ;
358+ }
345359
346360 // ToPrimitive
347361 testNotCoercibleToPrimitive ( "string" , test ) ;
@@ -351,7 +365,9 @@ function testCoercibleToBooleanTrue(test) {
351365 test ( true ) ;
352366 test ( 1 ) ;
353367 test ( "string" ) ;
354- test ( Symbol ( "1" ) ) ;
368+ if ( typeof Symbol !== "undefined" ) {
369+ test ( Symbol ( "1" ) ) ;
370+ }
355371 test ( { } ) ;
356372}
357373
@@ -434,7 +450,9 @@ function testNotCoercibleToBigInt(test) {
434450 testPrimitiveValue ( TypeError , 0 ) ;
435451 testPrimitiveValue ( TypeError , NaN ) ;
436452 testPrimitiveValue ( TypeError , Infinity ) ;
437- testPrimitiveValue ( TypeError , Symbol ( "1" ) ) ;
453+ if ( typeof Symbol !== "undefined" ) {
454+ testPrimitiveValue ( TypeError , Symbol ( "1" ) ) ;
455+ }
438456
439457 // when a String parses to NaN -> SyntaxError
440458 function testStringValue ( string ) {
0 commit comments