mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:07:44 +00:00
LibJS: Use GetV to look up the toJSON property in SerializeJSONProperty
The current implementation of step 2a sort of manually implemented GetV with a ToObject + Get combo. But in the call to Get, the receiver wasn't the correct object. So when invoking toJSON, the receiver was an Object type rather than a BigInt. This also adds spec comments to SerializeJSONProperty.
This commit is contained in:
parent
e6164fa439
commit
b0e5609b88
2 changed files with 71 additions and 11 deletions
|
@ -38,6 +38,19 @@ describe("correct behavior", () => {
|
|||
});
|
||||
});
|
||||
|
||||
test("serialize BigInt with a toJSON property", () => {
|
||||
Object.defineProperty(BigInt.prototype, "toJSON", {
|
||||
configurable: true, // Allows deleting this property at the end of this test case.
|
||||
get() {
|
||||
"use strict";
|
||||
return () => typeof this;
|
||||
},
|
||||
});
|
||||
|
||||
expect(JSON.stringify(1n)).toBe('"bigint"');
|
||||
delete BigInt.prototype.toJSON;
|
||||
});
|
||||
|
||||
test("ignores non-enumerable properties", () => {
|
||||
let o = { foo: "bar" };
|
||||
Object.defineProperty(o, "baz", { value: "qux", enumerable: false });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue