SDAPI Script Threads 2.0
A script thread is a container for a running script. When a Script Pipelet or Controller Script is called, a script thread is created representing the script file. A script thread is either 'running' or 'halted'. If the script thread is halted, a stack frame is created representing the entry point of the script. For every function that is subsequently called, a new stack frame is created and added to the script's call stack. When function is exited, the stack frame is removed from the call stack.
The script thread's call stack is a zero-based
index where element
0
represents the current
location of the script execution path.
- Fetch variables based on script thread and stack frame index. See Object Members for more information.
- Evaluate expressions based on script thread and stack frame index. See Object Members for more information.
- Control the execution of the script by stepping into a function, stepping out of a function, stepping over the current line, resuming scripts, and stopping script threads. See Object Members for more information.
In the vast majority of cases, you do not want to interact with a βrunningβ script thread, because there is no guarantee that the thread will be alive when your request is processed.
Examples
Example 1: Get all script threads
REQUEST:
GET /s/-/dw/debugger/v1_0/threads HTTP/1.1
RESPONSE:
HTTP/1.1 200 OK
{
"_v":"2.0",
"script_threads":[
{
"call_stack":[
{
"index":0,
"location":
{
"function_name":"first()",
"line_number":25,
"script_path":"/app_storefront_controllers/cartridge/scripts/models/CartModel.js"
}
},
{
"index":1,
"location":
{
"function_name":"execute()",
"line_number":12,
"script_path":"/app_storefront_controllers/cartridge/controllers/Cart.js"
}
}],
"id":2,
"status":"halted"
}
]
}
Example 2: Get a specific script thread
REQUEST:
GET /s/-/dw/debugger/v1_0/threads/2 HTTP/1.1
RESPONSE:
HTTP/1.1 200 OK
{
"_v":"2.0",
"call_stack":[
{
"index":0,
"location":
{
"function_name":"first()",
"line_number":25,
"script_path":"/app_storefront_controllers/cartridge/scripts/models/CartModel.js"
}
},
{
"index":1,
"location":
{
"function_name":"execute()",
"line_number":12,
"script_path":"/app_storefront_controllers/cartridge/controllers/Cart.js"
}
}],
"id":2,
"status":"halted"
}
Example 3: Reset script thread timeout counter for all halted threads
REQUEST:
POST /s/-/dw/debugger/v1_0/threads/reset HTTP/1.1
RESPONSE:
HTTP/1.1 204 No Content