@@ -38,7 +38,7 @@ export class RubyVM {
3838 // Wrap exported functions from Ruby VM to prohibit nested VM operation
3939 // if the call stack has sandwitched JS frames like JS -> Ruby -> JS -> Ruby.
4040 const proxyExports = ( exports : RbAbi . RbAbiGuest ) => {
41- const excludedMethods : ( keyof RbAbi . RbAbiGuest ) [ ] = [ "addToImports" , "instantiate" , "rbSetShouldProhibitRewind" ] ;
41+ const excludedMethods : ( keyof RbAbi . RbAbiGuest ) [ ] = [ "addToImports" , "instantiate" , "rbSetShouldProhibitRewind" , "rbGcDisable" , "rbGcEnable" ] ;
4242 const excluded = [ "constructor" ] . concat ( excludedMethods ) ;
4343 // wrap all methods in RbAbi.RbAbiGuest class
4444 for ( const key of Object . getOwnPropertyNames ( RbAbi . RbAbiGuest . prototype ) ) {
@@ -49,15 +49,18 @@ export class RubyVM {
4949 if ( typeof value === "function" ) {
5050 exports [ key ] = ( ...args : any [ ] ) => {
5151 const isNestedVMCall = this . interfaceState . hasJSFrameAfterRbFrame ;
52- let oldValue = false ;
5352 if ( isNestedVMCall ) {
54- oldValue = this . guest . rbSetShouldProhibitRewind ( true )
53+ const oldShouldProhibitRewind = this . guest . rbSetShouldProhibitRewind ( true )
54+ const oldIsDisabledGc = this . guest . rbGcDisable ( )
55+ const result = Reflect . apply ( value , exports , args )
56+ this . guest . rbSetShouldProhibitRewind ( oldShouldProhibitRewind )
57+ if ( ! oldIsDisabledGc ) {
58+ this . guest . rbGcEnable ( )
59+ }
60+ return result ;
61+ } else {
62+ return Reflect . apply ( value , exports , args )
5563 }
56- const result = Reflect . apply ( value , exports , args )
57- if ( isNestedVMCall ) {
58- this . guest . rbSetShouldProhibitRewind ( oldValue )
59- }
60- return result ;
6164 }
6265 }
6366 }
0 commit comments