mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
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.
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
// Which functions callback sites admit: built-ins, bound functions and closures, but not the Promise statics, Symbol,
|
|
// or a tool, each refused with the site's own wording.
|
|
const sites = {
|
|
map: (f) => [1].map(f),
|
|
sort: (f) => [2, 1].sort(f),
|
|
then: (f) => Promise.resolve(1).then(f),
|
|
catch: (f) => Promise.reject(1).catch(f),
|
|
finally: (f) => Promise.resolve(1).finally(f),
|
|
replace: (f) => "a".replace("a", f),
|
|
replaceAll: (f) => "a".replaceAll("a", f),
|
|
parse: (f) => JSON.parse("[1]", f),
|
|
stringify: (f) => JSON.stringify([1], f),
|
|
}
|
|
const callables = {
|
|
abs: Math.abs,
|
|
string: String,
|
|
bound: ((x) => x).bind(null),
|
|
arrow: (x) => x,
|
|
resolve: Promise.resolve,
|
|
all: Promise.all,
|
|
withResolvers: Promise.withResolvers,
|
|
symbol: Symbol,
|
|
tool: tools.echo,
|
|
nested: tools.git.status,
|
|
number: 5,
|
|
}
|
|
const out = []
|
|
for (const [s, site] of Object.entries(sites)) {
|
|
for (const [c, f] of Object.entries(callables)) {
|
|
try {
|
|
const v = site(f)
|
|
out.push([s, c, v instanceof Promise ? "promise" : v])
|
|
} catch (e) {
|
|
out.push([s, c, e.name, e.message])
|
|
}
|
|
}
|
|
}
|
|
for (const f of [() => Symbol("s"), () => new Symbol(), () => (tools.x = 1), () => (tools.git.x = 1)]) {
|
|
try {
|
|
out.push(f())
|
|
} catch (e) {
|
|
out.push([e.name, e.message])
|
|
}
|
|
}
|
|
return out
|