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 wasm example #344

Merged
merged 4 commits into from
Sep 30, 2023
Merged

Add wasm example #344

merged 4 commits into from
Sep 30, 2023

Conversation

sagudev
Copy link
Member

@sagudev sagudev commented Feb 5, 2023

env_import.handle()
));

let args = HandleValueArray::from_rooted_slice(&[
Copy link
Member

Choose a reason for hiding this comment

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

Same comment about this slice. from_rooted_slice is so easy to misuse ;_;

Comment on lines 128 to 129
let args_slice = [ObjectValue(module.get()), ObjectValue(imports.get())];
let args = HandleValueArray::from_rooted_slice(&args_slice);
Copy link
Member Author

Choose a reason for hiding this comment

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

I am not 100% sure about this one, I did it like it is done in servo/components/script/dom/paintworkletglobalscope.rs.

Copy link
Member

Choose a reason for hiding this comment

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

That code needs to be fixed as well ;_;

Copy link
Member Author

Choose a reason for hiding this comment

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

Not a Rust unsafe experienced but wrapping [ObjectValue(module.get()), ObjectValue(imports.get())] in ManuallyDrop should be enough?

Copy link
Member

@jdm jdm Feb 19, 2023

Choose a reason for hiding this comment

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

The safety risk here is that the garbage collector does not know about the slice that contains those JS values, so if they are moved for any reason (like if a GC occurs during the next spidermonkey API call), the JS values will not be updated with the new pointers. This means the handles passed as arguments would be invalid and could cause a crash.

Copy link
Member

Choose a reason for hiding this comment

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

I filed #346 about the missing pieces to make this safe.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, but we do have CustomTrace and auto_root! so

auto_root!(in(rt.cx()) let vec = vec![ObjectValue(module.get()), ObjectValue(imports.get())]);

should do it, right?

@mrobinson
Copy link
Member

Oh, perhaps I reviewed this too hastily. Maybe @jdm would look at this one as well since there were some comments before.

Copy link
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

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

Nice.

@sagudev
Copy link
Member Author

sagudev commented Sep 30, 2023

Rebased and one new commit added.

@jdm jdm added this pull request to the merge queue Sep 30, 2023
Merged via the queue into servo:master with commit 2fa4b2b Sep 30, 2023
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.

3 participants