tor-browser

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

constructor-coercion.js (872B)


      1 // Copyright (C) 2022 Kevin Gibbons. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 description: BigInt constructor only coerces its input once
      6 esid: sec-bigint-constructor-number-value
      7 info: |
      8  BigInt ( value )
      9    1. If NewTarget is not undefined, throw a TypeError exception.
     10    2. Let prim be ? ToPrimitive(value, number).
     11    3. If Type(prim) is Number, return ? NumberToBigInt(prim).
     12    4. Otherwise, return ? ToBigInt(prim).
     13 features: [BigInt]
     14 ---*/
     15 
     16 var first = true;
     17 var v = {
     18  [Symbol.toPrimitive]: function() {
     19    if (first) {
     20      first = false;
     21      return "42";
     22    }
     23    throw new Test262Error("Symbol.toPrimitive should only be invoked once");
     24  },
     25 };
     26 
     27 assert.sameValue(BigInt(v), 42n, "BigInt constructor should use the post-ToPrimitive value as the argument to ToBigInt");
     28 
     29 reportCompare(0, 0);