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

Async functions should be able to throw exceptions #189

Open
cpcallen opened this issue Apr 30, 2020 · 0 comments · May be fixed by #201
Open

Async functions should be able to throw exceptions #189

cpcallen opened this issue Apr 30, 2020 · 0 comments · May be fixed by #201

Comments

@cpcallen
Copy link
Collaborator

Recording this here as a known issue because it's come up in #187 and in private correspondence with @grassick:

JS Interpreter should provide a convenient mechanism for async native functions to throw errors.
At the moment it is possible to do using the following procedure:

  1. Create an Error (or subclass) object by calling myInterpreter.createObject or .createObjectProto; call this error.
  2. Call myInterpreter.unwind(Interpreter.Completion.THROW, error, undefined)
  3. Set myInterpreter.paused_ = false
  4. And of course ensure that myInterpreter.run() will get called again, to resume execution.

Step 4 will naturally always be the responsibility of the code which originally created the Interpreter instance to the embedder. Step 1 is likewise probably best left as a responsibility of the author of the native function. But Steps 2 and 3 are very much implementation details of the JS Interpreter (note that paused_ has a trailing underscore, so is supposed to be private!), so ought to be encapsulated.

One possible solution to this problem has been proposed in PR #178.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant