Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add undocumented/private API to hook into when a new frame is created. #701

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adamscybot
Copy link

@adamscybot adamscybot commented Jun 8, 2024

This is a small change to add a new hook, similar to __evaluate_entry and __evaluate_exit, but for when a new frame is created from an old one. I am building an open-source pluggable framework around JSonata, and this small change will open up an enormous amount of awesome possibilities.

It is beneficial for advanced cases like modifying env with additional metadata or mutating it so that you can analyse bind/lookup calls & provide diagnostics. I have actually patially achieved this already to significant effect by hooking into the env on __evaluate_entry. However, in some cases inside the JSONata core, a new frame is created, which is then immediately bound to, and consequently that happens before it has yet to recurse through evaluate and the entry callback. That means that callback is unable to capture everything for these advance pro-mode use cases. This new callback would enable that possibility.

I accept this will be undocumented and could change in the future.

The callback is set via a Symbol, so it can not be manipulated or read inside a query. See #700, which would need to be merged first, both as approval of the general Symbol approach and because the minor TS def changes are needed from there.

Signed-off-by: Adam Thomas adam@adam-thomas.co.uk

This is helpful in scenarios where you wish to debug the environment
behavior, or modify the env for advanced scenarios.

As the callback is set via a Symbol, it can not be manipulated
or read inside a query. See jsonata-js/jsonata/jsonata-js#700.
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