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

Implement [[HostDefined]] for Module and Script #3379

Closed
jedel1043 opened this issue Oct 12, 2023 · 2 comments · Fixed by #3381
Closed

Implement [[HostDefined]] for Module and Script #3379

jedel1043 opened this issue Oct 12, 2023 · 2 comments · Fixed by #3381
Labels
enhancement New feature or request

Comments

@jedel1043
Copy link
Member

jedel1043 commented Oct 12, 2023

We left the implementation of [[HostDefined]] fields for Script and Module as a future improvement, but it's pretty necessary for users that want to store additional data on a runnable.

Script:

#[derive(Trace, Finalize)]
struct Inner {
realm: Realm,
#[unsafe_ignore_trace]
source: boa_ast::Script,
codeblock: GcRefCell<Option<Gc<CodeBlock>>>,
loaded_modules: GcRefCell<FxHashMap<JsString, Module>>,
host_defined: (),
}

Module:

#[derive(Trace, Finalize)]
struct Inner {
realm: Realm,
environment: GcRefCell<Option<Gc<DeclarativeEnvironment>>>,
namespace: GcRefCell<Option<JsObject>>,
kind: ModuleKind,
host_defined: (),
}

Probably a simple GcRefCell<Box<dyn NativeObject>> and an accessor/mutable accessor should be enough for both.

@jedel1043 jedel1043 added the enhancement New feature or request label Oct 12, 2023
@arexon
Copy link
Contributor

arexon commented Oct 12, 2023

I'm willing to work on this.

Probably a simple GcRefCell<Box> and an accessor/mutable accessor should be enough for both.

Wouldn't this use HostDefined struct? Or is [[HostDefined]] meant to store only 1 object in Script and Module?

@jedel1043
Copy link
Member Author

Wouldn't this use HostDefined struct? Or is [[HostDefined]] meant to store only 1 object in Script and Module?

Both are good. We can implement it using HostDefined for now and if there's not much usage for storing multiple objects, we can just return to a simple Box<dyn NativeObject>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants