Skip to content

Conversation

@karlseguin
Copy link
Collaborator

Back in the zig-js-runtime days, globals were used for the state and webapi declarations. This caused problems largely because it was done across compilation units (using @import("root")...).

The generic Env(S, WebApi) was used to solve these problems, while still making it work for different States and WebApis.

This change removes the generics and hard-codes the *Page as the state and only supports our WebApis for the class declarations.

To accommodate this change, the runtime/tests have been removed. I don't consider this a huge loss - whatever behavior these were testing, already exists in the browser/**/*.zig web api.

As we write more complex/complete WebApis, we're seeing more and more cases that need to rely on js objects directly (JsObject, Function, Promises, etc...). The goal is to make these easier to use. Rather than using Env.JsObject, you now import "js.zig" and use js.JsObject (TODO: rename JsObject to Object). Everything is just a plain Zig struct, rather than being nested in a generic.

After this change, I plan on:

1 - Renaming the js objects, JsObject -> Object. These should be referenced in
the webapi as js.Object, js.This, ...

2 - Splitting the code across multiple files (Env.zig, Context.zig,
Caller.zig, ...)

Back in the zig-js-runtime days, globals were used for the state and webapi
declarations. This caused problems largely because it was done across
compilation units (using @import("root")...).

The generic Env(S, WebApi) was used to solve these problems, while still making
it work for different States and WebApis.

This change removes the generics and hard-codes the *Page as the state and
only supports our WebApis for the class declarations.

To accommodate this change, the runtime/*tests* have been removed. I don't
consider this a huge loss - whatever behavior these were testing, already
exists in the browser/**/*.zig web api.

As we write more complex/complete WebApis, we're seeing more and more cases
that need to rely on js objects directly (JsObject, Function, Promises, etc...).
The goal is to make these easier to use. Rather than using Env.JsObject, you
now import "js.zig" and use js.JsObject (TODO: rename JsObject to Object).
Everything is just a plain Zig struct, rather than being nested in a generic.

After this change, I plan on:

1 - Renaming the js objects, JsObject -> Object. These should be referenced in
    the webapi as js.Object, js.This, ...

2 - Splitting the code across multiple files (Env.zig, Context.zig,
    Caller.zig, ...)
@karlseguin karlseguin merged commit 66f82fd into main Oct 2, 2025
10 checks passed
@karlseguin karlseguin deleted the remove_generic_js branch October 2, 2025 02:58
@github-actions github-actions bot locked and limited conversation to collaborators Oct 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants