| 1 |
// Copyright (C) 2017 Josh Wolfe. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
description: Left shift for non-primitive BigInt values |
| 6 |
esid: sec-left-shift-operator-runtime-semantics-evaluation |
| 7 |
info: | |
| 8 |
ShiftExpression : ShiftExpression << AdditiveExpression |
| 9 |
|
| 10 |
1. Let lref be the result of evaluating ShiftExpression. |
| 11 |
2. Let lval be ? GetValue(lref). |
| 12 |
3. Let rref be the result of evaluating AdditiveExpression. |
| 13 |
4. Let rval be ? GetValue(rref). |
| 14 |
5. Let lnum be ? ToNumeric(lval). |
| 15 |
6. Let rnum be ? ToNumeric(rval). |
| 16 |
7. If Type(lnum) does not equal Type(rnum), throw a TypeError exception. |
| 17 |
8. Let T be Type(lnum). |
| 18 |
9. Return T::leftShift(lnum, rnum). |
| 19 |
|
| 20 |
features: [BigInt, Symbol.toPrimitive] |
| 21 |
---*/ |
| 22 |
|
| 23 |
assert.sameValue(Object(0b101n) << 1n, 0b1010n, "Object(0b101n) << 1n === 0b1010n"); |
| 24 |
assert.sameValue(Object(0b101n) << Object(1n), 0b1010n, "Object(0b101n) << Object(1n) === 0b1010n"); |
| 25 |
|
| 26 |
function err() { |
| 27 |
throw new Test262Error(); |
| 28 |
} |
| 29 |
|
| 30 |
assert.sameValue( |
| 31 |
{[Symbol.toPrimitive]: function() { return 0b101n; }, valueOf: err, toString: err} << 1n, 0b1010n, |
| 32 |
"primitive from @@toPrimitive"); |
| 33 |
assert.sameValue( |
| 34 |
{valueOf: function() { return 0b101n; }, toString: err} << 1n, 0b1010n, |
| 35 |
"primitive from {}.valueOf"); |
| 36 |
assert.sameValue( |
| 37 |
{toString: function() { return 0b101n; }} << 1n, 0b1010n, |
| 38 |
"primitive from {}.toString"); |
| 39 |
assert.sameValue( |
| 40 |
0b101n << {[Symbol.toPrimitive]: function() { return 1n; }, valueOf: err, toString: err}, 0b1010n, |
| 41 |
"primitive from @@toPrimitive"); |
| 42 |
assert.sameValue( |
| 43 |
0b101n << {valueOf: function() { return 1n; }, toString: err}, 0b1010n, |
| 44 |
"primitive from {}.valueOf"); |
| 45 |
assert.sameValue( |
| 46 |
0b101n << {toString: function() { return 1n; }}, 0b1010n, |
| 47 |
"primitive from {}.toString"); |
| 48 |
assert.sameValue( |
| 49 |
{valueOf: function() { return 0b101n; }} << {valueOf: function() { return 1n; }}, 0b1010n, |
| 50 |
"primitive from {}.valueOf"); |