mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:07:44 +00: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
2 changed files with 16 additions and 2 deletions
|
@ -52,8 +52,8 @@ ThrowCompletionOr<Value> BigIntConstructor::call()
|
||||||
if (primitive.is_number())
|
if (primitive.is_number())
|
||||||
return TRY(number_to_bigint(global_object, primitive));
|
return TRY(number_to_bigint(global_object, primitive));
|
||||||
|
|
||||||
// 4. Otherwise, return ? ToBigInt(value).
|
// 4. Otherwise, return ? ToBigInt(prim).
|
||||||
return TRY(value.to_bigint(global_object));
|
return TRY(primitive.to_bigint(global_object));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 21.2.1.1 BigInt ( value ), https://tc39.es/ecma262/#sec-bigint-constructor-number-value
|
// 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("0X10")).toBe(16n);
|
||||||
expect(BigInt(`0x${"f".repeat(25)}`)).toBe(1267650600228229401496703205375n);
|
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", () => {
|
describe("errors", () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue