@@ -38,22 +38,13 @@ page: *Page,
3838// used to prevent recursive evalutaion
3939is_evaluating : bool ,
4040
41- // used to prevent executing scripts while we're doing a blocking load
42- is_blocking : bool = false ,
43-
4441// Only once this is true can deferred scripts be run
4542static_scripts_done : bool ,
4643
4744// List of async scripts. We don't care about the execution order of these, but
4845// on shutdown/abort, we need to cleanup any pending ones.
4946asyncs : OrderList ,
5047
51- // When an async script is ready to be evaluated, it's moved from asyncs to
52- // this list. You might think we can evaluate an async script as soon as it's
53- // done, but we can only evaluate scripts when `is_blocking == false`. So this
54- // becomes a list of scripts to execute on the next evaluate().
55- asyncs_ready : OrderList ,
56-
5748// Normal scripts (non-deferred & non-async). These must be executed in order
5849scripts : OrderList ,
5950
@@ -89,7 +80,6 @@ pub fn init(browser: *Browser, page: *Page) ScriptManager {
8980 .asyncs = .{},
9081 .scripts = .{},
9182 .deferreds = .{},
92- .asyncs_ready = .{},
9383 .sync_modules = .empty ,
9484 .is_evaluating = false ,
9585 .allocator = allocator ,
@@ -129,7 +119,6 @@ pub fn reset(self: *ScriptManager) void {
129119 self .clearList (& self .asyncs );
130120 self .clearList (& self .scripts );
131121 self .clearList (& self .deferreds );
132- self .clearList (& self .asyncs_ready );
133122 self .static_scripts_done = false ;
134123}
135124
@@ -321,10 +310,6 @@ pub fn getModule(self: *ScriptManager, url: [:0]const u8) !void {
321310}
322311
323312pub fn waitForModule (self : * ScriptManager , url : [:0 ]const u8 ) ! GetResult {
324- std .debug .assert (self .is_blocking == false );
325- self .is_blocking = true ;
326- defer self .is_blocking = false ;
327-
328313 // Normally it's dangerous to hold on to map pointers. But here, the map
329314 // can't change. It's possible that by calling `tick`, other entries within
330315 // the map will have their value change, but the map itself is immutable
@@ -398,24 +383,10 @@ fn evaluate(self: *ScriptManager) void {
398383 return ;
399384 }
400385
401- if (self .is_blocking ) {
402- // Cannot evaluate scripts while a blocking-load is in progress. Not
403- // only could that result in incorrect evaluation order, it could
404- // trigger another blocking request, while we're doing a blocking request.
405- return ;
406- }
407-
408386 const page = self .page ;
409387 self .is_evaluating = true ;
410388 defer self .is_evaluating = false ;
411389
412- // every script in asyncs_ready is ready to be evaluated.
413- while (self .asyncs_ready .first ) | n | {
414- var pending_script : * PendingScript = @fieldParentPtr ("node" , n );
415- defer pending_script .deinit ();
416- pending_script .script .eval (page );
417- }
418-
419390 while (self .scripts .first ) | n | {
420391 var pending_script : * PendingScript = @fieldParentPtr ("node" , n );
421392 if (pending_script .complete == false ) {
@@ -573,11 +544,13 @@ pub const PendingScript = struct {
573544
574545 const manager = self .manager ;
575546 self .complete = true ;
576- if (self .script .is_async ) {
577- manager .asyncs . remove ( & self . node );
578- manager . asyncs_ready . append ( & self . node ) ;
547+ if (! self .script .is_async ) {
548+ manager .evaluate ( );
549+ return ;
579550 }
580- manager .evaluate ();
551+ // async script can be evaluated immediately
552+ defer self .deinit ();
553+ self .script .eval (manager .page );
581554 }
582555
583556 fn errorCallback (self : * PendingScript , err : anyerror ) void {
@@ -601,7 +574,7 @@ pub const PendingScript = struct {
601574
602575 const script = & self .script ;
603576 if (script .is_async ) {
604- return if ( self . complete ) & self . manager . asyncs_ready else & self .manager .asyncs ;
577+ return & self .manager .asyncs ;
605578 }
606579
607580 if (script .is_defer ) {
0 commit comments