Merged
Conversation
Merged
df96ee4 to
1602786
Compare
napi automatically wraps and unwraps the `data` pointer on functions created through `napi_create_function`, so we don't need to use the `napi_create_external` API in neon-runtime. Instead we can work with the raw pointers. This aligns the C++ and n-api APIs so that the `neon` crate can just assume associated data for a function is always a raw pointer.
napi expects you to return a `napi_value` from your functions, instead of using `SetReturn` like in nan. I ended up having to duplicate these `invoke` implementations after all!
dherman
requested changes
Jun 13, 2020
Collaborator
dherman
left a comment
There was a problem hiding this comment.
This is incredible, and so many tests, too! Thank you for this amazing PR.
I just made a few small suggestions.
dherman
approved these changes
Jun 19, 2020
Collaborator
dherman
left a comment
There was a problem hiding this comment.
Looks great! We can ship as long as we get CI passing.
Collaborator
|
Looks like CI is passing, Travis just somehow isn't updating the PR. Merged! 🎉🎉🎉🎉🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements most simple function calls between Rust and JS code. (no thread-safe callbacks yet!) Builds on #493.
With function calls, we can start porting tests from the legacy runtime to n-api. I ported tests for objects and functions here.
There are some notable differences between NAN and n-api in how they deal with functions.
v8::Externalvalue. n-api also unwraps it for you when you ask for the data pointer. To align the two runtimes, I moved the unwrapping of thev8::Externalfor the NAN runtime intoneon-sys. Functions that were used to get data out from thev8::Externalvalue now take void pointers.get_dynamic_callback()is now a no-op but I left it in so the data format can be changed later.SetReturn()to set the return value for a function call. With n-api, you can return annapi_valuefrom your functions instead. The n-api runtime gets its ownCallbackimpl andneon_runtime::call::set_returnis unused.undefinednapi_value.The
FunctionCallbackInfostructure was one that could only be used as a reference. n-api has an opaquenapi_callback_infotype alias for a pointer, which could not be used in this way. I changedFunctionCallbackInfoto be a pointer instead.FunctionCallbackInfo<'a>, so we can't store it for longer than the actual function call lasts?