@@ -62,9 +62,7 @@ pub fn CDPT(comptime TypeProvider: type) type {
6262 session_id_gen : SessionIdGen = .{},
6363 browser_context_id_gen : BrowserContextIdGen = .{},
6464
65- browser_context : ? * BrowserContext (Self ),
66-
67- browser_context_pool : std .heap .MemoryPool (BrowserContext (Self )),
65+ browser_context : ? BrowserContext (Self ),
6866
6967 // Re-used arena for processing a message. We're assuming that we're getting
7068 // 1 message at a time.
@@ -83,17 +81,15 @@ pub fn CDPT(comptime TypeProvider: type) type {
8381 .allocator = allocator ,
8482 .browser_context = null ,
8583 .message_arena = std .heap .ArenaAllocator .init (allocator ),
86- .browser_context_pool = std .heap .MemoryPool (BrowserContext (Self )).init (allocator ),
8784 };
8885 }
8986
9087 pub fn deinit (self : * Self ) void {
91- if (self .browser_context ) | bc | {
88+ if (self .browser_context ) | * bc | {
9289 bc .deinit ();
9390 }
9491 self .browser .deinit ();
9592 self .message_arena .deinit ();
96- self .browser_context_pool .deinit ();
9793 }
9894
9995 pub fn handleMessage (self : * Self , msg : []const u8 ) bool {
@@ -127,7 +123,7 @@ pub fn CDPT(comptime TypeProvider: type) type {
127123 .cdp = self ,
128124 .arena = arena ,
129125 .sender = sender ,
130- .browser_context = if (self .browser_context ) | bc | bc else null ,
126+ .browser_context = if (self .browser_context ) | * bc | bc else null ,
131127 };
132128
133129 // See dispatchStartupCommand for more info on this.
@@ -222,7 +218,7 @@ pub fn CDPT(comptime TypeProvider: type) type {
222218 }
223219
224220 fn isValidSessionId (self : * const Self , input_session_id : []const u8 ) bool {
225- const browser_context = self .browser_context orelse return false ;
221+ const browser_context = &( self .browser_context orelse return false ) ;
226222 const session_id = browser_context .session_id orelse return false ;
227223 return std .mem .eql (u8 , session_id , input_session_id );
228224 }
@@ -231,24 +227,22 @@ pub fn CDPT(comptime TypeProvider: type) type {
231227 if (self .browser_context != null ) {
232228 return error .AlreadyExists ;
233229 }
234- const browser_context_id = self .browser_context_id_gen .next ();
230+ const id = self .browser_context_id_gen .next ();
235231
236- const browser_context = try self . browser_context_pool . create ( );
237- errdefer self .browser_context_pool . destroy ( browser_context ) ;
232+ self . browser_context = @as ( BrowserContext ( Self ), undefined );
233+ const browser_context = & self .browser_context .? ;
238234
239- try BrowserContext (Self ).init (browser_context , browser_context_id , self );
240- self .browser_context = browser_context ;
241- return browser_context_id ;
235+ try BrowserContext (Self ).init (browser_context , id , self );
236+ return id ;
242237 }
243238
244239 pub fn disposeBrowserContext (self : * Self , browser_context_id : []const u8 ) bool {
245- const bc = self .browser_context orelse return false ;
240+ const bc = &( self .browser_context orelse return false ) ;
246241 if (std .mem .eql (u8 , bc .id , browser_context_id ) == false ) {
247242 return false ;
248243 }
249244 bc .deinit ();
250245 self .browser .closeSession ();
251- self .browser_context_pool .destroy (bc );
252246 self .browser_context = null ;
253247 return true ;
254248 }
@@ -563,7 +557,7 @@ pub fn Command(comptime CDP_T: type, comptime Sender: type) type {
563557
564558 pub fn createBrowserContext (self : * Self ) ! * BrowserContext (CDP_T ) {
565559 _ = try self .cdp .createBrowserContext ();
566- self .browser_context = self .cdp .browser_context .? ;
560+ self .browser_context = &( self .cdp .browser_context .? ) ;
567561 return self .browser_context .? ;
568562 }
569563
0 commit comments