domenic/zones

Show how the web platform would integrate zones

Opened this issue · 1 comments

Rough thoughts: Web IDL's callback function type gets modified to have a zone field. The conversion from JS functions to Web IDL callback functions stores the current zone alongside the JS function. Web IDL's "invoke" algorithm for invoking callback functions uses this spec's CallInZone.

For the reference, here is how present native async stacks are implemented in Blink:

Async markup API

class Instrumentation {
    // Notify debugger that native async task has been scheduled (setTimeout).
    // V8 stack is captured here and is associated with the |task|.
    void asyncTaskScheduled(const String& taskName, void* task, bool recurring);

    // Notify debugger that native async was canceled (clearTimeout).
    // Pops stack from async call chain for |task|.
    void asyncTaskCanceled(void* task);

    // Notify debugger that callback for the async task started execution.
    // Sets |task| as currently executing so that further |asyncTaskScheduled|
    // could be associated with it.
    void asyncTaskStarted(void* task);

    // Notify debugger that callback for the async task callback completed.
    void asyncTaskFinished(void* task);

    // RAII object for asyncTaskStarted / asyncTaskFinished.
    class AsyncTask { ... }
}

setTimeout implementation using the above API.

DOMTimer::DOMTimer(ExecutionContext* context, bool singleShot)
{
    Instrumentation::asyncTaskScheduled(context, singleShot ? "setTimeout" : "setInterval", this, !singleShot);
}

void DOMTimer::fired()
{
    Instrumentation::AsyncTask asyncTask(getExecutionContext(), this);
    ...
}

void DOMTimer::stop()
{
    Instrumentation::asyncTaskCanceled(getExecutionContext(), this);
}