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

Sam Weinig sam.weinig at gmail.com
Fri Jul 3 15:23:52 PDT 2009


On Fri, Jul 3, 2009 at 2:42 PM, Drew Wilson <atwilson at google.com> wrote:

> 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 {
>         ...
>     }
>

GenerateConstructor is a slight misnomer unfortunately.  Event
non-instatiatable interfaces should have one so that they can be exposed on
the global object for use with instanceof and accessing the prototype.


>
> 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.
>

It is hard to say without a full diff.  Nothing you have described seems too
far off.

-Sam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20090703/2f719a93/attachment.html>


More information about the webkit-dev mailing list