JsBreakpointDebugger Class

A debugger that pauses the scripts at breakpoints, at the debugger statements and on request, and steps through their statements. Set it in JsEngineOptions.Debugger before the code is compiled.

public class JsBreakpointDebugger : JsDebugger

Remarks

When the script pauses, JsBreakpointDebugger.OnPaused (or the callback given to the constructor) is called on the thread of the engine. The script waits until it returns: it can read the scopes, the call stack and evaluate code at the statement (JsDebugPause.Event), then return how the script resumes. To stop the script, throw a JsTerminationException.

The breakpoints can be added, removed, enabled and disabled from any thread, including while a script runs.

A step is based on the call depth of the statements: a step that leaves the code being run (e.g. the end of a script, or an await) pauses at the next statement that runs, such as the statement of a promise job.

Inheritance
JsDebugger JsBreakpointDebugger

Constructors

NameDescription
JsBreakpointDebugger()Initializes a new instance of the JsBreakpointDebugger class, for a class that overrides JsBreakpointDebugger.OnPaused.
JsBreakpointDebugger(Func<JsDebugPause, JsStepAction>)Initializes a new instance of the JsBreakpointDebugger class.

JsBreakpointDebugger overloads

JsBreakpointDebugger()

JsBreakpointDebugger.cs

Initializes a new instance of the JsBreakpointDebugger class, for a class that overrides JsBreakpointDebugger.OnPaused.

protected JsBreakpointDebugger()

JsBreakpointDebugger(Func<JsDebugPause, JsStepAction>)

JsBreakpointDebugger.cs

Initializes a new instance of the JsBreakpointDebugger class.

public JsBreakpointDebugger(Func<JsDebugPause, JsStepAction> onPaused)
Parameters
onPaused Func<JsDebugPause, JsStepAction>
Called when a script pauses. It returns how the script resumes.

Properties

NameDescription
BreakpointsGets the breakpoints, in the order they were added.
PauseOnDebuggerStatementsGets or sets whether the debugger statements pause the scripts. The default is true.

Gets the breakpoints, in the order they were added.

public IReadOnlyList<JsBreakpoint> Breakpoints { get; }

PauseOnDebuggerStatements

JsBreakpointDebugger.cs

Gets or sets whether the debugger statements pause the scripts. The default is true.

public bool PauseOnDebuggerStatements { get; set; }

Property value

bool

Methods

NameDescription
AddBreakpoint(string?, int, int?, string?)Adds a breakpoint.
ClearBreakpoints()Removes all the breakpoints.
OnDebuggerStatement(JsDebugEvent)Called when a debugger statement runs.
OnPaused(JsDebugPause)Called when a script pauses, on the thread of the engine. The script waits until it returns.
OnStatement(JsDebugEvent)Called before a statement runs.
RemoveBreakpoint(JsBreakpoint)Removes a breakpoint.
RequestPause()Pauses the script at the next statement that runs. It can be called from any thread.

AddBreakpoint(string?, int, int?, string?)

JsBreakpointDebugger.cs

Adds a breakpoint.

public JsBreakpoint AddBreakpoint(string? url, int line, int? column = null, string? condition = null)

Parameters

url string?
The URL of the code (the name given to the script, the module, or the //# sourceURL= comment of eval code).
line int
The line, 1-based.
column int?
The column of the statement, 1-based in UTF-16 code units, or null to pause at each statement that starts on the line.
condition string?
The code evaluated at the statement: the script pauses when its value is truthy. Null to always pause.

Returns

JsBreakpoint The breakpoint.

Exceptions

ArgumentOutOfRangeException
line or column is less than 1.

ClearBreakpoints()

JsBreakpointDebugger.cs

Removes all the breakpoints.

public void ClearBreakpoints()

OnDebuggerStatement(JsDebugEvent)

JsBreakpointDebugger.cs

Called when a debugger statement runs.

protected internal override void OnDebuggerStatement(JsDebugEvent debugEvent)

Parameters

debugEvent JsDebugEvent
The statement. It is valid until the method returns.

OnPaused(JsDebugPause)

JsBreakpointDebugger.cs

Called when a script pauses, on the thread of the engine. The script waits until it returns.

protected virtual JsStepAction OnPaused(JsDebugPause pause)

Parameters

pause JsDebugPause
The statement where the script is paused, and why. It is valid until the method returns.

Returns

JsStepAction How the script resumes.

OnStatement(JsDebugEvent)

JsBreakpointDebugger.cs

Called before a statement runs.

protected internal override void OnStatement(JsDebugEvent debugEvent)

Parameters

debugEvent JsDebugEvent
The statement. It is valid until the method returns.

RemoveBreakpoint(JsBreakpoint)

JsBreakpointDebugger.cs

Removes a breakpoint.

public bool RemoveBreakpoint(JsBreakpoint breakpoint)

Parameters

breakpoint JsBreakpoint
The breakpoint.

Returns

bool True when the breakpoint was removed; false when it is not a breakpoint of the debugger.

Pauses the script at the next statement that runs. It can be called from any thread.

public void RequestPause()