[webkit-dev] Invocation with undefined this on JS binding object

youenn fablet youennf at gmail.com
Wed Jul 1 11:48:19 PDT 2015

One way may be to make 'size' an attribute, cachable and returning a
JSFunction wrapping a C++ function returning 1. Not sure this will pass
signature tests though.
This can be done as a custom 'size' function also but I guess you need to
return the same JS object all the time.

A second approach might be to return the 'size' method bound to the count
queuing strategy object. That is easy in JS but I do not know how easy it
is within JSC.

IIUC, 'size' is somehow similar to a C++ static class method. A third
approach could be to add a 'static' IDL keyword to the binding generator to
enable calling static methods of the DOM class. No custom code in that case.

 Hope this helps

Le mer. 1 juil. 2015 20:07, Geoffrey Garen <ggaren at apple.com> a écrit :

Hi Xabier.

Our bindings assume, by default, that the ‘this’ parameter passed to any
DOM interface is an object of the interface’s type. This is how most DOM
bindings work.

Our bindings also assume that a requested property can be read from the
‘this’ object, which represents the DOM interface.

If you’re going to pass undefined into the size function, you’ve violated
both assumptions. (It would be meaningless to remove the type check — the
call to size later would just crash anyway.)

The easiest way to make this work is to make the function custom. What
exactly did you do when you tried that, and why exactly didn’t it work?

Side note: Shouldn’t this function bear the name “strategySize” rather than


> On Jul 1, 2015, at 10:59 AM, Xabier Rodríguez Calvar <calvaris at igalia.com>
>       Hello,
> I need some help with some JS bindings code. I am implementing
> CountQueuingStrategy [1], which is an object containing two properties,
> one of them a function. That strategy is passed to another
> ReadableStream object [2] and as you can see at step 8, the size method
> is extracted from the strategy and kept inside the stream for later
> use. That use happens at [3], step 5.b.i, when the spec says that we
> have to pass undefined as this (and we do).
> [1] https://streams.spec.whatwg.org/#cqs-class
> [2] https://streams.spec.whatwg.org/#rs-constructor
> [3] https://streams.spec.whatwg.org/#enqueue-in-readable-stream
> The problem comes when invoking that method at the generated bindings:
> EncodedJSValue JSC_HOST_CALL
> jsCountQueuingStrategyPrototypeFunctionSize(ExecState* exec)
> {
>    JSValue thisValue = exec->thisValue();
>    JSCountQueuingStrategy* castedThis =
> jsDynamicCast<JSCountQueuingStrategy*>(thisValue);
>    if (UNLIKELY(!castedThis))
>        return throwThisTypeError(*exec, "CountQueuingStrategy",
> "size");
> JSCountQueuingStrategy::info());
>    return JSValue::encode(castedThis->size(exec));
> }
> The problem is that it checks that "this" casts to the class and of
> course it fails because the spec says it has to be undefined. I haven't
> found any way to overcome this, even making the method custom.
> Any ideas here?
> Thanks in advance and best regards.
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev

webkit-dev mailing list
webkit-dev at lists.webkit.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20150701/96c6409b/attachment.html>

More information about the webkit-dev mailing list