Bug 131240 - [Bindings] "nullable" sequence<T> support is incomplete
Summary: [Bindings] "nullable" sequence<T> support is incomplete
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Bindings (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Antonio Gomes
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-04 15:19 PDT by Antonio Gomes
Modified: 2014-06-16 10:43 PDT (History)
6 users (show)

See Also:


Attachments
patch (16.11 KB, patch)
2014-04-07 14:26 PDT, Antonio Gomes
no flags Details | Formatted Diff | Diff
simpler patch (13.30 KB, patch)
2014-04-08 17:36 PDT, Antonio Gomes
no flags Details | Formatted Diff | Diff
simpler patch (2) - with WebSocket.idl changes (14.24 KB, patch)
2014-05-27 09:15 PDT, Antonio Gomes
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Antonio Gomes 2014-04-04 15:19:38 PDT
sample foo.idl:

[
    Conditional=XXX,
] interface Foo {
    [RaisesException] void fooIt(sequence<unsigned long>? seq);
}

Generated JSFoo.cpp code:

EncodedJSValue JSC_HOST_CALL jsFooPrototypeFunctionFooIt(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    JSFoo* castedThis = jsDynamicCast<JSFoo*>(thisValue);
    if (!castedThis)
        return throwVMTypeError(exec);
    ASSERT_GC_OBJECT_INHERITS(castedThis, JSFoo::info());
    Foo& impl = castedThis->impl();
    if (exec->argumentCount() != 1)
        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    ExceptionCode ec = 0;
    Vector<unsigned> seq(toNativeArray<unsigned>(exec, exec->argument(0)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    impl.fooIt(seq, ec);
    setDOMException(exec, ec);
    return JSValue::encode(jsUndefined());
}

In JSDOMBindings.h, "toNativeArray" bails out early if JSValue's (i.e. argument0) getObject is null, throwing a VM error "Value is not a sequence".

According to WebIDL [1] there is no restriction for nullable sequences.

[1] http://www.w3.org/TR/WebIDL/#dfn-nullable-type
Comment 1 Darin Adler 2014-04-06 11:56:26 PDT
Do we have one of these nullable sequences in our bindings already? Can we make a regression test showing that null doesn’t work for that?
Comment 2 Antonio Gomes 2014-04-07 14:26:08 PDT
Created attachment 228758 [details]
patch

I choose to add a bool parameter, named "acceptsNullable", to JSDOMBindings::toNativeArray method, and set it to "true" from the generated code upon the presence of "?" in the idl definition.

It might be that we should simply make toNativeArray to accept "null" arrays always, similarly to toRefPtrNativeArray.

Please let me know.
Comment 3 Antonio Gomes 2014-04-07 14:28:28 PDT
(In reply to comment #1)
> Do we have one of these nullable sequences in our bindings already? Can we make a regression test showing that null doesn’t work for that?

I am afraid it is not there yet, but this discrepancy between toNativeArray and toRefPtrNative array was what brought my attention to this.
Comment 4 Darin Adler 2014-04-07 23:11:20 PDT
I’m not really happy doing this patch when there is no binding yet that uses it. It prevents us from doing any real testing. I suggest we hold off on this until we are actually using it in at least one binding.
Comment 5 Antonio Gomes 2014-04-08 11:40:21 PDT
(In reply to comment #4)
> I’m not really happy doing this patch when there is no binding yet that uses it. It prevents us from doing any real testing. I suggest we hold off on this until we are actually using it in at least one binding.

Hi Darin. Would you be ok with a less intrusive approach/patch, where no changes to the perl code is made, as proposed in comment #2?

Reasons I particularly insist are:

- it seems logical to me to make toNativeArray in pair with toRefPtrNativeArray in that sense (acceptance of null as a valid sequence valid). Particularly, toRefPtrNativeArray does take "null" ok as an empty sequence, while toNativeArray does not.

- there is support for nullable sequences in in the generated code for this***, so it seems logical to make both methods actually called by it (i.e. toNativeArray and toRefPtrNativeArray) to support it.

- there are a couple of specifications making use of this nullable sequence:

1) 
https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#options-object-
concept

2) http://www.khronos.org/registry/webcl/specs/latest/1.0/#3.5
if you look at
 void enqueueNDRangeKernel(...,
                    sequence<CLuint>?                     globalWorkOffset, 
                    sequence<CLuint>                      globalWorkSize,
                    optional sequence<CLuint>?            localWorkSize,
                    optional sequence<WebCLEvent>?        eventWaitList,
                    optional WebCLEvent?                  event);

"eventWaitList" goes through toRefPtrNativeArray code path and can take "null" just fine. globalWorkSize does through toNativeArray, and fails to accept it.




***see that if (arg.isNull() || ...) gets added.
Comment 6 Antonio Gomes 2014-04-08 17:36:01 PDT
Created attachment 228919 [details]
simpler patch

Patch that does not change the code generator, and simply makes toNativeArray in pair with toRefPtrNativeArray.

Darin, would you mind to look?
Comment 7 Darin Adler 2014-04-09 07:33:10 PDT
Comment on attachment 228919 [details]
simpler patch

This change is completely reasonable. But it needs a real regression test, testing its effect on an actual binding.

If this change has no effect on any actual generated binding, we should not make the change at this time, until it does have an effect.
Comment 8 Darin Adler 2014-04-09 07:34:09 PDT
(In reply to comment #5)
> - there are a couple of specifications making use of this nullable sequence:
> 
> 1) 
> https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#options-object-
> concept
> 
> 2) http://www.khronos.org/registry/webcl/specs/latest/1.0/#3.5
> if you look at
>  void enqueueNDRangeKernel(...,
>                     sequence<CLuint>?                     globalWorkOffset, 
>                     sequence<CLuint>                      globalWorkSize,
>                     optional sequence<CLuint>?            localWorkSize,
>                     optional sequence<WebCLEvent>?        eventWaitList,
>                     optional WebCLEvent?                  event);
> 
> "eventWaitList" goes through toRefPtrNativeArray code path and can take "null" just fine. globalWorkSize does through toNativeArray, and fails to accept it.

We should land this change when we are landing one of these bindings, so the change has an actual effect on WebKit rather than a theoretical one.
Comment 9 Antonio Gomes 2014-04-09 13:20:52 PDT
Comment on attachment 228919 [details]
simpler patch

Ok. Removing the r? flags.
Comment 10 Antonio Gomes 2014-05-27 09:15:56 PDT
Created attachment 232133 [details]
simpler patch (2) - with WebSocket.idl changes

It turns out WebSocket.idl can benefit from this patch. Changes incorporated.
Comment 11 Antonio Gomes 2014-05-27 10:48:37 PDT
Comment on attachment 232133 [details]
simpler patch (2) - with WebSocket.idl changes

Darin, could you look again?
Comment 12 Antonio Gomes 2014-06-04 10:43:38 PDT
(In reply to comment #11)
> (From update of attachment 232133 [details])
> Darin, could you look again?

Friendly re-ping.
Comment 13 Darin Adler 2014-06-04 15:20:33 PDT
Comment on attachment 232133 [details]
simpler patch (2) - with WebSocket.idl changes

View in context: https://bugs.webkit.org/attachment.cgi?id=232133&action=review

> Source/WebCore/bindings/scripts/test/TestObj.idl:212
> +    void    methodWithAndWithoutNullableSequence(sequence<unsigned long> arrayArg, sequence<unsigned long>? nullableArrayArg);
> +    void    methodWithAndWithoutNullableSequence2(unsigned long[] arrayArg, unsigned long[]? nullableArrayArg);

Should not have four spaces after "void".
Comment 14 Darin Adler 2014-06-04 15:21:03 PDT
Comment on attachment 232133 [details]
simpler patch (2) - with WebSocket.idl changes

View in context: https://bugs.webkit.org/attachment.cgi?id=232133&action=review

> Source/WebCore/Modules/websockets/WebSocket.idl:37
> +    Constructor(DOMString url, [Default=Undefined] optional sequence<DOMString>? protocols),

Do we have test coverage for this?
Comment 15 Antonio Gomes 2014-06-16 10:43:19 PDT
Fixed by <https://webkit.org/b/131240>.