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

[Merged by Bors] - Prepare Promises for new host hooks and job queue API #2528

Closed
wants to merge 8 commits into from

Conversation

jedel1043
Copy link
Member

As part of the new modules PR, I was working on implementing the host hooks for the module import hooks and custom job queues. However, the promises module needed a bit of a refactor in order to couple with the new API. So, I thought it was a good idea to separate the promises refactor into its own PR, since the other PR is already big as it is.

  • Replaced some usages of JobCallback with a new NativeJob that isn't traced by the GC, since those closures are always rooted and executed by the Context globally. This will also allow hosts to pass their custom jobs to the job queue, and maybe could also accept futures in the Future (pun intended 😆).
  • Refactored several functions to account for the HostPromiseRejectionTracker hook which needs the promise JsObject.
  • Rewrote some patterns with newer Rust idioms.

@jedel1043 jedel1043 added enhancement New feature or request builtins PRs and Issues related to builtins/intrinsics execution Issues or PRs related to code execution labels Jan 11, 2023
@jedel1043 jedel1043 added this to the v0.17.0 milestone Jan 11, 2023
@github-actions
Copy link

github-actions bot commented Jan 11, 2023

Test262 conformance changes

Test result main count PR count difference
Total 94,205 94,205 0
Passed 70,348 70,348 0
Ignored 18,622 18,622 0
Failed 5,235 5,235 0
Panics 0 0 0
Conformance 74.68% 74.68% 0.00%

@codecov
Copy link

codecov bot commented Jan 11, 2023

Codecov Report

Merging #2528 (1e6a548) into main (45982ef) will increase coverage by 0.80%.
The diff coverage is 40.21%.

@@            Coverage Diff             @@
##             main    #2528      +/-   ##
==========================================
+ Coverage   50.36%   51.17%   +0.80%     
==========================================
  Files         362      373      +11     
  Lines       36691    36349     -342     
==========================================
+ Hits        18481    18601     +120     
+ Misses      18210    17748     -462     
Impacted Files Coverage Δ
boa_engine/src/builtins/async_generator/mod.rs 8.00% <0.00%> (-0.05%) ⬇️
.../src/builtins/iterable/async_from_sync_iterator.rs 15.45% <0.00%> (ø)
boa_engine/src/object/operations.rs 66.40% <0.00%> (-1.08%) ⬇️
boa_engine/src/vm/opcode/await_stm/mod.rs 0.00% <0.00%> (ø)
boa_engine/src/builtins/promise/mod.rs 23.33% <42.58%> (+2.57%) ⬆️
boa_engine/src/job.rs 84.61% <75.00%> (-15.39%) ⬇️
boa_engine/src/context/mod.rs 66.29% <100.00%> (ø)
boa_engine/src/value/equality.rs 81.94% <0.00%> (-1.39%) ⬇️
boa_engine/src/bytecompiler/mod.rs 62.93% <0.00%> (-1.02%) ⬇️
boa_engine/src/builtins/regexp/mod.rs 66.29% <0.00%> (-0.63%) ⬇️
... and 37 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@raskad raskad left a comment

Choose a reason for hiding this comment

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

Nice refactor and docs!

boa_engine/src/object/operations.rs Outdated Show resolved Hide resolved
Copy link
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

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

LGTM! Nice work! 😄

@jedel1043
Copy link
Member Author

bors r+

bors bot pushed a commit that referenced this pull request Jan 14, 2023
As part of the new modules PR, I was working on implementing the [host hooks](https://tc39.es/ecma262/#sec-host-hooks-summary) for the module import hooks and custom job queues. However, the promises module needed a bit of a refactor in order to couple with the new API. So, I thought it was a good idea to separate the promises refactor into its own PR, since the other PR is already big as it is.

- Replaced some usages of `JobCallback` with a new `NativeJob` that isn't traced by the GC, since those closures are always rooted and executed by the `Context` globally. This will also allow hosts to pass their custom jobs to the job queue, and maybe could also accept futures in the Future (pun intended 😆).
- Refactored several functions to account for the `HostPromiseRejectionTracker` hook which needs the promise `JsObject`. 
- Rewrote some patterns with newer Rust idioms.
@bors
Copy link

bors bot commented Jan 14, 2023

Pull request successfully merged into main.

Build succeeded:

@bors bors bot changed the title Prepare Promises for new host hooks and job queue API [Merged by Bors] - Prepare Promises for new host hooks and job queue API Jan 14, 2023
@bors bors bot closed this Jan 14, 2023
@bors bors bot deleted the promises-refactor2 branch January 14, 2023 01:05
bors bot pushed a commit that referenced this pull request Jan 19, 2023
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builtins PRs and Issues related to builtins/intrinsics enhancement New feature or request execution Issues or PRs related to code execution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants