Changeset 207725 in webkit


Ignore:
Timestamp:
Oct 22, 2016 10:06:19 PM (7 years ago)
Author:
Chris Dumez
Message:

[Web IDL] Two types are distinguishable for overload resolution if at most one of the two includes a nullable type
https://bugs.webkit.org/show_bug.cgi?id=163791

Reviewed by Sam Weinig.

Update overload resolution in the bindings generator so that 2 nullable types
are no longer considered as distinguishable, as per Web IDL:

  • bindings/scripts/CodeGeneratorJS.pm:

(AreTypesDistinguishableForOverloadResolution):

  • bindings/scripts/test/JS/JSTestObj.cpp:

(WebCore::jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter1):
(WebCore::jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter1Caller):
(WebCore::jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter2):
(WebCore::jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter2Caller):
(WebCore::jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter):

  • bindings/scripts/test/TestObj.idl:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207724 r207725  
     12016-10-22  Chris Dumez  <cdumez@apple.com>
     2
     3        [Web IDL] Two types are distinguishable for overload resolution if at most one of the two includes a nullable type
     4        https://bugs.webkit.org/show_bug.cgi?id=163791
     5
     6        Reviewed by Sam Weinig.
     7
     8        Update overload resolution in the bindings generator so that 2 nullable types
     9        are no longer considered as distinguishable, as per Web IDL:
     10        - https://heycam.github.io/webidl/#dfn-distinguishable
     11
     12        * bindings/scripts/CodeGeneratorJS.pm:
     13        (AreTypesDistinguishableForOverloadResolution):
     14        * bindings/scripts/test/JS/JSTestObj.cpp:
     15        (WebCore::jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter1):
     16        (WebCore::jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter1Caller):
     17        (WebCore::jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter2):
     18        (WebCore::jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter2Caller):
     19        (WebCore::jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter):
     20        * bindings/scripts/test/TestObj.idl:
     21
    1222016-10-22  Chris Dumez  <cdumez@apple.com>
    223
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r207716 r207725  
    19741974    };
    19751975
    1976     # FIXME: The WebIDL mandates this but this currently does not work because some of our IDL is wrong.
    1977     # return 0 if $idlTypeA->isNullable && $idlTypeB->isNullable;
     1976    # Two types are distinguishable for overload resolution if at most one of the two includes a nullable type.
     1977    return 0 if $idlTypeA->isNullable && $idlTypeB->isNullable;
    19781978
    19791979    # Union types: idlTypeA and idlTypeB  are distinguishable if:
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r207711 r207725  
    963963JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionOverloadWithNullableUnion(JSC::ExecState*);
    964964JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionOverloadWithOptionalUnion(JSC::ExecState*);
     965JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter(JSC::ExecState*);
    965966JSC::EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionClassMethod(JSC::ExecState*);
    966967JSC::EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionClassMethodWithOptional(JSC::ExecState*);
     
    15861587    { "overloadWithNullableUnion", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionOverloadWithNullableUnion), (intptr_t) (1) } },
    15871588    { "overloadWithOptionalUnion", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionOverloadWithOptionalUnion), (intptr_t) (0) } },
     1589    { "overloadWithNullableNonDistinguishingParameter", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter), (intptr_t) (2) } },
    15881590    { "classMethodWithClamp", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionClassMethodWithClamp), (intptr_t) (2) } },
    15891591    { "classMethodWithEnforceRange", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionClassMethodWithEnforceRange), (intptr_t) (2) } },
     
    71567158}
    71577159
     7160static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter1Caller(JSC::ExecState*, JSTestObj*, JSC::ThrowScope&);
     7161
     7162static inline EncodedJSValue jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter1(ExecState* state)
     7163{
     7164    return BindingCaller<JSTestObj>::callOperation<jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter1Caller>(state, "overloadWithNullableNonDistinguishingParameter");
     7165}
     7166
     7167static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter1Caller(JSC::ExecState* state, JSTestObj* castedThis, JSC::ThrowScope& throwScope)
     7168{
     7169    UNUSED_PARAM(state);
     7170    UNUSED_PARAM(throwScope);
     7171    auto& impl = castedThis->wrapped();
     7172    if (UNLIKELY(state->argumentCount() < 2))
     7173        return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
     7174    TestObj* obj = nullptr;
     7175    if (!state->uncheckedArgument(0).isUndefinedOrNull()) {
     7176        obj = JSTestObj::toWrapped(state->uncheckedArgument(0));
     7177        if (UNLIKELY(!obj))
     7178            return throwArgumentTypeError(*state, throwScope, 0, "obj", "TestObject", "overloadWithNullableNonDistinguishingParameter", "TestObj");
     7179    }
     7180    auto node = JSTestNode::toWrapped(state->uncheckedArgument(1));
     7181    if (UNLIKELY(!node))
     7182        return throwArgumentTypeError(*state, throwScope, 1, "node", "TestObject", "overloadWithNullableNonDistinguishingParameter", "TestNode");
     7183    impl.overloadWithNullableNonDistinguishingParameter(WTFMove(obj), *node);
     7184    return JSValue::encode(jsUndefined());
     7185}
     7186
     7187static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter2Caller(JSC::ExecState*, JSTestObj*, JSC::ThrowScope&);
     7188
     7189static inline EncodedJSValue jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter2(ExecState* state)
     7190{
     7191    return BindingCaller<JSTestObj>::callOperation<jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter2Caller>(state, "overloadWithNullableNonDistinguishingParameter");
     7192}
     7193
     7194static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter2Caller(JSC::ExecState* state, JSTestObj* castedThis, JSC::ThrowScope& throwScope)
     7195{
     7196    UNUSED_PARAM(state);
     7197    UNUSED_PARAM(throwScope);
     7198    auto& impl = castedThis->wrapped();
     7199    if (UNLIKELY(state->argumentCount() < 2))
     7200        return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
     7201    TestNode* node = nullptr;
     7202    if (!state->uncheckedArgument(0).isUndefinedOrNull()) {
     7203        node = JSTestNode::toWrapped(state->uncheckedArgument(0));
     7204        if (UNLIKELY(!node))
     7205            return throwArgumentTypeError(*state, throwScope, 0, "node", "TestObject", "overloadWithNullableNonDistinguishingParameter", "TestNode");
     7206    }
     7207    auto index = convert<IDLLong>(*state, state->uncheckedArgument(1), NormalConversion);
     7208    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
     7209    impl.overloadWithNullableNonDistinguishingParameter(WTFMove(node), WTFMove(index));
     7210    return JSValue::encode(jsUndefined());
     7211}
     7212
     7213EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter(ExecState* state)
     7214{
     7215    VM& vm = state->vm();
     7216    auto throwScope = DECLARE_THROW_SCOPE(vm);
     7217    UNUSED_PARAM(throwScope);
     7218    size_t argsCount = std::min<size_t>(2, state->argumentCount());
     7219    if (argsCount == 2) {
     7220        JSValue distinguishingArg = state->uncheckedArgument(1);
     7221        if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits(JSTestNode::info()))
     7222            return jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter1(state);
     7223        if (distinguishingArg.isNumber())
     7224            return jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter2(state);
     7225        return jsTestObjPrototypeFunctionOverloadWithNullableNonDistinguishingParameter2(state);
     7226    }
     7227    return argsCount < 2 ? throwVMError(state, throwScope, createNotEnoughArgumentsError(state)) : throwVMTypeError(state, throwScope);
     7228}
     7229
    71587230EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionClassMethod(ExecState* state)
    71597231{
  • trunk/Source/WebCore/bindings/scripts/test/TestObj.idl

    r207705 r207725  
    314314    void overloadWithOptionalUnion(optional (DOMString or boolean) objectOrNode = true);
    315315    void overloadWithOptionalUnion(long index);
     316
     317    void overloadWithNullableNonDistinguishingParameter(TestObj? obj, TestNode node);
     318    void overloadWithNullableNonDistinguishingParameter(TestNode? node, long index);
    316319#endif
    317320
Note: See TracChangeset for help on using the changeset viewer.