Commit 8cf319fe authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[bigint] Make ToBigInt throw the correct error.

We must throw a SyntaxError only when failing to convert a string. In
the other cases we must throw a TypeError.

R=jkummerow@chromium.org

Bug: v8:6791
Change-Id: I802d8b6830b341f87e46e7de198af74ba95b8658
Reviewed-on: https://chromium-review.googlesource.com/752803Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49131}
parent 2a971833
......@@ -530,14 +530,16 @@ MaybeHandle<BigInt> BigInt::FromObject(Isolate* isolate, Handle<Object> obj) {
}
if (obj->IsString()) {
Handle<BigInt> n;
if (StringToBigInt(isolate, Handle<String>::cast(obj)).ToHandle(&n)) {
return n;
if (!StringToBigInt(isolate, Handle<String>::cast(obj)).ToHandle(&n)) {
THROW_NEW_ERROR(isolate,
NewSyntaxError(MessageTemplate::kBigIntFromObject, obj),
BigInt);
}
// ... else fall through.
return n;
}
THROW_NEW_ERROR(
isolate, NewSyntaxError(MessageTemplate::kBigIntFromObject, obj), BigInt);
isolate, NewTypeError(MessageTemplate::kBigIntFromObject, obj), BigInt);
}
Handle<Object> BigInt::ToNumber(Handle<BigInt> x) {
......
......@@ -22,8 +22,8 @@ const six = BigInt(6);
// ToBigInt, NumberToBigInt, BigInt
{
assertThrows(() => BigInt(undefined), SyntaxError);
assertThrows(() => BigInt(null), SyntaxError);
assertThrows(() => BigInt(undefined), TypeError);
assertThrows(() => BigInt(null), TypeError);
assertThrows(() => BigInt({}), SyntaxError);
assertThrows(() => BigInt("foo"), SyntaxError);
}{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment