@@ -923,6 +923,12 @@ export class Thread implements IVariableStoreLocationProvider {
923
923
const context = new ExecutionContext ( description ) ;
924
924
this . _executionContexts . set ( description . id , context ) ;
925
925
926
+ if ( this . _scriptWithSourceMapHandler ) {
927
+ this . _installWasmPauseHandler ( description . id ) ;
928
+ }
929
+ }
930
+
931
+ private _installWasmPauseHandler ( contextId : number ) {
926
932
// WASM files don't have sourcemaps and so aren't paused in the usual
927
933
// instrumentation BP. But we do need to pause, either to figure out the WAT
928
934
// lines or by mapping symbolicated files.
@@ -937,14 +943,14 @@ export class Thread implements IVariableStoreLocationProvider {
937
943
// }),
938
944
//
939
945
// For now, overwrite WebAssembly methods in the runtime to get the same effect. This needs to be run in event new execution context:
940
- this . _cdp . Runtime . evaluate ( {
946
+ return this . _cdp . Runtime . evaluate ( {
941
947
expression : breakOnWasmInit . expr ( ) ,
942
948
silent : true ,
943
- contextId : description . id ,
949
+ contextId,
944
950
} ) ;
945
951
}
946
952
947
- async _executionContextDestroyed ( contextId : number ) {
953
+ private async _executionContextDestroyed ( contextId : number ) {
948
954
const context = this . _executionContexts . get ( contextId ) ;
949
955
if ( ! context ) return ;
950
956
this . _executionContexts . delete ( contextId ) ;
@@ -1016,13 +1022,18 @@ export class Thread implements IVariableStoreLocationProvider {
1016
1022
}
1017
1023
1018
1024
const expectedPauseReason = this . _expectedPauseReason ;
1019
- if ( isWasmBreak && this . _lastParsedWasmScriptIds ) {
1025
+ if ( isWasmBreak ) {
1020
1026
// Resolve all pending WASM symbols when we've just initialized something
1021
1027
const ids = this . _lastParsedWasmScriptIds ;
1022
1028
this . _lastParsedWasmScriptIds = undefined ;
1023
- await Promise . all (
1024
- ids . map ( id => this . _handleSourceMapPause ( id , location ) ) ,
1025
- ) ;
1029
+ // In theory `ids` should always have something, but it seems like we
1030
+ // can see (and ignore) multiple scriptParsed events with the same ID
1031
+ // for the same program if it's WebAssembly.compile'd multiple times.
1032
+ if ( ids ) {
1033
+ await Promise . all (
1034
+ ids . map ( id => this . _handleSourceMapPause ( id , location ) ) ,
1035
+ ) ;
1036
+ }
1026
1037
return this . resume ( ) ;
1027
1038
} else if ( scriptId && ( await this . _handleSourceMapPause ( scriptId , location ) ) ) {
1028
1039
// Pause if we just resolved a breakpoint that's on this
@@ -1979,12 +1990,15 @@ export class Thread implements IVariableStoreLocationProvider {
1979
1990
// setting the URL breakpoint for wasm fails if debugger isn't fully initialized
1980
1991
await this . debuggerReady . promise ;
1981
1992
1993
+ const wasmHandlers = Promise . all ( [ ...this . _executionContexts . keys ( ) ]
1994
+ . map ( id => this . _installWasmPauseHandler ( id ) ) ) ;
1982
1995
const result = await Promise . all ( [
1983
1996
this . _cdp . Debugger . setInstrumentationBreakpoint ( {
1984
1997
instrumentation : 'beforeScriptWithSourceMapExecution' ,
1985
1998
} ) ,
1986
1999
] ) ;
1987
2000
this . _pauseOnSourceMapBreakpointIds = result . map ( r => r ?. breakpointId ) . filter ( truthy ) ;
2001
+ await wasmHandlers ;
1988
2002
} else if ( ! needsPause && this . _pauseOnSourceMapBreakpointIds ?. length ) {
1989
2003
const breakpointIds = this . _pauseOnSourceMapBreakpointIds ;
1990
2004
this . _pauseOnSourceMapBreakpointIds = undefined ;
0 commit comments