@@ -477,7 +477,7 @@ function createCommandContext(inspector) {
477477 const scripts = { } ;
478478 const watchedExpressions = [ ] ;
479479
480- const knownBreakpoints = new Map ( ) ;
480+ const knownBreakpoints = [ ] ;
481481
482482 const writer = createRemoteAwareWriter ( true ) ;
483483 const formatValue = value => writer ( value ) ;
@@ -504,19 +504,30 @@ function createCommandContext(inspector) {
504504 }
505505 }
506506
507- function convertResultToRemoteObject ( { result, wasThrown } ) {
507+ function convertResultToError ( result ) {
508508 const { className, description } = result ;
509- if ( wasThrown ) {
510- const err = new Error ( extractErrorMessage ( description ) ) ;
511- err . stack = description ;
512- Object . defineProperty ( err , 'name' , { value : className } ) ;
513- return err ;
514- }
509+ const err = new Error ( extractErrorMessage ( description ) ) ;
510+ err . stack = description ;
511+ Object . defineProperty ( err , 'name' , { value : className } ) ;
512+ return err ;
513+ }
514+
515+ function convertResultToRemoteObject ( { result, wasThrown } ) {
516+ if ( wasThrown ) return convertResultToError ( result ) ;
515517 return new Proxy ( new RemoteObject ( result ) , createRemoteObjectProxyHandler ( inspector . client ) ) ;
516518 }
517519
518520 function handleBreakpointResolved ( { breakpointId, location } ) {
519- knownBreakpoints . set ( breakpointId , location ) ;
521+ const isExisting = knownBreakpoints . some ( bp => {
522+ if ( bp . breakpointId === breakpointId ) {
523+ bp . location = location ;
524+ return true ;
525+ }
526+ return false ;
527+ } ) ;
528+ if ( ! isExisting ) {
529+ knownBreakpoints . push ( { breakpointId, location } ) ;
530+ }
520531 }
521532
522533 const ctx = {
@@ -614,7 +625,10 @@ function createCommandContext(inspector) {
614625 callFrameId : currentFrame ,
615626 expression : `debug(${ script . slice ( 0 , - 2 ) } )` ,
616627 includeCommandLineAPI : true ,
617- } ) . then ( ( ) => undefined ) ; // hide the noise
628+ } ) . then ( ( { result, wasThrown } ) => {
629+ if ( wasThrown ) return convertResultToError ( result ) ;
630+ return undefined ; // This breakpoint can't be removed the same way
631+ } ) ;
618632 }
619633
620634 // setBreakpoint('scriptname')
@@ -655,6 +669,11 @@ function createCommandContext(inspector) {
655669 . then ( registerBreakpoint ) ;
656670 } ,
657671
672+ clearBreakpoint ( ) {
673+ // TODO: Use Debugger.removeBreakpoint({ breakpointId })
674+ throw new Error ( 'Not implemented' ) ;
675+ } ,
676+
658677 get cont ( ) {
659678 return Debugger . resume ( ) ;
660679 } ,
@@ -703,8 +722,8 @@ function createCommandContext(inspector) {
703722 }
704723
705724 let isBreakpoint = false ;
706- knownBreakpoints . forEach ( actualLocation => {
707- if ( actualLocation . scriptId === scriptId && ( actualLocation . lineNumber + 1 ) === i ) {
725+ knownBreakpoints . forEach ( ( { location } ) => {
726+ if ( location . scriptId === scriptId && ( location . lineNumber + 1 ) === i ) {
708727 isBreakpoint = true ;
709728 }
710729 } ) ;
0 commit comments