@@ -428,20 +428,8 @@ class VariableContext {
428
428
}
429
429
430
430
let variable : Variable | undefined ;
431
- if (
432
- p . name === '[[FunctionLocation]]'
433
- && p . value
434
- && ( p . value . subtype as string ) === 'internal#location'
435
- ) {
436
- variable = this . createVariable (
437
- FunctionLocationVariable ,
438
- {
439
- name : p . name ,
440
- presentationHint : { visibility : 'internal' , attributes : [ 'readOnly' ] } ,
441
- sortOrder : SortOrder . Internal ,
442
- } ,
443
- p . value ,
444
- ) ;
431
+ if ( isFunctionLocation ( p ) ) {
432
+ variable = this . createFunctionLocationVariable ( p ) ;
445
433
} else if ( p . value !== undefined ) {
446
434
variable = this . createVariableByType (
447
435
{
@@ -461,6 +449,18 @@ class VariableContext {
461
449
return flatten ( await Promise . all ( properties ) ) ;
462
450
}
463
451
452
+ public createFunctionLocationVariable ( p : FunctionLocationDescriptor ) {
453
+ return this . createVariable (
454
+ FunctionLocationVariable ,
455
+ {
456
+ name : p . name ,
457
+ presentationHint : { visibility : 'internal' , attributes : [ 'readOnly' ] } ,
458
+ sortOrder : SortOrder . Internal ,
459
+ } ,
460
+ p . value ,
461
+ ) ;
462
+ }
463
+
464
464
private async createPropertyVar (
465
465
p : AnyPropertyDescriptor ,
466
466
owner : Cdp . Runtime . RemoteObject ,
@@ -971,16 +971,19 @@ class NodeVariable extends Variable {
971
971
}
972
972
973
973
class FunctionVariable extends ObjectVariable {
974
- private readonly baseChildren = once ( ( ) => super . getChildren ( { variablesReference : this . id } ) ) ;
975
-
976
974
public override async toDap ( previewContext : PreviewContextType ) : Promise < Dap . Variable > {
977
- const [ dap , children ] = await Promise . all ( [
975
+ const [ dap , props ] = await Promise . all ( [
978
976
super . toDap ( previewContext ) ,
979
- this . baseChildren ( ) ,
977
+ this . context . cdp . Runtime . getProperties ( {
978
+ objectId : this . remoteObject . objectId ! ,
979
+ ownProperties : true ,
980
+ nonIndexedPropertiesOnly : true ,
981
+ } ) ,
980
982
] ) ;
981
983
982
- if ( children . some ( c => c instanceof FunctionLocationVariable ) ) {
983
- dap . valueLocationReference = this . id ;
984
+ const location = props ?. internalProperties ?. find ( isFunctionLocation ) ;
985
+ if ( location ) {
986
+ dap . valueLocationReference = this . context . createFunctionLocationVariable ( location ) . id ;
984
987
}
985
988
986
989
return dap ;
@@ -1580,15 +1583,8 @@ export class VariableStore {
1580
1583
}
1581
1584
1582
1585
public async getLocations ( variablesReference : number ) : Promise < Cdp . Debugger . Location > {
1583
- const container = this . vars . get ( variablesReference ) ;
1584
- if ( ! container ) {
1585
- throw errors . locationNotFound ( ) ;
1586
- }
1587
-
1588
- // note: is actually free because the container will have cached its children
1589
- const children = await container . getChildren ( { variablesReference } ) ;
1590
- const locationVar = children . find ( isInstanceOf ( FunctionLocationVariable ) ) ;
1591
- if ( ! locationVar ) {
1586
+ const locationVar = this . vars . get ( variablesReference ) ;
1587
+ if ( ! locationVar || ! ( locationVar instanceof FunctionLocationVariable ) ) {
1592
1588
throw errors . locationNotFound ( ) ;
1593
1589
}
1594
1590
@@ -1630,3 +1626,15 @@ function errorFromException(details: Cdp.Runtime.ExceptionDetails): Dap.Error {
1630
1626
|| details . text ;
1631
1627
return errors . createUserError ( message ) ;
1632
1628
}
1629
+
1630
+ type FunctionLocationDescriptor = Cdp . Runtime . InternalPropertyDescriptor & {
1631
+ value : Cdp . Debugger . Location ;
1632
+ } ;
1633
+
1634
+ function isFunctionLocation (
1635
+ p : Cdp . Runtime . InternalPropertyDescriptor ,
1636
+ ) : p is FunctionLocationDescriptor {
1637
+ return p . name === '[[FunctionLocation]]'
1638
+ && ! ! p . value
1639
+ && ( p . value . subtype as string ) === 'internal#location' ;
1640
+ }
0 commit comments