mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-29 11:07:16 +02: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:
committed by
Linus Groh
parent
e6164fa439
commit
b0e5609b88
Notes:
sideshowbarker
2024-07-17 19:40:57 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/b0e5609b88d Pull-request: https://github.com/SerenityOS/serenity/pull/12332
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user