mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
LibJS: Only coerce value once in BigInt constructor
See https://github.com/tc39/ecma262/pull/2812.
This commit is contained in:
parent
8c11786145
commit
301bba8c19
Notes:
sideshowbarker
2024-07-17 18:08:55 +09:00
Author: https://github.com/davidot
Commit: 301bba8c19
Pull-request: https://github.com/SerenityOS/serenity/pull/14765
Reviewed-by: https://github.com/linusg ✅
2 changed files with 16 additions and 2 deletions
|
@ -52,8 +52,8 @@ ThrowCompletionOr<Value> BigIntConstructor::call()
|
|||
if (primitive.is_number())
|
||||
return TRY(number_to_bigint(global_object, primitive));
|
||||
|
||||
// 4. Otherwise, return ? ToBigInt(value).
|
||||
return TRY(value.to_bigint(global_object));
|
||||
// 4. Otherwise, return ? ToBigInt(prim).
|
||||
return TRY(primitive.to_bigint(global_object));
|
||||
}
|
||||
|
||||
// 21.2.1.1 BigInt ( value ), https://tc39.es/ecma262/#sec-bigint-constructor-number-value
|
||||
|
|
|
@ -63,6 +63,20 @@ describe("correct behavior", () => {
|
|||
expect(BigInt("0X10")).toBe(16n);
|
||||
expect(BigInt(`0x${"f".repeat(25)}`)).toBe(1267650600228229401496703205375n);
|
||||
});
|
||||
|
||||
test("only coerces value once", () => {
|
||||
let calls = 0;
|
||||
const value = {
|
||||
[Symbol.toPrimitive]() {
|
||||
expect(calls).toBe(0);
|
||||
++calls;
|
||||
return "123";
|
||||
},
|
||||
};
|
||||
|
||||
expect(BigInt(value)).toEqual(123n);
|
||||
expect(calls).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue