@@ -80,7 +80,7 @@ pub const VM = struct {
8080};
8181
8282pub const Env = struct {
83- nat_ctx : * NativeContext ,
83+ nat_ctx : NativeContext ,
8484
8585 isolate : v8.Isolate ,
8686 isolate_params : v8.CreateParams ,
@@ -94,10 +94,11 @@ pub const Env = struct {
9494 }
9595
9696 pub fn init (
97+ self : * Env ,
9798 alloc : std.mem.Allocator ,
9899 loop : * public.Loop ,
99100 userctx : ? public.UserContext ,
100- ) anyerror ! Env {
101+ ) void {
101102
102103 // v8 values
103104 // ---------
@@ -117,13 +118,14 @@ pub const Env = struct {
117118 // ObjectTemplate for the global namespace
118119 const globals = v8 .FunctionTemplate .initDefault (isolate );
119120
120- return Env {
121- .nat_ctx = try NativeContext . init ( alloc , loop , userctx ) ,
121+ self .* = Env {
122+ .nat_ctx = undefined ,
122123 .isolate_params = params ,
123124 .isolate = isolate ,
124125 .hscope = hscope ,
125126 .globals = globals ,
126127 };
128+ NativeContext .init (& self .nat_ctx , alloc , loop , userctx );
127129 }
128130
129131 pub fn deinit (self : * Env ) void {
@@ -155,9 +157,9 @@ pub const Env = struct {
155157 }
156158
157159 // load user-defined Types into Javascript environement
158- pub fn load (self : Env , js_types : []usize ) anyerror ! void {
160+ pub fn load (self : * Env , js_types : []usize ) anyerror ! void {
159161 var tpls : [gen .Types .len ]TPL = undefined ;
160- try gen .load (self .nat_ctx , self .isolate , self .globals , TPL , & tpls );
162+ try gen .load (& self .nat_ctx , self .isolate , self .globals , TPL , & tpls );
161163 for (tpls , 0.. ) | tpl , i | {
162164 js_types [i ] = @intFromPtr (tpl .tpl .handle );
163165 }
@@ -185,8 +187,8 @@ pub const Env = struct {
185187 // TODO: is there a better way to do it at the Template level?
186188 // see https://github.com/Browsercore/jsruntime-lib/issues/128
187189 if (T_refl .proto_index ) | proto_index | {
188- const cstr_tpl = getTpl (self .nat_ctx , i );
189- const proto_tpl = getTpl (self .nat_ctx , proto_index );
190+ const cstr_tpl = getTpl (& self .nat_ctx , i );
191+ const proto_tpl = getTpl (& self .nat_ctx , proto_index );
190192 const cstr_obj = cstr_tpl .getFunction (js_ctx ).toObject ();
191193 const proto_obj = proto_tpl .getFunction (js_ctx ).toObject ();
192194 _ = cstr_obj .setPrototype (js_ctx , proto_obj );
@@ -225,7 +227,7 @@ pub const Env = struct {
225227 return self .js_ctx .? .getGlobal ();
226228 }
227229
228- pub fn bindGlobal (self : Env , obj : anytype ) anyerror ! void {
230+ pub fn bindGlobal (self : * Env , obj : anytype ) anyerror ! void {
229231 const T_refl = comptime gen .getType (@TypeOf (obj ));
230232 if (! comptime refl .isGlobalType (T_refl .T )) return error .notGlobalType ;
231233 const T = T_refl .Self ();
@@ -252,7 +254,7 @@ pub const Env = struct {
252254
253255 _ = try bindObjectNativeAndJS (
254256 self .nat_ctx .alloc ,
255- self .nat_ctx ,
257+ & self .nat_ctx ,
256258 T_refl ,
257259 nat_obj_ptr ,
258260 self .js_ctx .? .getGlobal (),
0 commit comments