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 Isolate.ThrowException(exception) support #90

Closed
robfig opened this issue Mar 10, 2021 · 2 comments · Fixed by #221
Closed

Add Isolate.ThrowException(exception) support #90

robfig opened this issue Mar 10, 2021 · 2 comments · Fixed by #221

Comments

@robfig
Copy link
Contributor

robfig commented Mar 10, 2021

Thanks for amazing project! Very exciting to be able to use v8 so easily.

I'm providing my JS script an API implemented with a Go FunctionCallback. If an error occurs, how do I signal that to the caller? Throwing a JS error seems like the correct route, but I don't see any way to do that.

For example

	
	global, _ := v8go.NewObjectTemplate(iso)
	fn, _ := v8go.NewFunctionTemplate(iso, func(info *v8go.FunctionCallbackInfo) *v8go.Value {
		// HOW TO RAISE A JS ERROR?
		return nil
	})
	global.Set("myfn", fn)

Thank you

@rogchap
Copy link
Owner

rogchap commented Mar 18, 2021

Hey @robfig
Thanks for your interest in the project.
This is unfortunately not possible 😢
I had tried to get this to work as part of the Basic Promise PR, but I had issues creating Error values... just kept crashing.
I left it out for now but plan to work on it to have it working again. Ref: #76 (comment)

@dylanahsmith
Copy link
Collaborator

If you use the latest changes on master, then there is now a Function.NewInstance function that can be used to call a function as a constructor (e.g. like new Error(message)). I think the only thing left is to add an Isolate.ThrowException method.

A workaround would be to execute some JS code to throw the exception (or define a function to do that). This code is on the slow path, so that may be acceptable.

@dylanahsmith dylanahsmith changed the title Question - Raising an error from a FunctionCallback Add Isolate.ThrowException(exception) support Aug 19, 2021
@genevieve genevieve linked a pull request Nov 9, 2021 that will close this issue
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 a pull request may close this issue.

3 participants