| 1 |
const foo = { [Symbol.toPrimitive]: () => "foo" }; |
| 2 |
|
| 3 |
expect((new class { [foo](){ return 0; } }).foo()).toBe(0); |
| 4 |
expect((new class { get [foo](){ return 0; } }).foo).toBe(0); |
| 5 |
expect((new class { set [foo](v){ return v; } }).foo = 0).toBe(0); |
| 6 |
|
| 7 |
const arrayLike = { [Symbol.toPrimitive] : () => [] }; |
| 8 |
|
| 9 |
expect(() => new class { [arrayLike](){ return 0; } }).toThrow("@@toPrimitive must return a primitive value."); |
| 10 |
expect(() => new class { get [arrayLike](){ return 0; } }).toThrow("@@toPrimitive must return a primitive value."); |
| 11 |
expect(() => new class { set [arrayLike](v){ return v; } }).toThrow("@@toPrimitive must return a primitive value."); |