toobject_before_topropertykey.js (1157B)
1 // Copyright (C) 2021 Jamie Kyle. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: sec-object.hasown 5 description: > 6 ToObject is performed before ToPropertyKey. 7 info: | 8 Object.hasOwn ( _O_, _P_ ) 9 10 1. Let _obj_ be ? ToObject(_O_). 11 2. Let _key_ be ? ToPropertyKey(_P_). 12 13 ToPropertyKey ( argument ) 14 15 1. Let key be ? ToPrimitive(argument, hint String). 16 author: Jamie Kyle 17 features: [Symbol.toPrimitive, Object.hasOwn] 18 ---*/ 19 20 var callCount1 = 0; 21 var coercibleKey1 = { 22 get toString() { 23 callCount1++; 24 throw new Test262Error(); 25 }, 26 get valueOf() { 27 callCount1++; 28 throw new Test262Error(); 29 }, 30 }; 31 32 assert.throws(TypeError, function() { 33 Object.hasOwn(null, coercibleKey1); 34 }); 35 assert.sameValue(callCount1, 0, "toString and valueOf must not be called"); 36 37 38 var callCount2 = 0; 39 var coercibleKey2 = {}; 40 coercibleKey2[Symbol.toPrimitive] = function() { 41 callCount2++; 42 throw new Test262Error(); 43 }; 44 45 assert.throws(TypeError, function() { 46 Object.hasOwn(undefined, coercibleKey2); 47 }); 48 assert.sameValue(callCount2, 0, "Symbol.toPrimitive must not be called"); 49 50 reportCompare(0, 0);