[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/752803
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49131}
This commit is contained in:
Georg Neis 2017-11-03 11:32:00 +01:00 committed by Commit Bot
parent 2a971833cd
commit 8cf319fec8
2 changed files with 8 additions and 6 deletions

View File

@ -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) {

View File

@ -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);
}{