Skip to content

Commit

Permalink
Merge pull request #1281 from cxielarko/bigint-bool-eq
Browse files Browse the repository at this point in the history
ToPrimitive called without hint for boolean equality
  • Loading branch information
littledan authored Oct 16, 2017
2 parents 68e9124 + a9092bd commit 772fb79
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/language/expressions/equals/to-prim-hint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);

1 comment on commit 772fb79

@rwaldron
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.