Make all built-in constructors public
This Pull Request makes all our built-in constructors public. This should ensure our users can still construct objects from Rust without having to compile and run any JS code.
Test262 conformance changes
VM implementation
| Test result | main count | PR count | difference |
|---|---|---|---|
| Total | 90,619 | 90,619 | 0 |
| Passed | 56,885 | 56,885 | 0 |
| Ignored | 13,788 | 13,788 | 0 |
| Failed | 19,946 | 19,946 | 0 |
| Panics | 0 | 0 | 0 |
| Conformance | 62.77% | 62.77% | 0.00% |
Codecov Report
Merging #2137 (f2cb13d) into main (613f4c3) will not change coverage. The diff coverage is
65.51%.
@@ Coverage Diff @@
## main #2137 +/- ##
=======================================
Coverage 43.51% 43.51%
=======================================
Files 220 220
Lines 20015 20015
=======================================
Hits 8710 8710
Misses 11305 11305
| Impacted Files | Coverage Δ | |
|---|---|---|
| boa_engine/src/builtins/array_buffer/mod.rs | 9.42% <0.00%> (ø) |
|
| boa_engine/src/builtins/dataview/mod.rs | 8.08% <0.00%> (ø) |
|
| boa_engine/src/builtins/error/aggregate.rs | 38.88% <0.00%> (ø) |
|
| boa_engine/src/builtins/function/mod.rs | 24.34% <0.00%> (ø) |
|
| boa_engine/src/builtins/generator/mod.rs | 10.86% <0.00%> (ø) |
|
| boa_engine/src/builtins/generator_function/mod.rs | 77.27% <0.00%> (ø) |
|
| boa_engine/src/builtins/intl/date_time_format.rs | 56.25% <0.00%> (ø) |
|
| boa_engine/src/builtins/proxy/mod.rs | 8.82% <0.00%> (ø) |
|
| boa_engine/src/builtins/typed_array/mod.rs | 3.74% <0.00%> (ø) |
|
| boa_engine/src/builtins/array/mod.rs | 75.03% <100.00%> (ø) |
|
| ... and 18 more |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 613f4c3...f2cb13d. Read the comment docs.
Marking as draft since it's missing some documentation
So, I just realized we don't really need to expose the constructors because we already have them exposed in the intrinsics of Context:
let constructor = context.intrinsics().constructors().$constructor_type().constructor();
let obj = constructor.construct(args, None, context)?;
However, it can be argued that is not as "pretty" as calling
let obj = ConstructorType::constructor(context.intrinsics().constructors().$constructor_type().constructor(), args, context)?;
So exposing the constructors has still some readability value. On the other hand, a user doesn't really need to know the internals of how constructors work in order to use the first method, but with the second method they would need to know to always pass the correct constructor every time.
I'm inclined for the first method, because it's easier to use and it just needs some documentation with examples, unlike the second method which exposes a big chunk of new methods. What do you think?
I'm inclined for the first method, because it's easier to use and it just needs some documentation with examples, unlike the second method which exposes a big chunk of new methods. What do you think?
I completely agree with this. I think we could also build some abstraction based on that method in the future, if the readability becomes a big enough issue.
I believe this to be a blocking issue for my use-case, where I'd like to initialize the context with a custom set of built-ins, which requires these builtin modules (structs, constructors, etc) to be accessible outside of the boa_engine itself. I posted more about this here: https://discord.com/channels/595323158140158003/595382036215365633/1031513873636917319
Gonna close this because advanced users can access all builtin objects from the Intrinsics struct, so exposing all constructors is not necessary. We can reopen this in the future if there's a need to expose the builtins.