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

Native global v2 #209

Merged
merged 10 commits into from
Mar 7, 2024
Merged

Native global v2 #209

merged 10 commits into from
Mar 7, 2024

Conversation

krichprollsch
Copy link
Member

@krichprollsch krichprollsch commented Feb 26, 2024

Bind global object with native

pub const Window = struct {
  pub const global_type = true;
};

try js_env.start(alloc);
try js_env.bindGlobal(window);
> foo();
ReferenceError: foo is not defined
> window.foo = () => true;
<- () => true
> foo();
<- true

Fix #171
Fix #203

Replace #208

@krichprollsch krichprollsch self-assigned this Feb 26, 2024
@krichprollsch krichprollsch marked this pull request as ready for review February 26, 2024 15:05
for (tpls, 0..) |tpl, i| {
js_types[i] = @intFromPtr(tpl.tpl.handle);
}
self.nat_ctx.loadTypes(js_types);

if (gen.GlobalType) |T| {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a big fan of this root declaration. Is it better to have instead a declaration at the API definition level?

src/reflect.zig Outdated
@@ -755,6 +756,10 @@ pub const Struct = struct {
}
}

pub fn is_global_type(comptime self: Struct) bool {
Copy link
Member

Choose a reason for hiding this comment

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

camelCase

Copy link
Member

Choose a reason for hiding this comment

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

new style comptime

Copy link
Member

Choose a reason for hiding this comment

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

assert comptime

@krichprollsch krichprollsch merged commit a99b12e into main Mar 7, 2024
4 checks passed
@krichprollsch krichprollsch deleted the native-global-v2 branch March 7, 2024 13:48
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.

Init js env context with a native global object Env.addObject should return the js object attached
2 participants