opencode/packages/codemode-rust/conformance/cases/std-json-parse-errors.js
Sebastian Herrlinger b97c413f60 fix(codemode): match the reference's callback rules and messages in built-ins
Found while reading the rebase's recordings; none of these were recorded
before, and the pre-rebase reference behaves the same except where noted.

- Callback sites (array methods, sort, then/catch/finally, replace and
  replaceAll, JSON.parse's reviver and JSON.stringify's replacer) admit
  what the reference's isSupportedCallback does: not the Promise statics
  or Symbol (marked NOT_CALLBACK), nor a namespace reference, each refused
  with the site's wording. The hint now says (value) => fn(value), as on
  dev.
- Symbol says it isn't callable, and new Symbol() asks for a call.
- Array.prototype methods on a receiver that isn't an array name themselves
  and what they got.
- JSON.parse fails with its host runtime's message after the reference's
  prefix, from the parser Response.json already used.
- Assigning to a namespace says only data fields may be assigned; a
  namespace is described as a namespace reference, and the un-awaited
  promise hint names load(...), as on dev.

Recorded: std-callback-admission, std-json-parse-errors and
std-array-receivers.
2026-11-18 21:55:08 +01:00

10 lines
459 B
JavaScript

// JSON.parse's errors carry its host runtime's message after the reference's own prefix.
const texts = ["a", "", "{", "[1,]", '{"a":}', "[1 2]", "tru", '"abc', "1e", "01", "{a:1}", "[1]x", " ", "nul", '"\\x"', "-",
'{"a" 1}', "[", '{"a":1,}', '"\t"', "1.", ".5", "[1,,2]", "{,}", '"\\u12"', "Infinity", "NaN", '{"a":1}}', "1 2", "/"]
return texts.map((t) => {
try {
return ["ok", JSON.parse(t)]
} catch (e) {
return [e.name, e.message]
}
})