diff --git a/src/objects/bigint.cc b/src/objects/bigint.cc index 23511d9977..70d0d831fc 100644 --- a/src/objects/bigint.cc +++ b/src/objects/bigint.cc @@ -530,14 +530,16 @@ MaybeHandle BigInt::FromObject(Isolate* isolate, Handle obj) { } if (obj->IsString()) { Handle n; - if (StringToBigInt(isolate, Handle::cast(obj)).ToHandle(&n)) { - return n; + if (!StringToBigInt(isolate, Handle::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 BigInt::ToNumber(Handle x) { diff --git a/test/mjsunit/harmony/bigint/basics.js b/test/mjsunit/harmony/bigint/basics.js index 86d585e422..7ae51a04a0 100644 --- a/test/mjsunit/harmony/bigint/basics.js +++ b/test/mjsunit/harmony/bigint/basics.js @@ -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); }{