[whatwg] Workers feedback

Jonas Sicking jonas at sicking.cc
Fri Aug 8 10:10:52 PDT 2008


So the API I'm proposing is the following:

[NoInterfaceObject] interface WorkerFactory {
    Worker createWorker(in DOMString scriptURL);
    Worker createSharedWorker(in DOMString name, in DOMString scriptURL);
};


interface Worker {
    boolean postMessage(in DOMString message);
    boolean postMessage(in DOMString message,
                        in MessagePort messagePort);

    // event handler attributes
             attribute EventListener onmessage;
             attribute EventListener onload;
             attribute EventListener onerror;
             attribute EventListener onunload;
};

interface WorkerParent {
    boolean postMessage(in DOMString message);
    boolean postMessage(in DOMString message,
                        in MessagePort messagePort);
};

[NoInterfaceObject] interface WorkerGlobalScope {
    // core worker features
    readonly attribute WorkerGlobalScope self;
    readonly attribute WorkerLocation location;
    readonly attribute DOMString name;
    readonly attribute boolean closing;
    readonly attribute WorkerParent parent;
    void close();

    // event handler attributes
             attribute EventListener onunload;
};

(We might want to add an onconnect property to WorkerGlobalScope, but it
doesn't seem strictly needed)

I think that it has the following advantages over the current draft spec:

* We don't expose users to MessagePort objects in the majority of
   scenarios.
* There is no permanent .port properties anywhere that would go dead if
   the port is passed somewhere.
* There is no need for pseudo properties anywhere (the port variable
   inside the WorkerGlobalScript)
* The current draft duplicates the onunload property on both the
   worker and its port. Not sure if this is needed or just a bug.
* All onX objects live on the same object rather than some living
   on the worker, some living on worker.port.

I'd be interested to hear what others think of this proposal.

/ Jonas



More information about the whatwg mailing list