summaryrefslogtreecommitdiff
path: root/test/language/expressions/equals/to-prim-hint.js
blob: cdb5b71bf61c41bf2fdf3d8669eefaaa9ff95a13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-abstract-equality-comparison
description: Object operands coerced without ToPrimitive hint
info: |
  7.2.14 Abstract Equality Comparison

  ...
  6. If Type(x) is Boolean, return the result of the comparison !
  ToNumber(x) == y.
  7. If Type(y) is Boolean, return the result of the comparison x == !
  ToNumber(y).
  8. If Type(x) is either String, Number, or Symbol and Type(y) is
  Object, return the result of the comparison x == ToPrimitive(y).
  9. If Type(x) is Object and Type(y) is either String, Number, or
  Symbol, return the result of the comparison ToPrimitive(x) == y.
  ...
features: [Symbol.toPrimitive]
---*/

let count = 0;
let obj = {
  [Symbol.toPrimitive](hint) {
    count += 1;
    assert.sameValue(hint, "default");
    return 1;
  }
};

assert.sameValue(true == obj, true);
assert.sameValue(count, 1);
assert.sameValue(obj == true, true);
assert.sameValue(count, 2);