tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

symbol_property_toPrimitive.js (786B)


      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 /*---
      5 esid: sec-object.hasown
      6 description: Object.hasOwn with symbol and @@toPrimitive conversion
      7 info: |
      8  Object.hasOwn ( _O_, _P_ )
      9 
     10  1. Let _obj_ be ? ToObject(_O_).
     11  1. Let _key_ be ? ToPropertyKey(_P_).
     12  ...
     13 author: Jamie Kyle
     14 features: [Symbol.toPrimitive, Object.hasOwn]
     15 ---*/
     16 
     17 var obj = {};
     18 var sym = Symbol();
     19 
     20 var callCount = 0;
     21 var wrapper = {};
     22 wrapper[Symbol.toPrimitive] = function() {
     23  callCount += 1;
     24  return sym;
     25 };
     26 
     27 obj[sym] = 0;
     28 
     29 assert.sameValue(
     30  Object.hasOwn(obj, wrapper),
     31  true,
     32  "Returns true if symbol own property found"
     33 );
     34 
     35 assert.sameValue(callCount, 1, "toPrimitive method called exactly once");
     36 
     37 reportCompare(0, 0);