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

Implement v8 engine #17

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

Implement v8 engine #17

wants to merge 1 commit into from

Conversation

calebeby
Copy link

@calebeby calebeby commented May 3, 2024

Hello! I'm so excited to finally submit this as a PR! I began working on this about a year ago but then I set it aside because I struggled with borrowing-related challenges with v8's handles.

I finally was able to get a version of this to successfully work by closely studying higher-level v8 wrappers jstime and mini-v8. First, I tried to use those libraries directly, but I ended up needing to modify those libraries to make it work. Instead, I chose the approach of depending on v8 directly and including the wrapping code directly. The approach is most similar to the mini-v8 library, but drastically simplified to address our comparatively simple use-case.

Please let me know if you have any questions or if there are changes that you would like me to make. I'd love to get this merged!

impl V8Wrapper {
fn new() -> V8Wrapper {
INIT.call_once(|| {
let platform = v8::new_unprotected_default_platform(0, false).make_shared();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case you are wondering, you can read more about new_unprotected_default_platform in supabase/edge-runtime#227, denoland/deno#20495, and denoland/rusty_v8#1381.

It would be nice to be able to call the "protected" platform initialization on the main thread, but it seems like there is no easy way to detect if code is running on the main thread, and we don't want to accidentally initialize on a thread other than the main thread and cause a memory error. We could alternatively expose a function that calls the "protected" platform initialization, for users to themselves call it on the main thread, and then have the unprotected initialization as a fallback in case users didn't call the initialization themselves.

@calebeby
Copy link
Author

Hey @xu-cheng just wondering if you're willing to spend some time reviewing this!

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