Skip to content

Hand JS functions to Pharo as QJSFunction and let Pharo call them - #9

Merged
noha merged 1 commit into
mainfrom
js-functions-to-pharo
Oct 28, 2026
Merged

noha merged 1 commit into
mainfrom
js-functions-to-pharo

Conversation

@noha

@noha noha commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

A JS function reaching Pharo, as the argument of an exposed method or as the result of an evaluation, used to arrive as its source text. It is now a QJSFunction, which understands value, value:, value:value:, cull: and valueWithArguments: like a block, so a Pharo method that takes a block takes a JS closure:

grid.rowsDo_(row => names.push(row.name()))

The shim gets qjs_value_dup, so Pharo can keep a function beyond the callback that only lends its arguments, and qjs_call, which calls it with the same stack and deadline handling as qjs_eval, now shared in enter_js/leave_js. Arguments and results take along the exposure table of the binding the function came through. A function handed back to JS is the same function again. QJSFunction frees its box through finalization.

A JS function reaching Pharo, as the argument of an exposed method or as
the result of an evaluation, used to arrive as its source text. It is now
a QJSFunction, which understands value, value:, value:value:, cull: and
valueWithArguments: like a block, so a Pharo method that takes a block
takes a JS closure:

    grid.rowsDo_(row => names.push(row.name()))

The shim gets qjs_value_dup, so Pharo can keep a function beyond the
callback that only lends its arguments, and qjs_call, which calls it with
the same stack and deadline handling as qjs_eval, now shared in
enter_js/leave_js. Arguments and results take along the exposure table of
the binding the function came through. A function handed back to JS is
the same function again. QJSFunction frees its box through finalization.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@noha
noha merged commit 2c4256e into main Oct 28, 2026
4 checks passed
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