Skip to content

feat(runtime): redesign the JavaScript evaluation API around named arguments - #661

Draft
route wants to merge 1 commit into
mainfrom
feat/js-api-final
Draft

route wants to merge 1 commit into
mainfrom
feat/js-api-final

Conversation

@route

@route route commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

The combined end state of #659 and #660, as one diff from main, for reviewing the final design without the compatibility layer that #659 adds and #660 removes. Its tree is identical to #660's branch.

Kept as a draft: the plan is to merge #659 for 0.20, then #660 for 0.21.

…guments

`#evaluate`, `#evaluate_async`, `#execute`, `#evaluate_func` and `#evaluate_on` had four argument conventions and three
return semantics between them, and scripts reached their arguments through `arguments[0]`. Now there are three entry
points sharing one convention, plus the same three on `Node` with `this` bound to the element:

- Keyword arguments become the script's parameters, `page.evaluate("a + b", a: 1, b: 2)`, bound by name when the script
  is a function declaration. Positional arguments keep working through `arguments[n]` but can't be mixed with them.
- A script is an expression, which gets wrapped, or a function/arrow declaration, used as-is. Scripts are read by a
  small scanner, `Frame::Script`, that skips strings, template literals, regular expressions and comments.
- A returned promise or thenable is awaited, bounded by `timeout:` and raising `ScriptTimeoutError`, now a
  `TimeoutError`. `await` works directly.
- `#evaluate_handle` returns a `Ferrum::RemoteObject`, and `Node#execute`/`Node#evaluate_handle` are added.
- `#evaluate_async`, `#evaluate_func` and `#evaluate_on` are removed.

This is the end state of the two-step migration that first ships the new API next to the old one with warnings.
@route
route force-pushed the feat/js-api-final branch from 6d3f7c8 to 19f318d Compare October 21, 2026 19:20
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.

1 participant