Skip to content

Commit aed1287

Browse files
committed
fix: wait for debugger to be enabled before setting bps in vs
Fixes #1109
1 parent 310d785 commit aed1287

File tree

7 files changed

+18
-63
lines changed

7 files changed

+18
-63
lines changed

src/adapter/breakpoints.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,13 @@ export class BreakpointManager {
525525
await promise;
526526
}
527527

528+
const thread = this._thread;
529+
if (thread?.debuggerReady.hasSettled() === false) {
530+
const promise = thread.debuggerReady.promise;
531+
this.addLaunchBlocker(promise);
532+
await promise;
533+
}
534+
528535
// Creates new breakpoints for the parameters, unsetting any previous
529536
// breakpoints that don't still exist in the params.
530537
const mergeInto = (previous: UserDefinedBreakpoint[]): ISetBreakpointResult => {
@@ -594,7 +601,6 @@ export class BreakpointManager {
594601
this._uninstallSourceMapHandler(this._thread);
595602
}
596603

597-
const thread = this._thread;
598604
if (thread && result.new.length) {
599605
// This will add itself to the launch blocker if needed:
600606
this.ensureModuleEntryBreakpoint(thread, params.source);

src/adapter/threads.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ export class Thread implements IVariableStoreDelegate {
157157
private readonly _dap: DeferredContainer<Dap.Api>;
158158
private disposed = false;
159159

160+
public debuggerReady = getDeferred<void>();
161+
160162
/**
161163
* Details set when a "step in" is issued. Used allow async stepping in
162164
* sourcemapped worker scripts.
@@ -614,6 +616,7 @@ export class Thread implements IVariableStoreDelegate {
614616
// There is a bug in Chrome that does not retain debugger id
615617
// across cross-process navigations. Refresh it upon clearing contexts.
616618
this._cdp.Debugger.enable({}).then(response => {
619+
this.debuggerReady.resolve();
617620
if (response) {
618621
Thread._allThreadsByDebuggerId.set(response.debuggerId, this);
619622
}

src/test/evaluate/evaluate-auto-expands-getter-447.txt

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,12 @@
1212
> [[Prototype]]: Object
1313
> foo (set): ƒ foo(x) {}
1414
> [[Prototype]]: Object
15-
> foo (set): ƒ foo(x) {}
16-
> [[Prototype]]: Object
17-
> arguments (get): ƒ ()
18-
> arguments (set): ƒ ()
19-
> caller (get): ƒ ()
20-
> caller (set): ƒ ()
21-
length: 1
22-
> [[Prototype]]: ƒ ()
23-
> [[Scopes]]: Scopes[0]
2415

2516
> result: {}
2617
foo: 42
2718
> [[Prototype]]: Object
2819
foo: 42
2920
> [[Prototype]]: Object
30-
foo: 42
31-
> [[Prototype]]: Object
32-
> arguments (get): ƒ ()
33-
> arguments (set): ƒ ()
34-
> caller (get): ƒ ()
35-
> caller (set): ƒ ()
36-
length: 1
37-
> [[Prototype]]: ƒ ()
38-
> [[Scopes]]: Scopes[0]
3921

4022
> result: {}
4123
> foo (get): ƒ foo() { throw 'wat'; }
@@ -51,27 +33,9 @@
5133
> [[Prototype]]: Object
5234
> foo (get): ƒ foo() { throw 'wat'; }
5335
> [[Prototype]]: Object
54-
> foo (get): ƒ foo() { throw 'wat'; }
55-
> [[Prototype]]: Object
56-
> arguments (get): ƒ ()
57-
> arguments (set): ƒ ()
58-
> caller (get): ƒ ()
59-
> caller (set): ƒ ()
60-
length: 1
61-
> [[Prototype]]: ƒ ()
62-
> [[Scopes]]: Scopes[0]
6336

6437
> result: {}
6538
> [[Prototype]]: Object
6639
normalObject: true
6740
> [[Prototype]]: Object
68-
normalObject: true
69-
> [[Prototype]]: Object
70-
> arguments (get): ƒ ()
71-
> arguments (set): ƒ ()
72-
> caller (get): ƒ ()
73-
> caller (set): ƒ ()
74-
length: 1
75-
> [[Prototype]]: ƒ ()
76-
> [[Scopes]]: Scopes[0]
7741

src/test/evaluate/evaluate-default.txt

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,13 @@ result: 3
5252
> [[Prototype]]: Object
5353
> foo (set): ƒ foo(x) {}
5454
> [[Prototype]]: Object
55-
> Object
56-
> arguments (get): ƒ ()
57-
> arguments (set): ƒ ()
58-
> caller (get): ƒ ()
59-
> caller (set): ƒ ()
60-
length: 1
61-
> [[Prototype]]: ƒ ()
62-
> [[Scopes]]: Scopes[0]
6355

6456
> result: {}
6557
> foo (get): ƒ foo() { return 42 }
6658
42
6759
> [[Prototype]]: Object
6860
> foo (get): ƒ foo() { return 42 }
6961
> [[Prototype]]: Object
70-
> Object
71-
> arguments (get): ƒ ()
72-
> arguments (set): ƒ ()
73-
> caller (get): ƒ ()
74-
> caller (set): ƒ ()
75-
length: 1
76-
> [[Prototype]]: ƒ ()
77-
> [[Scopes]]: Scopes[0]
7862

7963
> result: {}
8064
> foo (get): ƒ foo() { throw 'wat'; }
@@ -90,14 +74,6 @@ result: 3
9074
> [[Prototype]]: Object
9175
> foo (get): ƒ foo() { throw 'wat'; }
9276
> [[Prototype]]: Object
93-
> Object
94-
> arguments (get): ƒ ()
95-
> arguments (set): ƒ ()
96-
> caller (get): ƒ ()
97-
> caller (set): ƒ ()
98-
length: 1
99-
> [[Prototype]]: ƒ ()
100-
> [[Scopes]]: Scopes[0]
10177

10278
Evaluating#1: setTimeout(() => { throw new Error('bar')}, 0)
10379
stderr> Uncaught Error: bar

src/test/node/node-runtime-sets-arguments.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
1: 'very fancy'
1010
2: '--arguments'
1111
length: 3
12+
> __proto__: Array(0)

src/test/node/node-runtime.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,12 @@ describe('node runtime', () => {
673673
});
674674
handle.load();
675675

676-
handle.log(await handle.dap.once('stopped'));
677-
handle.dap.evaluate({ expression: 'require("inspector").close()' });
676+
const { threadId } = handle.log(await handle.dap.once('stopped'));
677+
const stack = await handle.dap.stackTrace({ threadId });
678+
handle.dap.evaluate({
679+
expression: 'require("inspector").close()',
680+
frameId: stack.stackFrames[0].id,
681+
});
678682
handle.log(await handle.dap.once('terminated'));
679683
handle.assertLog({ substring: true });
680684
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
require('inspector'); // make sure require is available
12
debugger;

0 commit comments

Comments
 (0)