8000 Fixed issues 2-4 from #860 by bardrop · Pull Request #868 · dop251/goja · GitHub
[go: up one dir, main page]

Skip to content

Fixed issues 2-4 from #860 - #868

Closed
bardrop wants to merge 1 commit into
dop251:masterfrom
bardrop-oss:fix-860-patterns
Closed

bardrop wants to merge 1 commit into
dop251:masterfrom
bardrop-oss:fix-860-patterns

Conversation

@bardrop
@bardrop bardrop commented Nov 13, 2026
Copy link
Copy Markdown
Contributor

Fixes #860. Item 1 (unary minus) is already fixed in f493a2b; this covers the other three.

2. Computed key after a getter with the same name. Non-constant computed value properties in an object literal were emitted as setElem1/setElem1Named, which do an ordinary [[Set]]. So a preceding getter made it throw, a preceding setter got called instead of the property being created, an inherited setter on Object.prototype ran, and { [k]: [] } with k = "__proto__" changed the prototype. Both instructions are only used for object literals, so they now define an own data property (writable/enumerable/configurable), like defineProp does for classes.

3. Nested patterns with defaults. In { b: [v1 = 1] = [] } the inner [v1 = 1] is first parsed as an assignment pattern (because of the = []), and reinterpretArrayAssignPatternAsBinding then passed each element to reinterpretAsDestructBindingTarget, which rejects v1 = 1. It now uses reinterpretAsBindingElement, the same as the object pattern version does. Invalid targets like [x.y = 1] or [v += 1] are still a SyntaxError.

4. await in a nested async arrow inside parameters. A block body opens a new scope, but a concise body is parsed in the enclosing one and so kept inFuncParams from the outer function. parseArrowFunctionBody now clears it for the concise body. async function f(p = await 1) {} and async function f(p = () => await 1) {} are still rejected.

Testing: three new tests in compiler_test.go (all fail on master, pass now); go test ./... passes including test262; go vet and gofmt clean.

- Computed data properties in object literals are now defined as own
  properties instead of being assigned, so a preceding getter or setter
  with the same name, an inherited setter, or __proto__ no longer
  interferes.
- Array patterns that were first parsed as assignment patterns now keep
  element initialisers when reinterpreted as binding patterns
  (e.g. `let { b: [v1 = 1] = [] } = {}`).
- A concise arrow function body no longer inherits the formal parameters
  context of the enclosing function, so `await` is allowed in
  `async function f(p = async (q) => await q) {}`.

Fixes #860.
@dop251
dop251 commented Nov 16, 2026
Copy link
Copy Markdown
Owner

See #879

@dop251 dop251 closed this Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-obj converts twice; computed key after a same-name getter throws; nested pattern with defaults rejected

2 participants

0