Changeset 228637 in webkit


Ignore:
Timestamp:
Feb 19, 2018 2:46:58 AM (6 years ago)
Author:
Carlos Garcia Campos
Message:

Merge r228189 - [WebIDL] Support optional Promise arguments
https://bugs.webkit.org/show_bug.cgi?id=182399
<rdar://problem/36754552>

Reviewed by Sam Weinig and Chris Dumez.

Previously, declaring a Promise argument as optional would result in a native type of
std::optional<RefPtr<DOMPromise>>. This is wasteful, since RefPtr can represent an optional
argument by storing nullptr. Further, PassArgumentExpression() assumed Promises were never
optional and tried to pass the argument as a Ref by calling RefPtr::releaseNonNull().

This patch removes the std::optional wrapper around optional Promises and simply passes the
promise as a RefPtr to native code.

  • bindings/scripts/CodeGeneratorJS.pm:

(PassArgumentExpression):
(GenerateParametersCheck):

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

(WebCore::jsTestObjPrototypeFunctionMethodWithOptionalPromiseBody):
(WebCore::jsTestObjPrototypeFunctionMethodWithOptionalPromise):

  • bindings/scripts/test/TestObj.idl:
Location:
releases/WebKitGTK/webkit-2.20/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/ChangeLog

    r228634 r228637  
     12018-02-06  Andy Estes  <aestes@apple.com>
     2
     3        [WebIDL] Support optional Promise arguments
     4        https://bugs.webkit.org/show_bug.cgi?id=182399
     5        <rdar://problem/36754552>
     6
     7        Reviewed by Sam Weinig and Chris Dumez.
     8
     9        Previously, declaring a Promise argument as optional would result in a native type of
     10        std::optional<RefPtr<DOMPromise>>. This is wasteful, since RefPtr can represent an optional
     11        argument by storing nullptr. Further, PassArgumentExpression() assumed Promises were never
     12        optional and tried to pass the argument as a Ref by calling RefPtr::releaseNonNull().
     13
     14        This patch removes the std::optional wrapper around optional Promises and simply passes the
     15        promise as a RefPtr to native code.
     16
     17        * bindings/scripts/CodeGeneratorJS.pm:
     18        (PassArgumentExpression):
     19        (GenerateParametersCheck):
     20        * bindings/scripts/test/JS/JSTestObj.cpp:
     21        (WebCore::jsTestObjPrototypeFunctionMethodWithOptionalPromiseBody):
     22        (WebCore::jsTestObjPrototypeFunctionMethodWithOptionalPromise):
     23        * bindings/scripts/test/TestObj.idl:
     24
    1252018-02-05  Ryosuke Niwa  <rniwa@webkit.org>
    226
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r228038 r228637  
    15391539
    15401540    return "WTFMove(${name})" if $type->isNullable;
    1541    
     1541
    15421542    if ($codeGenerator->IsBufferSourceType($type)) {
    15431543        return "*${name}" if $type->name eq "ArrayBuffer";
     
    15451545    }
    15461546
    1547     return "${name}.releaseNonNull()" if $codeGenerator->IsCallbackInterface($type) || $codeGenerator->IsCallbackFunction($type) || $codeGenerator->IsPromiseType($type);
     1547    return "${name}.releaseNonNull()" if $codeGenerator->IsCallbackInterface($type) || $codeGenerator->IsCallbackFunction($type) || ($codeGenerator->IsPromiseType($type) && (ref($context) ne "IDLArgument" || !$context->isOptional));
    15481548    return "*${name}" if $codeGenerator->IsWrapperType($type);
    15491549    return "WTFMove(${name})";
     
    56575657                } else {
    56585658                    my $argumentIDLType = GetIDLType($interface, $argument->type);
    5659                     my $defaultValue = "std::optional<Converter<$argumentIDLType>::ReturnType>()";
     5659
     5660                    my $defaultValue;
     5661                    if ($codeGenerator->IsPromiseType($argument->type)) {
     5662                        $defaultValue = "nullptr";
     5663                    } else {
     5664                        $defaultValue = "std::optional<Converter<$argumentIDLType>::ReturnType>()";
     5665                        $nativeValueCastFunction = "std::optional<Converter<$argumentIDLType>::ReturnType>";
     5666                    }
    56605667
    56615668                    $optionalCheck = "state->argument($argumentIndex).isUndefined() ? $defaultValue : ";
    56625669                    $argumentLookupForConversion = "state->uncheckedArgument($argumentIndex)";
    5663                     $nativeValueCastFunction = "std::optional<Converter<$argumentIDLType>::ReturnType>";
    56645670                }
    56655671            } else {
     
    56715677                }
    56725678            }
    5673    
     5679
    56745680            my $globalObjectReference = $operation->isStatic ? "*jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())" : "*castedThis->globalObject()";
    56755681            my $argumentExceptionThrower = GetArgumentExceptionThrower($interface, $argument, $argumentIndex, $quotedFunctionName);
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r228038 r228637  
    14931493JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalXPathNSResolver(JSC::ExecState*);
    14941494JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalRecord(JSC::ExecState*);
     1495JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalPromise(JSC::ExecState*);
    14951496JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithCallbackArg(JSC::ExecState*);
    14961497JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithNonCallbackArgAndCallbackArg(JSC::ExecState*);
     
    21672168    { "methodWithOptionalXPathNSResolver", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithOptionalXPathNSResolver), (intptr_t) (0) } },
    21682169    { "methodWithOptionalRecord", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithOptionalRecord), (intptr_t) (0) } },
     2170    { "methodWithOptionalPromise", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithOptionalPromise), (intptr_t) (0) } },
    21692171    { "methodWithCallbackArg", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithCallbackArg), (intptr_t) (1) } },
    21702172    { "methodWithNonCallbackArgAndCallbackArg", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithNonCallbackArgAndCallbackArg), (intptr_t) (2) } },
     
    66396641}
    66406642
     6643static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionMethodWithOptionalPromiseBody(JSC::ExecState* state, typename IDLOperation<JSTestObj>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
     6644{
     6645    UNUSED_PARAM(state);
     6646    UNUSED_PARAM(throwScope);
     6647    auto& impl = castedThis->wrapped();
     6648    auto promise = state->argument(0).isUndefined() ? nullptr : convert<IDLPromise<IDLVoid>>(*state, state->uncheckedArgument(0));
     6649    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
     6650    impl.methodWithOptionalPromise(WTFMove(promise));
     6651    return JSValue::encode(jsUndefined());
     6652}
     6653
     6654EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalPromise(ExecState* state)
     6655{
     6656    return IDLOperation<JSTestObj>::call<jsTestObjPrototypeFunctionMethodWithOptionalPromiseBody>(*state, "methodWithOptionalPromise");
     6657}
     6658
    66416659static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionMethodWithCallbackArgBody(JSC::ExecState* state, typename IDLOperation<JSTestObj>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
    66426660{
  • releases/WebKitGTK/webkit-2.20/Source/WebCore/bindings/scripts/test/TestObj.idl

    r222454 r228637  
    240240    void    methodWithOptionalXPathNSResolver(optional XPathNSResolver? resolver);
    241241    void    methodWithOptionalRecord(optional record<DOMString, long>? record = null);
     242    void    methodWithOptionalPromise(optional Promise<void> promise);
    242243
    243244    // Callback interface parameters.
Note: See TracChangeset for help on using the changeset viewer.