Debugging Scripting Services in JavaScript

The toolkit offers Debug functionality in order to support developers in the hunt of server-side bugs.

Debug Perspective

Debugger Debug View

  • Sessions - contains all debug execution sessions.
  • Variables/Values - contains the variables and their values, available in the current scope of execution.
  • File/Row/Source - contains information about the position of the already set Breakpoints.

Available Commands

  • Button Step Into Step Into
  • Button Step Over Step Over
  • Button Continue Continue
  • Button Skip All Breakpoints Skip all breakpoints

Example

Step 0 - Project Structure

Project

simple_service.js:


main();

function main(){
    var message = createMessage();
    var students = createStudents();
    response.getWriter().println(message);
    response.getWriter().println(JSON.stringify(students));
}

function createMessage(){
    var initialValue = 1;
    var endValue = startCounter(initialValue);
	var message = 'Initial value was '+initialValue+', end value is '+endValue;
    return message;
}

function startCounter(value) {
    for(var i = 0; i < 5; i++){
        value ++;
    }
	return value;
}

function createStudents(){
    var students = [];
    students.push(createStudent('Desi', 18));
    students.push(createStudent('Jordan', 21));
    students.push(createStudent('Martin', 22));
    return students;
}

function createStudent(name, age){
    var student = {};
    student.name = name;
    student.age = age;
    return student;
}

library_jslib:


exports.generateGuid = function() {
    var guid = ''+uuid.randomUUID();
    return guid;
};

require_service.js:


var guidGen = require('/DebuggerDemo/library');
var user = 'Test User';
var id = guidGen.generateGuid();

response.getWriter().println(user+", id "+id);
response.getWriter().flush();
response.getWriter().close();

Step 1 - Open Debug Perspective

  1. Click other… to list available perspectives.

    Perspectives

  2. From the list, select Debug.

    Open Perspective

  3. The Debug perspective is open.

    Debugger Debug View

Step 2 - Start Debugging

  1. From Workspace Explorer, select simple_service.js.

    Project

  2. Debugger was started and waits for user interaction.

    Debugger Start Session

  3. Press the Step Into Button Step Into button to continue with script execution.

    Debugger Step Into

  4. Set some Breakpoints.
  5. Click on the line numbers on the left side of the opened editor.
  6. Press the Refresh Button Refresh button to see Breakpoints that were set.

    Debugger Set Breakpoints

  7. Press the Continue Button Continue button to resume script execution to the next breakpoint.

    Debugger Continue

  8. Press the Continue Button Continue button again.

    Debugger Continue

  9. To exit the Debug Session, press the Skip all breakpoints Button Skip All Breakpoints button or continue pressing Step Over Button Step Over or Step Into Button Step Into until the script execution finishes.

Step 3 - Debugging Scripts Requiring Libraries

  1. From Workspace Explorer, select require_service.js.

    Debugger Select Require Service

    Debugger Start Session

  2. A new Debug Session is started.
  3. Press the Refresh Button Refresh button, select a session and press Step Into Button Step Into.

    Debugger Step Into

  4. Continue debugging.

    Debugger Step Into

    Debugger Step Over

Edit