mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
- delete: optional and parenthesized targets delete; an identifier fails when it runs; built-in constants and prototypes refuse; a function's name and length can be deleted; strings and nullish bases get the reference's errors; tool references refuse. - arguments: delete leaves a hole, length is a hidden writable property, the binding can be reassigned, and iterating it reads its enumerable own values. - await is a plain name at the top level unless an expression starts with it, and an escaped await is a label. - A named function expression's own name is bound before its parameters, so their defaults see it read-only. - Iterators that break the protocol get the reference's errors everywhere they are opened, stepped or closed, including async yield* over a non-iterable. - Promise.all, allSettled, any and race reject when their input is not iterable or iterating it fails. - An accessor in an object literal fails when the literal runs, and export is a parse error, as in the reference. Drops 77 files from rust-skipped.txt.
58 lines
1.9 KiB
JavaScript
58 lines
1.9 KiB
JavaScript
// The errors for iterators that break the protocol, in each place a program opens or steps one.
|
|
const attempt = async (f) => {
|
|
try {
|
|
return await f()
|
|
} catch (error) {
|
|
return String(error)
|
|
}
|
|
}
|
|
const sync = (iterator) => ({ [Symbol.iterator]: () => iterator })
|
|
const asyncOf = (iterator) => ({ [Symbol.asyncIterator]: () => iterator })
|
|
const step = () => ({ done: false, value: 1 })
|
|
return {
|
|
method: await attempt(() => [...{ [Symbol.iterator]: 1 }]),
|
|
methodResult: await attempt(() => [...{ [Symbol.iterator]: () => 1 }]),
|
|
next: await attempt(() => [...sync({ next: 5 })]),
|
|
nextResult: await attempt(() => [...sync({ next: () => 5 })]),
|
|
returnMethod: await attempt(() => {
|
|
for (const x of sync({ next: step, return: 7 })) break
|
|
}),
|
|
returnResult: await attempt(() => {
|
|
const [a] = sync({ next: step, return: () => 5 })
|
|
}),
|
|
bodyErrorWins: await attempt(() => {
|
|
for (const x of sync({ next: step, return: 7 })) throw new Error("body")
|
|
}),
|
|
delegateReturn: await attempt(() => {
|
|
const g = (function* () {
|
|
yield* sync({ next: step, return: () => 5 })
|
|
})()
|
|
g.next()
|
|
return g.return(1)
|
|
}),
|
|
delegateThrow: await attempt(() => {
|
|
const g = (function* () {
|
|
yield* sync({ next: step, throw: 3 })
|
|
})()
|
|
g.next()
|
|
return g.throw(new Error("x"))
|
|
}),
|
|
asyncDelegate: await attempt(async () => {
|
|
const g = (async function* () {
|
|
yield* 5
|
|
})()
|
|
return await g.next()
|
|
}),
|
|
asyncMethod: await attempt(async () => {
|
|
for await (const x of { [Symbol.asyncIterator]: 1 });
|
|
}),
|
|
asyncNextResult: await attempt(async () => {
|
|
for await (const x of asyncOf({ next: async () => 5 }));
|
|
}),
|
|
asyncReturn: await attempt(async () => {
|
|
for await (const x of asyncOf({ next: async () => step(), return: 7 })) break
|
|
}),
|
|
asyncReturnResult: await attempt(async () => {
|
|
for await (const x of asyncOf({ next: async () => step(), return: () => 5 })) break
|
|
}),
|
|
}
|