mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
LibJS: Implement rawJSON and isRawJSON functions
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This commit is contained in:
parent
e0ceb66580
commit
223c9c91e6
Notes:
github-actions[bot]
2025-04-24 13:34:52 +00:00
Author: https://github.com/aplefull
Commit: 223c9c91e6
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4451
Reviewed-by: https://github.com/trflynn89 ✅
10 changed files with 209 additions and 4 deletions
57
Libraries/LibJS/Tests/builtins/JSON/JSON.rawJSON.js
Normal file
57
Libraries/LibJS/Tests/builtins/JSON/JSON.rawJSON.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
test("JSON.rawJSON basic functionality", () => {
|
||||
expect(Object.isExtensible(JSON.rawJSON)).toBeTrue();
|
||||
expect(typeof JSON.rawJSON).toBe("function");
|
||||
expect(Object.getPrototypeOf(JSON.rawJSON)).toBe(Function.prototype);
|
||||
expect(Object.getOwnPropertyDescriptor(JSON.rawJSON, "prototype")).toBeUndefined();
|
||||
|
||||
expect(JSON.stringify(JSON.rawJSON(1))).toBe("1");
|
||||
expect(JSON.stringify(JSON.rawJSON(1.1))).toBe("1.1");
|
||||
expect(JSON.stringify(JSON.rawJSON(-1))).toBe("-1");
|
||||
expect(JSON.stringify(JSON.rawJSON(-1.1))).toBe("-1.1");
|
||||
expect(JSON.stringify(JSON.rawJSON(1.1e1))).toBe("11");
|
||||
expect(JSON.stringify(JSON.rawJSON(1.1e-1))).toBe("0.11");
|
||||
expect(JSON.stringify(JSON.rawJSON(null))).toBe("null");
|
||||
expect(JSON.stringify(JSON.rawJSON(true))).toBe("true");
|
||||
expect(JSON.stringify(JSON.rawJSON(false))).toBe("false");
|
||||
expect(JSON.stringify(JSON.rawJSON('"foo"'))).toBe('"foo"');
|
||||
|
||||
expect(JSON.stringify({ 42: JSON.rawJSON(37) })).toBe('{"42":37}');
|
||||
expect(JSON.stringify({ x: JSON.rawJSON(1), y: JSON.rawJSON(2) })).toBe('{"x":1,"y":2}');
|
||||
expect(JSON.stringify({ x: { x: JSON.rawJSON(1), y: JSON.rawJSON(2) } })).toBe(
|
||||
'{"x":{"x":1,"y":2}}'
|
||||
);
|
||||
|
||||
expect(JSON.stringify([JSON.rawJSON(1), JSON.rawJSON(1.1)])).toBe("[1,1.1]");
|
||||
expect(
|
||||
JSON.stringify([
|
||||
JSON.rawJSON('"1"'),
|
||||
JSON.rawJSON(true),
|
||||
JSON.rawJSON(null),
|
||||
JSON.rawJSON(false),
|
||||
])
|
||||
).toBe('["1",true,null,false]');
|
||||
expect(JSON.stringify([{ x: JSON.rawJSON(1), y: JSON.rawJSON(1) }])).toBe('[{"x":1,"y":1}]');
|
||||
});
|
||||
|
||||
test("JSON.rawJSON error cases", () => {
|
||||
expect(() => JSON.rawJSON(Symbol("123"))).toThrow(TypeError);
|
||||
expect(() => JSON.rawJSON(undefined)).toThrow(SyntaxError);
|
||||
expect(() => JSON.rawJSON({})).toThrow(SyntaxError);
|
||||
expect(() => JSON.rawJSON([])).toThrow(SyntaxError);
|
||||
|
||||
const illegalChars = ["\n", "\t", "\r", " "];
|
||||
|
||||
illegalChars.forEach(char => {
|
||||
expect(() => {
|
||||
JSON.rawJSON(`${char}123`);
|
||||
}).toThrow(SyntaxError);
|
||||
|
||||
expect(() => {
|
||||
JSON.rawJSON(`123${char}`);
|
||||
}).toThrow(SyntaxError);
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
JSON.rawJSON("");
|
||||
}).toThrow(SyntaxError);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue