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

Add more utility functions around modules and exports #3937

Merged
merged 8 commits into from
Aug 17, 2024

Conversation

hansl
Copy link
Contributor

@hansl hansl commented Jul 27, 2024

This allows to create a moderately simple example (see tests/gcd.rs) that can be used as a tutorial.

There are some typing issues, notably the name argument in get_typed_fn. Let's discuss.

Copy link

codecov bot commented Jul 29, 2024

Codecov Report

Attention: Patch coverage is 87.09677% with 4 lines in your changes missing coverage. Please review.

Project coverage is 51.62%. Comparing base (6ddc2b4) to head (899eab9).
Report is 231 commits behind head on main.

Files Patch % Lines
core/engine/src/object/builtins/jsfunction.rs 83.33% 2 Missing ⚠️
core/engine/src/module/mod.rs 87.50% 1 Missing ⚠️
core/engine/src/object/builtins/jspromise.rs 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3937      +/-   ##
==========================================
+ Coverage   47.24%   51.62%   +4.37%     
==========================================
  Files         476      468       -8     
  Lines       46892    44999    -1893     
==========================================
+ Hits        22154    23230    +1076     
+ Misses      24738    21769    -2969     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

/// This combines two operations that are often done together into a simpler
/// version. If you need more control over the execution, use [`load_link_evaluate`]
/// and [`Context::run_jobs`] separately.
pub fn load_link_evaluate_and_run_jobs(&self, context: &mut Context) -> JsResult<()> {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it's time to find a better name for the original function. load_link_evaluate sounds a bit spec-y and I think something like run would also be fine. That would also make the name of this function a lot shorter; run_blocking or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

eval_blocking? Either way I can make the change in this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Though about something. I think people would also want to await other promises, so maybe it should be better to add an await_ method to JsPromise? That sidesteps the need for a new method for the module, and you would just call

module.load_link_resolve(context).await_(context)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PTAL

@hansl hansl requested a review from jedel1043 August 2, 2024 19:28
Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

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

Looks perfect to me!

Comment on lines +43 to +48
#[derive(Debug, Clone, Trace, Finalize)]
pub struct TypedJsFunction<A: TryIntoJsArguments, R: TryFromJs> {
inner: JsFunction,
_args: PhantomData<A>,
_ret: PhantomData<R>,
}
Copy link
Member

Choose a reason for hiding this comment

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

Loving this new API! It should help for strictness in many ways.

@jedel1043 jedel1043 requested a review from a team August 6, 2024 15:43
@jedel1043 jedel1043 added enhancement New feature or request API labels Aug 6, 2024
@jedel1043 jedel1043 added this to the next-release milestone Aug 6, 2024
Copy link
Member

@HalidOdat HalidOdat left a comment

Choose a reason for hiding this comment

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

Looks great! :)

@jedel1043 jedel1043 added this pull request to the merge queue Aug 17, 2024
Merged via the queue into boa-dev:main with commit 50fabc8 Aug 17, 2024
14 checks passed
@hansl hansl deleted the typed_fn branch August 19, 2024 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants