-
-
Notifications
You must be signed in to change notification settings - Fork 411
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
[Merged by Bors] - Redesign native functions and closures API #2499
Conversation
Test262 conformance changes
|
Codecov Report
@@ Coverage Diff @@
## main #2499 +/- ##
==========================================
+ Coverage 51.50% 51.64% +0.14%
==========================================
Files 358 356 -2
Lines 35755 35766 +11
==========================================
+ Hits 18414 18473 +59
+ Misses 17341 17293 -48
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Benchmark for 7e18e7aClick to view benchmark
|
Will disable the benchmark, since everything looks good. |
609a24f
to
1d18d8f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of this looks good to me. NativeCallable
makes sense the more I think about it. Maybe, NativeCallableFn
to be a bit more specific. I'm not entirely sure about it being in the function
module, and after looking at this, I'm also a bit curious about FunctionBuilder
too, as we use the term function in a lot of different contexts that it may be ambiguous at times. Maybe function
-> native_function
/native_fn
and FunctionBuilder
-> FunctionObjectBuilder
.
b08d19a
to
6bff1d0
Compare
Sounds good! Though, if we're changing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me 😄
70d45d1
to
24d7e04
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice changes. Great work on the docs too!
bors r+ |
This PR is a complete redesign of our current native functions and closures API. I was a bit dissatisfied with our previous design (even though I created it 😆), because it had a lot of superfluous traits, a forced usage of `Gc<GcCell<T>>` and an overly restrictive `NativeObject` bound. This redesign, on the other hand, simplifies a lot our public API, with a simple `NativeCallable` struct that has several constructors for each type of required native function. This new design doesn't require wrapping every capture type with `Gc<GcCell<T>>`, relaxes the trait requirement to `Trace + 'static` for captures, can be reused in both `JsObject` functions and (soonish) host defined functions, and is (in my opinion) a bit cleaner than the previous iteration. It also offers an `unsafe` API as an escape hatch for users that want to pass non-Copy closures which don't capture traceable types. Would ask for bikeshedding about the names though, because I don't know if `NativeCallable` is the most precise name for this. Same about the constructor names; I added the `from` prefix to all of them because it's the "standard" practice, but seeing the API doesn't have any other method aside from `call`, it may be better to just remove the prefix altogether. Let me know what you think :)
Pull request successfully merged into main. Build succeeded: |
This PR is a complete redesign of our current native functions and closures API.
I was a bit dissatisfied with our previous design (even though I created it 😆), because it had a lot of superfluous traits, a forced usage of
Gc<GcCell<T>>
and an overly restrictiveNativeObject
bound. This redesign, on the other hand, simplifies a lot our public API, with a simpleNativeCallable
struct that has several constructors for each type of required native function.This new design doesn't require wrapping every capture type with
Gc<GcCell<T>>
, relaxes the trait requirement toTrace + 'static
for captures, can be reused in bothJsObject
functions and (soonish) host defined functions, and is (in my opinion) a bit cleaner than the previous iteration. It also offers anunsafe
API as an escape hatch for users that want to pass non-Copy closures which don't capture traceable types.Would ask for bikeshedding about the names though, because I don't know if
NativeCallable
is the most precise name for this. Same about the constructor names; I added thefrom
prefix to all of them because it's the "standard" practice, but seeing the API doesn't have any other method aside fromcall
, it may be better to just remove the prefix altogether.Let me know what you think :)