-
-
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] - Implement host hooks and job queues APIs #2529
Conversation
Test262 conformance changes
|
Benchmark for 754d5b9Click to view benchmark
|
I thought a bit more about the design of this and I think I can unify the three lifetimes into only one with some lifetime trickery, making this PR a lot more lightweight! I'll make the fix today. |
1a1d18b
to
868705a
Compare
Codecov Report
@@ Coverage Diff @@
## main #2529 +/- ##
==========================================
+ Coverage 49.92% 51.07% +1.14%
==========================================
Files 377 374 -3
Lines 37557 36796 -761
==========================================
+ Hits 18751 18793 +42
+ Misses 18806 18003 -803
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
👀 |
c80e504
to
c537689
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 work. A great step in the direction of making boa more configurable for users and allowing the host implementations that the spec lists.
c537689
to
0f76a12
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.
Great job @jedel1043 , This looks perfect to me! :)
bors r+ |
Follows from #2528, and should complement #2411 to implement the module import hooks. ~~Similarly to the Intl/ICU4X PR (#2478), this has a lot of trivial changes caused by the new lifetimes. I thought about passing the queue and the hooks by value, but it was very painful having to wrap everything with `Rc` in order to be accessible by the host. In contrast, `&dyn` can be easily provided by the host and has the advantage of not requiring additional allocations, with the downside of adding two more lifetimes to our `Context`, but I think it's worth.~~ I was able to unify all lifetimes into the shortest one of the three, making our API just like before! Changes: - Added a new `HostHooks` trait and a `&dyn HostHooks` field to `Context`. This allows hosts to implement the trait for their custom type, then pass it to the context. - Added a new `JobQueue` trait and a `&dyn JobQueue` field to our `Context`, allowing custom event loops and other fun things. - Added two simple implementations of `JobQueue`: `IdleJobQueue` which does nothing and `SimpleJobQueue` which runs all jobs until all successfully complete or until any of them throws an error. - Modified `boa_cli` to run all jobs until the queue is empty, even if a job returns `Err`. This also prints all errors to the user.
Pull request successfully merged into main. Build succeeded: |
~~Builds off of #2529.~~ Merged. This Pull Request allows passing any function returning `impl Future<Output = JsResult<JsValue>>` to the `NativeFunction` constructor, allowing native concurrency hooks into the engine. It changes the following: - Adds a `NativeFunction::from_async_fn` function. - Adds a new `JobQueue::enqueue_future_job` method. - Adds an example usage on `boa_examples`.
Follows from #2528, and should complement #2411 to implement the module import hooks.
Similarly to the Intl/ICU4X PR (#2478), this has a lot of trivial changes caused by the new lifetimes. I thought about passing the queue and the hooks by value, but it was very painful having to wrap everything withI was able to unify all lifetimes into the shortest one of the three, making our API just like before!Rc
in order to be accessible by the host.In contrast,
&dyn
can be easily provided by the host and has the advantage of not requiring additional allocations, with the downside of adding two more lifetimes to ourContext
, but I think it's worth.Changes:
HostHooks
trait and a&dyn HostHooks
field toContext
. This allows hosts to implement the trait for their custom type, then pass it to the context.JobQueue
trait and a&dyn JobQueue
field to ourContext
, allowing custom event loops and other fun things.JobQueue
:IdleJobQueue
which does nothing andSimpleJobQueue
which runs all jobs until all successfully complete or until any of them throws an error.boa_cli
to run all jobs until the queue is empty, even if a job returnsErr
. This also prints all errors to the user.