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

fix: clean up some node-api details #24178

Merged
merged 1 commit into from
Jun 12, 2024
Merged

fix: clean up some node-api details #24178

merged 1 commit into from
Jun 12, 2024

Conversation

devsnek
Copy link
Member

@devsnek devsnek commented Jun 11, 2024

  • fix a few napi_* types
  • clean up env hooks
  • implement blocking queue in tsfn
  • reduce transmutes
  • use new DataView::new api from rusty_v8

cli/napi/node_api.rs Outdated Show resolved Hide resolved
@devsnek devsnek force-pushed the x/napi-cleanup branch 2 times, most recently from 610cecf to 024efcf Compare June 11, 2024 20:28
Copy link
Member

@nathanwhit nathanwhit left a comment

Choose a reason for hiding this comment

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

LGTM

&mut env.scope(),
env_ptr,
Some(name),
constructor.unwrap(),
Copy link
Member

Choose a reason for hiding this comment

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

That looks like a potential panic :D Maybe do let ... else { return napi_invalid_arg; }?

Copy link
Member Author

Choose a reason for hiding this comment

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

its not because it comes after check_arg!(env, constructor). but yea this gets confusing and wastes performance if rust doesn't optimize it out... i'd like if check_arg!() unwrapped it automatically but there's a bit of effort needed there. maybe another followup...

let local_getter: v8::Local<v8::Value> = if let Some(getter) =
property.getter
{
create_function(&mut env.scope(), env_ptr, None, getter, property.data)
Copy link
Member

Choose a reason for hiding this comment

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

If create_function accepted &mut Env instead of env_ptr I think Rust would complain here about double mutable borrow. Should we change create_function signature?

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 would enjoy to be wrong about this but the reason i did this is because i'm not sure its possible to encode the correct borrow in rust's type system for a function which accepts &mut Env and uses env.scope() to create and return a local handle.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that might get tricky. That's fine then

@devsnek devsnek merged commit 3765e6b into main Jun 12, 2024
17 checks passed
@devsnek devsnek deleted the x/napi-cleanup branch June 12, 2024 00:40
nathanwhit pushed a commit that referenced this pull request Jun 13, 2024
- fix a few napi_* types
- clean up env hooks
- implement blocking queue in tsfn
- reduce transmutes
- use new `DataView::new` api from rusty_v8
zebreus pushed a commit to zebreus/deno that referenced this pull request Jul 8, 2024
- fix a few napi_* types
- clean up env hooks
- implement blocking queue in tsfn
- reduce transmutes
- use new `DataView::new` api from rusty_v8
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.

None yet

5 participants