From a4b2398aba2211ce5901ceb46f73057864bd1707 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Tue, 6 Oct 2026 14:12:03 +0200 Subject: add global registry --- src/z/Env/Object.zig | 29 +++++++++++++++++++++++++++++ src/z/Env/root.zig | 7 ++----- 2 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 src/z/Env/Object.zig (limited to 'src/z/Env') diff --git a/src/z/Env/Object.zig b/src/z/Env/Object.zig new file mode 100644 index 0000000..77afa1f --- /dev/null +++ b/src/z/Env/Object.zig @@ -0,0 +1,29 @@ +const Env = @import("root.zig"); +const AnyFuture = Env.AnyFuture; +const Future = Env.Future; + +const Self = @This(); + +pub inline fn get(self: *Self, env: *Env, key: anytype) AnyFuture { + return env.getProp(self, key); +} + +pub inline fn set(self: *Self, env: *Env, key: anytype, value: anytype) Future(.undefined) { + return env.setProp(self, key, value); +} + +pub inline fn delete(self: *Self, env: *Env, key: anytype) Future(.undefined) { + return env.deleteProp(self, key); +} + +pub inline fn call(self: *Self, env: *Env, method: @EnumLiteral(), args: anytype) AnyFuture { + return env.callMethod(self, @tagName(method), args); +} + +pub inline fn free(self: *Self, env: *Env) Future(.undefined) { + return env.free(self); +} + +pub fn new(self: *Self, env: *Env) Future(.object) { + return env.new(self, .{}); +} diff --git a/src/z/Env/root.zig b/src/z/Env/root.zig index 99b47c5..5a08362 100644 --- a/src/z/Env/root.zig +++ b/src/z/Env/root.zig @@ -1,6 +1,5 @@ const std = @import("std"); -const mod = @import("../root.zig"); const js = @import("js.zig"); const Self = @This(); @@ -10,9 +9,7 @@ const future = @import("future.zig"); pub const AnyFuture = future.AnyFuture; pub const Future = future.Future; pub const Value = @import("value.zig").Value; -pub const Object = extern struct {}; - -pub const window: *Object = @ptrFromInt(1); +pub const Object = @import("Object.zig"); calls: std.ArrayList(Call) = .empty, values: std.ArrayList(Value) = .empty, @@ -56,7 +53,7 @@ pub fn setProp( pub fn deleteProp( self: *Self, object: *Object, - key: []const u8, + key: anytype, ) Future(.undefined) { self.calls.append(self.gpa, .{ .kind = .del_prop, -- cgit v1.2.3-70-g09d2