new Tati(step_callback, stop_callback, error_callback, config)
Creates an instance of Tati. There can be multiple instances and each can be controlled separately.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
step_callback |
function | null | The callback handler for stepping. It is called before the runner runs a breakpoint or steps to the next line. The row and column of the next step is given as the first and second arguments. If the watch flag is set, a third argument of watches values is also passed to the callback. The watched values is a dictionary, containing values of the local variables before running that step. If a variable is shadowed by another, the most recent value is shown. If the step callback returns true, the execution will be paused until one of
the functions |
stop_callback |
function | null | Is called when the running of the code is finished. |
error_callback |
function | null | Is called when there is an error in parse or run time. The first and second arguments are the line and column, third argument would be the type of error (parse or runtime), and the forth would be the error description. In case of parser errors, if In case of runtime errors, if |
config |
object | Instance configuration. It contains the following properties:
|
Members
STOPPED
Returns the running status.
Methods
clearAllBreakpoints()
Clears all the breakpoints.
clearBreakpoint(line)
Clears the breakpoint on the given line.
Parameters:
Name | Type | Description |
---|---|---|
line |
integer | The breakpoint line. |
configureUIRefreshRate(ui_refresh_steps, ui_refresh_time)
Configures the UI refresh checking. This is to make sure UI is responsive
and specially the process is pausable, which cannot be ensured on every
cycle because of performance considerations. As a result, UI refresh config
is not for a precise flow control, for a precise control use the
step_callback
return value. For more info see Tati#constructor.
Parameters:
Name | Type | Description |
---|---|---|
ui_refresh_steps |
integer | How many steps to take before refreshing the UI. |
ui_refresh_time |
integer | The time it will wait before continuing the process. |
continue()
Runs to the next breakpoint or end.
It will call the step_callback
that was given to constructor on
reaching a breakpoint.
debug(run_to_breakpoint)
Runs the prepared code with the debug codes.
You can step line by line or run until reaching a breakpoint. It will
call the step_callback
that was given to constructor.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
run_to_breakpoint |
boolean | false | If true it will continue running until reaching a breakpoint. If false, it will step line by line. |
getCode()
Returns the last prepared code.
getContextList()
Returns the list of context variables.
getContextValue(varname)
Returns the value of a context variable. This can be used to access the results of the script being debugged. Of course, the only types that can be modified from inside the scripts are arrays and objects, i.e. the variables that are passed by reference and not by value.
Parameters:
Name | Type | Description |
---|---|---|
varname |
string | The variable name. |
getTimers()
Returns the list of working timers.
pause()
Pauses the script. When the script is running an intensive loop or process, checking for pause command will be done in intervals, which can be configured using Tati#configureUIRefreshRate.
When an script with a timeout or interval is being debugged but no breakpoint is set, pause will be applied on the next callback, Tati will prevent timer callback execution, but it doesn't stop the runtime event loop, so they will expire as defined.
Also note that Tati can only pause inside the given script and cannot enter the called functions that are defined elsewhere, i.e. native functions or external libraries.
prepare(code, watch_locals, step_loop_args, is_module)
Parses the given code, and prepares it for the flow with control, throws exception if there is a syntax problem in code.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
code |
string | The javascript code to compile/run. |
|
watch_locals |
boolean | true | If set, the callback will receive a snapshot of the local variables in an object too. |
step_loop_args |
boolean | true | If set, it will also step into
loop test and update expressions, like
|
is_module |
boolean | false | If set, the code will be treated as module,
i.e. import and export statements will work, otherwise they will raise
an unexpected token error in parse time. Note that imports cannot be
executed, because normal import statements must be the top-level of a module
and this cannot be the case when tati is wrapping the code. Also |
run()
Runs the prepared code as it is, without the debug codes. The only difference is that it is processed anyway, so the flow and the environment of the two debug/run procedures are the same.
setAllBreakpoints(bps)
Sets all breakpoints.
Parameters:
Name | Type | Description |
---|---|---|
bps |
integer | The breakpoint line. Breakpoints should be in the form of { 5: true, 10: true } where the keys are the line numbers and the breakpoint is only set if the value is exactly true. |
setBreakpoint(line)
Sets a breakpoint on the given line.
Parameters:
Name | Type | Description |
---|---|---|
line |
integer | The breakpoint line. |
setContext(context, masked)
Sets context variables. The members of the context will be set as given in this object. The masked argument can be used to define the variables and objects to be masked. Note that the masked are given in a list of strings.
k.setContext({foo:123, bar:"hello"}, [document, window]);
The masked list is not necessary, but for limiting the access scope
remember to mask globalThis
, window
, self and the
class name of Tati, which is normally Tati itself.
This function should be called before calling prepare
if the keys
of the context or the members of the masked list are changed. But it
won't be necessary if only the values of context variables are
changed later.
Parameters:
Name | Type | Description |
---|---|---|
context |
object | The new context object. |
masked |
Array | The list of the objects and variables to be
masked to |
setContextVariable(varname, value)
Sets or defines context variables. Like setContext
, the prepare
function should be called after adding new context properties.
Parameters:
Name | Type | Description |
---|---|---|
varname |
string | The variable name. |
value |
any | The new value. |
step()
Steps to the next line/expression.
It will call the step_callback
that was given to constructor.