tor-browser

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

to-prim-hint.js (1063B)


      1 // Copyright (C) 2017 Robin Templeton. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-abstract-equality-comparison
      6 description: Object operands coerced without ToPrimitive hint
      7 info: |
      8  7.2.14 Abstract Equality Comparison
      9 
     10  ...
     11  6. If Type(x) is Boolean, return the result of the comparison !
     12  ToNumber(x) == y.
     13  7. If Type(y) is Boolean, return the result of the comparison x == !
     14  ToNumber(y).
     15  8. If Type(x) is either String, Number, or Symbol and Type(y) is
     16  Object, return the result of the comparison x == ToPrimitive(y).
     17  9. If Type(x) is Object and Type(y) is either String, Number, or
     18  Symbol, return the result of the comparison ToPrimitive(x) == y.
     19  ...
     20 features: [Symbol.toPrimitive]
     21 ---*/
     22 
     23 let count = 0;
     24 let obj = {
     25  [Symbol.toPrimitive](hint) {
     26    count += 1;
     27    assert.sameValue(hint, "default");
     28    return 1;
     29  }
     30 };
     31 
     32 assert.sameValue(true == obj, true);
     33 assert.sameValue(count, 1);
     34 assert.sameValue(obj == true, true);
     35 assert.sameValue(count, 2);
     36 
     37 reportCompare(0, 0);