Fix shifting a negative value when using BigInts (#4429)

When shifting a negative BigInt value if the
shift count is very "big" the result should be -1.

eg.:
```
(-2n >> (2n*32n)) === -1n
```

Note: the `-2n >> (2n*31n)` already returned `-1n` prior this change.

JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.usz@partner.samsung.com
This commit is contained in:
Péter Gál
2021-01-07 12:45:10 +01:00
committed by GitHub
parent 6dfd02a08c
commit 7972386412
2 changed files with 52 additions and 0 deletions
+5
View File
@@ -1412,6 +1412,11 @@ ecma_bigint_shift (ecma_value_t left_value, /**< left BigInt value */
{
return ecma_bigint_raise_memory_error ();
}
else if (left_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN)
{
/* Shifting a negative value with a very big number to the right should be -1. */
return ecma_bigint_create_from_digit (1, true);
}
return ECMA_BIGINT_ZERO;
}