@@ -539,8 +539,15 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
539539 // no init, started with executor.startScope()
540540
541541 fn deinit (self : * Scope ) void {
542- for (self .destructor_callbacks .items ) | cb | {
543- cb .destructor (self );
542+ {
543+ // reverse order, as this has more chance of respecting any
544+ // dependencies objects might have with each other.
545+ const items = self .destructor_callbacks .items ;
546+ var i = items .len ;
547+ while (i > 0 ) {
548+ i -= 1 ;
549+ items [i ].destructor ();
550+ }
544551 }
545552
546553 {
@@ -1687,16 +1694,16 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
16871694 // called when the call scope ends
16881695 const DestructorCallback = struct {
16891696 ptr : * anyopaque ,
1690- destructorFn : * const fn (ptr : * anyopaque , scope : * Scope ) void ,
1697+ destructorFn : * const fn (ptr : * anyopaque ) void ,
16911698
16921699 fn init (ptr : anytype ) DestructorCallback {
16931700 const T = @TypeOf (ptr );
16941701 const ptr_info = @typeInfo (T );
16951702
16961703 const gen = struct {
1697- pub fn destructor (pointer : * anyopaque , scope : * Scope ) void {
1704+ pub fn destructor (pointer : * anyopaque ) void {
16981705 const self : T = @ptrCast (@alignCast (pointer ));
1699- return ptr_info .pointer .child .destructor (self , scope );
1706+ return ptr_info .pointer .child .destructor (self );
17001707 }
17011708 };
17021709
@@ -1706,25 +1713,25 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
17061713 };
17071714 }
17081715
1709- pub fn destructor (self : DestructorCallback , scope : * Scope ) void {
1710- self .destructorFn (self .ptr , scope );
1716+ pub fn destructor (self : DestructorCallback ) void {
1717+ self .destructorFn (self .ptr );
17111718 }
17121719 };
17131720
17141721 // An interface for types that want to have their jsScopeEnd function be
17151722 // called when the call scope ends
17161723 const CallScopeEndCallback = struct {
17171724 ptr : * anyopaque ,
1718- callScopeEndFn : * const fn (ptr : * anyopaque , scope : * Scope ) void ,
1725+ callScopeEndFn : * const fn (ptr : * anyopaque ) void ,
17191726
17201727 fn init (ptr : anytype ) CallScopeEndCallback {
17211728 const T = @TypeOf (ptr );
17221729 const ptr_info = @typeInfo (T );
17231730
17241731 const gen = struct {
1725- pub fn callScopeEnd (pointer : * anyopaque , scope : * Scope ) void {
1732+ pub fn callScopeEnd (pointer : * anyopaque ) void {
17261733 const self : T = @ptrCast (@alignCast (pointer ));
1727- return ptr_info .pointer .child .jsCallScopeEnd (self , scope );
1734+ return ptr_info .pointer .child .jsCallScopeEnd (self );
17281735 }
17291736 };
17301737
@@ -1734,8 +1741,8 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
17341741 };
17351742 }
17361743
1737- pub fn callScopeEnd (self : CallScopeEndCallback , scope : * Scope ) void {
1738- self .callScopeEndFn (self .ptr , scope );
1744+ pub fn callScopeEnd (self : CallScopeEndCallback ) void {
1745+ self .callScopeEndFn (self .ptr );
17391746 }
17401747 };
17411748 };
@@ -1815,7 +1822,7 @@ fn Caller(comptime E: type, comptime State: type) type {
18151822 // when a top-level (call_depth == 0) function ends.
18161823 if (call_depth == 0 ) {
18171824 for (scope .call_scope_end_callbacks .items ) | cb | {
1818- cb .callScopeEnd (scope );
1825+ cb .callScopeEnd ();
18191826 }
18201827
18211828 const arena : * ArenaAllocator = @alignCast (@ptrCast (scope .call_arena .ptr ));
0 commit comments