[webkit-dev] Inheritance in IDL files/JS bindings

Drew Wilson atwilson at google.com
Fri Jul 3 14:42:08 PDT 2009


I'm working on refactoring some code out of WebCore::Worker into a common
base class to be shared between SharedWorker and Worker.
So I've defined a new AbstractWorker.idl and its associated JS bindings.
AbstractWorker is not intended to be instantiable, so I don't have a
constructor generated for it.

    interface [CustomMarkFunction, Conditional=WORKERS] AbstractWorker {
        ...
    }

I then changed Worker.idl to make the Worker interface derive from the base
AbstractWorker interface, like so:

    interface [CustomMarkFunction, Conditional=WORKERS] Worker :
AbstractWorker {
               ...
    }

Everything compiles just fine, except that at runtime when I instantiate a
Worker object from Javascript, I seem to get an instance of AbstractWorker
instead, and referencing things that should be defined on the Worker
prototype (like Worker::postMessage) yields undefined. I thought at first
that perhaps I was doing something wrong with the prototype (setup in
JSWorkerConstructor.cpp) so I wrote some JS tests, which produced the
expected results:

    log(Worker.toString());   => "[object WorkerConstructor]"
    log(Worker.prototype.toString());    => "[object WorkerPrototype]"
    log(Worker.prototype.postMessage.toString());   => "function
postMessage() { [native code] }"

And yet when I actually instantiate a Worker object:

    var worker = new Worker("resources/worker-common.js");
    log (worker.toString());    => "[object *AbstractWorker*]"
    log (typeof worker.postMessage);    => "*undefined*"

Is there anything special I need to do when implementing inheritance in IDL
files and JS bindings? I *think* I'm correctly following the example of
other places where we use inheritance (example HTMLElement -> Element ->
Node), although there are some options defined in the .idl file like
"GenerateNativeConverter" and "GenerateToJS" that might be relevant but
which I couldn't find any documentation for.

Anyhow, I'm digging into this further, but I figured people might be able to
shed some light on possible causes of this behavior.

-atw
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20090703/79c8c156/attachment.html>


More information about the webkit-dev mailing list