/**
 * A thread is a running stack context and all the metadata needed.
 * @param {?string} firstBlock First block to execute in the thread.
 * @constructor
 */
function Thread (firstBlock) {
    /**
     * ID of top block of the thread
     * @type {!string}
     */
    this.topBlock = firstBlock;
    /**
     * ID of next block that the thread will execute, or null if none.
     * @type {?string}
     */
    this.nextBlock = firstBlock;
    /**
     * Stack for the thread. When the sequencer enters a control structure,
     * the block is pushed onto the stack so we know where to exit.
     * @type {Array.<string>}
     */
    this.stack = [];

    /**
     * Stack frames for the thread. Store metadata for the executing blocks.
     * @type {Array.<Object>}
     */
    this.stackFrames = [];

    /**
     * Status of the thread, one of three states (below)
     * @type {number}
     */
    this.status = 0; /* Thread.STATUS_RUNNING */

    /**
     * Yield timer ID (for checking when the thread should unyield).
     * @type {number}
     */
    this.yieldTimerId = -1;
}

/**
 * Thread status for initialized or running thread.
 * Threads are in this state when the primitive is called for the first time.
 * @const
 */
Thread.STATUS_RUNNING = 0;

/**
 * Thread status for a yielded thread.
 * Threads are in this state when a primitive has yielded.
 * @const
 */
Thread.STATUS_YIELD = 1;

/**
 * Thread status for a finished/done thread.
 * Thread is moved to this state when the interpreter
 * can proceed with execution.
 * @const
 */
Thread.STATUS_DONE = 2;

module.exports = Thread;

@@ -1078,16 +1078,161 @@
 Id = -1;
+%0A%0A    /**%0A     * Whether the thread has switched stack in the course of execution.%0A     * @type %7Bboolean%7D%0A     */%0A    this.switchedStack = false;
 %0A%7D%0A%0A/**%0A
@@ -1718,16 +1718,943 @@
 E = 2;%0A%0A
+/**%0A * Push stack and update stack frames appropriately.%0A * @param %7Bstring%7D blockId Block ID to push to stack.%0A */%0AThread.prototype.pushStack = function (blockId) %7B%0A    this.stack.push(blockId);%0A    // Push an empty stack frame, if we need one.%0A    // Might not, if we just popped the stack.%0A    if (this.stack.length %3E this.stackFrames.length) %7B%0A        this.stackFrames.push(%7B%7D);%0A    %7D%0A%7D;%0A%0A/**%0A * Pop last block on the stack and its stack frame.%0A * @returns %7Bstring%7D Block ID popped from the stack.%0A */%0AThread.prototype.popStack = function () %7B%0A    this.stackFrames.pop();%0A    return this.stack.pop();%0A%7D;%0A%0A/**%0A * Get last stack frame.%0A * @return %7B?Object%7D Last stack frame stored on this thread.%0A */%0AThread.prototype.getLastStackFrame = function () %7B%0A    return this.stackFrames%5Bthis.stackFrames.length - 1%5D;%0A%7D;%0A%0A/**%0A * Yields the thread.%0A */%0AThread.prototype.yield = function () %7B%0A    this.status = Thread.STATUS_YIELD;%0A%7D;%0A%0A
 module.e

Add helpers to thread object