new Tati(step_callback, stop_callback, error_callback, use_worker, default_root)
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 |
use_worker |
boolean | false | If set, the debugger will run in a web worker, much safer but communication with it will be limited so the context should be plain object and the script won't be able to interact with any other object (like DOM) directly. |
default_root |
boolean | The |
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(get_worker_context_on_callback)
Runs to the next breakpoint or end.
It will call the step_callback
that was given to constructor on
reaching a breakpoint.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
get_worker_context_on_callback |
boolean | true | see Tati#step |
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. |
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. This will still be true when using workers, the only difference is that a cloning will be applied and the results will only contain plain objects. See also Tati#getWorkerContext
Parameters:
Name | Type | Description |
---|---|---|
varname |
string | The variable name. |
(async) getWorkerContext()
This is used to update the context copy outside the worker. Note
that this is not usually needed as Tati updates the context values
before calling the step_callback
, unless the get_worker_context_on_callback
parameter is set to false
. It may be needed when the context variables
are big and transmitting them between the user instance and the worker
are intensive. In such cases, if the user needs to check the new context
values, they should call this before getting the context.
Note that this function is asynchronous, so you may need to use it with an await directive.
pause(get_worker_context_on_callback)
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.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
get_worker_context_on_callback |
boolean | true | see Tati#step |
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. |
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()
Sets all breakpoints. 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. |
(async) 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, and if not set, the masked list
contains three predefined elements: globalThis
, 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.
Note that if use_worker
is set to true
in the constructor, the
worker context objects are clones and are not directly accessible.
So directly modifying the value of context variables won't work and
you should use setContext
or setContextVariable
methods.
Also note that the context object must be a plain object when using
workers. Tati will automatically convert context variables to
plain objects when using workers, which means the functions will be
converted to undefined
.
This function is asynchronous, so you may want to use await to make sure the context is set accordingly.
Parameters:
Name | Type | Description |
---|---|---|
context |
object | The new context object. If |
masked |
Array | The list of the objects and variables to be
masked to |
(async) setContextVariable(varname, value)
Sets or defines context variables. Like setContext
, the prepare
function should be called after adding new context properties.
And if use_worker
is set true
, the clones of the set values will
be used in the worker.
This function is asynchronous, so you may want to use await to make sure the context is set accordingly.
Parameters:
Name | Type | Description |
---|---|---|
varname |
string | The variable name. |
value |
any | The new value. If |
step(get_worker_context_on_callback)
Steps to the next line/expression.
It will call the step_callback
that was given to constructor.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
get_worker_context_on_callback |
boolean | true | When using workers,
Tati updates the context values before calling the |