Skip to content

Conversation

@dherman
Copy link
Collaborator

@dherman dherman commented Oct 29, 2021

This PR experiments with a modified .call() and .construct() API for JsFunction, based on the ideas we came up with in #796 as well as the idea of overloading result types to make downcasting more concise and ergonomic. The changes include:

  • Uses the Arguments trait instead of IntoIterator, which still works for Vec and arrays but also heterogeneous tuples
  • Overloads and downcasts to the result type
  • Adds the .exec() method for discarding the result when it's not needed

This generally leads to more concise and readable code. But it has a few downsides:

  • The difference between arrays and tuples is subtle: heterogeneous vs homogeneous types, and the fact that empty arrays ([]) tend to lead to inference errors where empty tuples (()) usually work, could both be confusing especially to newer Rust programmers.
  • You still tend to end up having to compute arguments in previous statements in order to use cx, whereas the method chaining approach in Arguments builder API #796 circumvents this issue.
  • Downcasting with turbofish requires three blank type parameters (_) to be passed after the result type.
  • Always downcasting, even when the result type is JsValue, may not be able to be made zero cost. (But this is probably most often needed for discarding the result, in which case .exec() avoids the downcast overhead.)

I wanted to implement this before we finalize the builder APIs, so that we can consider the complete set of function call APIs holistically.

kjvalencik and others added 27 commits August 30, 2021 14:35
feat(neon): Add `JoinHandle` as a result of `Channel::send`
Initial implementation for JsPromise and TaskBuilder
…a panic

* Catches panics and converts to uncaughtException
* Throws uncaughtException if throwing
* Passes opaque exceptions through as JsBox
fix(neon): Fix undefined behavior in channel callbacks when there is a panic
Catch panics in tasks and convert to rejections
@dherman
Copy link
Collaborator Author

dherman commented Oct 29, 2021

Grrr, why did this think it was a PR against main… this was supposed to be against next/0.10.

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