@@ -6,7 +6,7 @@ import * as Platform from '../../core/platform/platform.js';
66import * as SDK from '../../core/sdk/sdk.js' ;
77import type * as Protocol from '../../generated/protocol.js' ;
88import { createTarget } from '../../testing/EnvironmentHelpers.js' ;
9- import { describeWithMockConnection } from '../../testing/MockConnection.js' ;
9+ import { describeWithMockConnection , setMockConnectionResponseHandler } from '../../testing/MockConnection.js' ;
1010import { createResource , getMainFrame } from '../../testing/ResourceTreeHelpers.js' ;
1111import * as TextUtils from '../text_utils/text_utils.js' ;
1212import * as Workspace from '../workspace/workspace.js' ;
@@ -51,6 +51,9 @@ describeWithMockConnection('ResourceMapping', () => {
5151 endColumn : 0 ,
5252 sourceURL : urlString `webpack:///src/foo.js` ,
5353 hasSourceURLComment : true ,
54+ source : `\nfunction foo() { console.log("foo"); }
55+ foo();
56+ //# sourceURL=webpack:///src/foo.js` ,
5457 } ,
5558 {
5659 scriptId : '2' as Protocol . Runtime . ScriptId ,
@@ -60,6 +63,7 @@ describeWithMockConnection('ResourceMapping', () => {
6063 endColumn : 27 ,
6164 sourceURL : url ,
6265 hasSourceURLComment : false ,
66+ source : 'console.log("bar");' ,
6367 } ,
6468 ] ;
6569 const OTHER_SCRIPT_ID = '3' as Protocol . Runtime . ScriptId ;
@@ -97,6 +101,15 @@ describeWithMockConnection('ResourceMapping', () => {
97101 undefined , hasSourceURLComment , false , length , false , null , null , null , null , embedderName , null ) ;
98102 } ) ;
99103 assert . lengthOf ( debuggerModel . scripts ( ) , SCRIPTS . length ) ;
104+
105+ setMockConnectionResponseHandler ( 'Debugger.getScriptSource' , param => {
106+ return {
107+ scriptSource : SCRIPTS . find ( s => s . scriptId === param . scriptId ) ?. source ?? '' ,
108+ getError ( ) {
109+ return undefined ;
110+ } ,
111+ } ;
112+ } ) ;
100113 } ) ;
101114
102115 it ( 'creates UISourceCode for added target' , ( ) => {
@@ -251,4 +264,26 @@ describeWithMockConnection('ResourceMapping', () => {
251264 assert . deepEqual ( mappedLines , expectedLines ) ;
252265 } ) ;
253266 } ) ;
267+
268+ describe ( 'functionBoundsAtRawLocation' , ( ) => {
269+ function makeLocation ( script : typeof SCRIPTS [ number ] , line : number , column : number ) : SDK . DebuggerModel . Location {
270+ return new SDK . DebuggerModel . Location ( debuggerModel , script . scriptId , line , column ) ;
271+ }
272+
273+ it ( 'finds the function bounds for an inline script' , async ( ) => {
274+ const functionBounds = await resourceMapping . functionBoundsAtRawLocation ( makeLocation ( SCRIPTS [ 0 ] , 5 , 16 ) ) ;
275+ assert . isOk ( functionBounds ) ;
276+ // TODO(crbug.com/452333154)
277+ // assert.strictEqual(functionBounds.name, 'foo');
278+ assert . strictEqual ( functionBounds . range . startLine , 5 ) ;
279+ assert . strictEqual ( functionBounds . range . startColumn , 12 ) ;
280+ assert . strictEqual ( functionBounds . range . endLine , 5 ) ;
281+ assert . strictEqual ( functionBounds . range . endColumn , 38 ) ;
282+ } ) ;
283+
284+ it ( 'finds no function bounds for an inline script with no functions' , async ( ) => {
285+ const functionBounds = await resourceMapping . functionBoundsAtRawLocation ( makeLocation ( SCRIPTS [ 1 ] , 11 , 9 ) ) ;
286+ assert . isNotOk ( functionBounds ) ;
287+ } ) ;
288+ } ) ;
254289} ) ;
0 commit comments