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

A simple module loader from a function #3932

Merged
merged 8 commits into from
Sep 9, 2024
Merged

Conversation

hansl
Copy link
Contributor

@hansl hansl commented Jul 22, 2024

This will be the foundation for having a combinatoric module loader system.

This will be the foundation for having a combinatoric module loader
system.
Copy link

codecov bot commented Jul 22, 2024

Codecov Report

Attention: Patch coverage is 0% with 81 lines in your changes missing coverage. Please review.

Project coverage is 51.97%. Comparing base (6ddc2b4) to head (1f00a42).
Report is 233 commits behind head on main.

Files Patch % Lines
core/interop/src/loaders/functions.rs 0.00% 25 Missing ⚠️
core/interop/src/loaders/cached.rs 0.00% 23 Missing ⚠️
core/interop/src/loaders/filesystem.rs 0.00% 21 Missing ⚠️
core/interop/src/loaders/fallback.rs 0.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3932      +/-   ##
==========================================
+ Coverage   47.24%   51.97%   +4.72%     
==========================================
  Files         476      472       -4     
  Lines       46892    45181    -1711     
==========================================
+ Hits        22154    23481    +1327     
+ Misses      24738    21700    -3038     

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

#[derive(Copy, Clone)]
pub struct FnModuleLoader<F>(F, &'static str)
where
F: Fn(&JsString) -> Option<Module>;
Copy link
Member

@jedel1043 jedel1043 Jul 25, 2024

Choose a reason for hiding this comment

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

Was thinking that maybe this should return JsResult<Module>. We could also have a separate loader for that (FallibleFnModuleLoader or something), but it seems better to just have this be the fallible version already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm thinking here that this is the simplest way to declare a module loader, without even worry about the error type and message; either the module exists or it doesn't. Even if it doesn't parse, or any other kind of error, just say it cannot be found.

I could see a better Option<Source> though, and show errors on parsing after the function returns the source of the module. WDYT?

@jedel1043 jedel1043 added enhancement New feature or request API labels Jul 25, 2024
@jedel1043 jedel1043 added this to the next-release milestone Jul 25, 2024
@hansl hansl requested a review from jedel1043 July 29, 2024 21:26
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.

Just a minor nitpick, besides that I looks good to me! :)

core/interop/src/loaders/functions.rs Outdated Show resolved Hide resolved
@HalidOdat HalidOdat requested a review from a team August 17, 2024 16:25
@hansl hansl requested a review from HalidOdat August 19, 2024 02:49
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 great! Hopefully in the future we'll be able to remove the Clone requirement on many of the bounds, it just requires some design work around ModuleLoader.

@jedel1043 jedel1043 requested a review from a team August 23, 2024 06:44
@raskad raskad added this pull request to the merge queue Sep 9, 2024
Merged via the queue into boa-dev:main with commit c21f10e Sep 9, 2024
14 checks passed
hansl added a commit to hansl/boa that referenced this pull request Sep 12, 2024
* A simple module loader from a function

This will be the foundation for having a combinatoric module loader
system.

* Add more utility module loader types

* clippies

* Remove convenience functions and allow AsRef<Path> for constructing fs

* clippies

* Move FnModuleLoader to return a result, and add a new simpler loader

* Address comment
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.

4 participants