opencode/packages/codemode-rust/conformance/cases/lang-arguments-object.js
kommander 03066b4ba3 fix(codemode): delete, arguments, await names and iterator errors match the reference
- 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.
2026-11-18 18:56:10 +01:00

39 lines
1.2 KiB
JavaScript

// The arguments object: indexed own properties that delete leaves as holes, a hidden writable length, and a
// binding that can be reassigned.
function f() {
const deleted = delete arguments[1]
arguments.extra = "x"
return {
deleted,
afterDelete: [typeof arguments[1], 1 in arguments, arguments.length],
keys: Object.keys(arguments),
spread: [...arguments],
json: JSON.stringify(arguments),
tag: Object.prototype.toString.call(arguments),
}
}
function g() {
arguments.length = "two"
const lengthWritten = [arguments.length, arguments.hasOwnProperty("length"), Object.keys(arguments).length]
arguments.length = 1
const applied = ((...xs) => xs).apply(null, arguments)
const deleted = delete arguments.length
return { lengthWritten, applied, deleted, after: arguments.length }
}
function h(a) {
arguments = [9]
const fromArrow = (() => {
arguments = "arrow"
return arguments
})()
return [a, arguments, fromArrow]
}
function frozen() {
Object.freeze(arguments)
try {
arguments[0] = 2
} catch (error) {
return [String(error), arguments[0]]
}
}
return { f: f(1, 2, 3), g: g(1, 2, 3), h: h(1), frozen: frozen(1) }