Some checks failed
ci / fast (linux) (push) Failing after 11m14s
Add the JSON global object with both methods following the sentinel NativeFunction + interpreter interception pattern. The implementation includes a dedicated recursive descent JSON parser (strict spec: no trailing commas, no single quotes, no hex/octal, surrogate pair support), JSON.stringify with replacer function/array, space indentation, toJSON, boxed primitive unwrapping, and circular reference detection via ptr_eq. Safety: depth-limited to 512 levels for both parse and stringify to prevent stack overflow from malicious input. Space string truncation uses char boundaries to avoid panics on multi-byte UTF-8. 138 unit tests, 2 conformance tests (js262). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
23 lines
824 B
JavaScript
23 lines
824 B
JavaScript
// JSON.stringify basic tests
|
|
console.log(JSON.stringify(null));
|
|
console.log(JSON.stringify(true));
|
|
console.log(JSON.stringify(false));
|
|
console.log(JSON.stringify(42));
|
|
console.log(JSON.stringify("hello"));
|
|
console.log(JSON.stringify({}));
|
|
console.log(JSON.stringify([]));
|
|
console.log(JSON.stringify([1, 2, 3]));
|
|
console.log(JSON.stringify({a: {b: [1, 2]}}));
|
|
console.log(JSON.stringify(0/0));
|
|
console.log(JSON.stringify(1/0));
|
|
console.log(JSON.stringify([1, undefined, 3]));
|
|
// Verify roundtrip for multi-key objects (order may vary)
|
|
var o = JSON.parse(JSON.stringify({a: 1, b: "two"}));
|
|
console.log(o.a);
|
|
console.log(o.b);
|
|
// undefined properties omitted
|
|
var s = JSON.stringify({a: 1, b: undefined});
|
|
console.log(s.indexOf('"a"') >= 0);
|
|
console.log(s.indexOf('"b"') === -1);
|
|
console.log(typeof JSON.stringify(undefined));
|