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

lazy builtins #3973

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft

lazy builtins #3973

wants to merge 9 commits into from

Conversation

jasonwilliams
Copy link
Member

Lazy Builtins

@jasonwilliams jasonwilliams mentioned this pull request Aug 29, 2024
Comment on lines -390 to -399
let function = object
.downcast_mut::<NativeFunctionObject>()
.expect("Builtin must be a function object");
function.f = NativeFunction::from_fn_ptr(self.function);
function.constructor = Some(ConstructorKind::Base);
function.realm = Some(self.realm.clone());
Copy link
Member

Choose a reason for hiding this comment

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

Oops, I suggested to remove this, but I think this is still needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've made some updates to this, take a look

core/engine/src/builtins/function/mod.rs Outdated Show resolved Hide resolved
core/engine/src/object/builtins/lazy_builtin.rs Outdated Show resolved Hide resolved

#[derive(Debug, Clone, Trace, Finalize)]
pub(crate) enum BuiltinKind {
Function(JsFunction),
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, thinking a bit more about this, I think Function should store a NativeFunctionObject instead, and the builder methods should be adjusted to consider this. Else, the builder won't set the builtin to the correct value while initializing.

Comment on lines +95 to +101
if builtin.borrow().data.init_and_realm.is_some() {
let mut builtin_borrow = builtin.borrow_mut();
let (init, realm_inner) = builtin_borrow
.data
.init_and_realm
.take()
.expect("init_and_realm not set");
Copy link
Member

Choose a reason for hiding this comment

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

With the new changes this can be improved. Instead of calling init_and_realm.is_some(), then init_and_realm.take(), we can do if let Some(data) = builtin.borrow_mut().data.init_and_realm.take()

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

Successfully merging this pull request may close these issues.

2 participants