Class: Kensakan

Kensakan(step_callback, stop_callback, error_callback, step_loop_args)

new Kensakan(step_callback, stop_callback, error_callback, step_loop_args)

Creates an instance of Kensakan. 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 step() or continue() is called. If it returns false the execution continues to the step or breakpoint.

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 error_callback argument is given to the constructor, Kensakan will call it.

In case of runtime errors, if error_callback argument is given to the constructor, Kensakan will call it. But it will not cancel the event or stop its propagation so it doesn't interfere with any other code handling mechanism.

step_loop_args boolean true

If set, it will also step into loop test and update expressions, see Kensakan#step_loop_args

Source:

Members

breakpoints

Set the breakpoint lines in this object to anything other than false or null, like:

    var k = new Kensakan (
           function(r,c,ws) {return true;}
         );

    k.prepare("console.log(1);\nconsole.log(2);\nconsole.log(3);\n");
    k.set_breakpoint(2);

    k.debug(true); // runs until reaching the breakpoint on line 2 
                   // (output:  1) 

    k.continue();  // runs until end as there is no other breakpoints 
                   // (output:  2,3)
Source:

step_loop_args

If set, Kensakan will also step into loop test and update expressions, like i<n and i++ in the loop:

       for( let i=0; i<n; i++ ) {...}

You can set step_loop_args, but should call prepare after so it can be applied.

Source:

Methods

clear_all_breakpoints()

Clears all the breakpoints.

Source:

clear_breakpoint()

Clears the breakpoint on the given line.

Source:

continue()

Runs to the next breakpoint or end. It will call the step_callback that was given to constructor on reaching a breakpoint.

Source:

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.

Source:

prepare(code, watch_locals)

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.

Source:

run()

Runs the prepared code as it is, without the debug codes. The only difference is that it is asyncized anyway, so the flow of the two debug/release procedures would be the same.

Source:

set_breakpoint()

Sets a breakpoint on the given line.

Source:

set_context()

Sets context variables. The members of the context object will be set as given in this object. This also can be used to mask global browser objects like document and window, i.e.

k.set_context({document: null, window: null});

This function should be called before prepare. But if the values of context members are changed later, there is no need to call prepare again. You only should call prepare again if the keys of the context are changed later. You can also access context directly, i.e.

k.context.x = 1;
Source:

step()

Steps to the next line/expression. It will call the step_callback that was given to constructor.

Source: