mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
LibJS: Throw an exception in NumberFormat.prototype.format for BigInts
Rather than crashing in the call to as_double(), throw an exception for now.
This commit is contained in:
parent
c65dea64bd
commit
40973814e9
2 changed files with 14 additions and 0 deletions
|
@ -41,6 +41,10 @@ ThrowCompletionOr<Value> NumberFormatFunction::call()
|
|||
// 4. Let x be ? ToNumeric(value).
|
||||
value = TRY(value.to_numeric(global_object));
|
||||
|
||||
// FIXME: Support BigInt number formatting.
|
||||
if (value.is_bigint())
|
||||
return vm.throw_completion<InternalError>(global_object, ErrorType::NotImplemented, "BigInt number formatting");
|
||||
|
||||
// 5. Return ? FormatNumeric(nf, x).
|
||||
// Note: Our implementation of FormatNumeric does not throw.
|
||||
auto formatted = format_numeric(m_number_format, value.as_double());
|
||||
|
|
|
@ -14,6 +14,16 @@ describe("errors", () => {
|
|||
Intl.NumberFormat().format(Symbol.hasInstance);
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert symbol to number");
|
||||
});
|
||||
|
||||
// FIXME: Remove this and add BigInt tests when BigInt number formatting is supported.
|
||||
test("bigint", () => {
|
||||
expect(() => {
|
||||
Intl.NumberFormat().format(1n);
|
||||
}).toThrowWithMessage(
|
||||
InternalError,
|
||||
"BigInt number formatting is not implemented in LibJS"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("special values", () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue