Changeset 228637 in webkit
- Timestamp:
- Feb 19, 2018 2:46:58 AM (6 years ago)
- 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 1 2018-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 1 25 2018-02-05 Ryosuke Niwa <rniwa@webkit.org> 2 26 -
releases/WebKitGTK/webkit-2.20/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
r228038 r228637 1539 1539 1540 1540 return "WTFMove(${name})" if $type->isNullable; 1541 1541 1542 1542 if ($codeGenerator->IsBufferSourceType($type)) { 1543 1543 return "*${name}" if $type->name eq "ArrayBuffer"; … … 1545 1545 } 1546 1546 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)); 1548 1548 return "*${name}" if $codeGenerator->IsWrapperType($type); 1549 1549 return "WTFMove(${name})"; … … 5657 5657 } else { 5658 5658 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 } 5660 5667 5661 5668 $optionalCheck = "state->argument($argumentIndex).isUndefined() ? $defaultValue : "; 5662 5669 $argumentLookupForConversion = "state->uncheckedArgument($argumentIndex)"; 5663 $nativeValueCastFunction = "std::optional<Converter<$argumentIDLType>::ReturnType>";5664 5670 } 5665 5671 } else { … … 5671 5677 } 5672 5678 } 5673 5679 5674 5680 my $globalObjectReference = $operation->isStatic ? "*jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())" : "*castedThis->globalObject()"; 5675 5681 my $argumentExceptionThrower = GetArgumentExceptionThrower($interface, $argument, $argumentIndex, $quotedFunctionName); -
releases/WebKitGTK/webkit-2.20/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
r228038 r228637 1493 1493 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalXPathNSResolver(JSC::ExecState*); 1494 1494 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalRecord(JSC::ExecState*); 1495 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalPromise(JSC::ExecState*); 1495 1496 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithCallbackArg(JSC::ExecState*); 1496 1497 JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithNonCallbackArgAndCallbackArg(JSC::ExecState*); … … 2167 2168 { "methodWithOptionalXPathNSResolver", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithOptionalXPathNSResolver), (intptr_t) (0) } }, 2168 2169 { "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) } }, 2169 2171 { "methodWithCallbackArg", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithCallbackArg), (intptr_t) (1) } }, 2170 2172 { "methodWithNonCallbackArgAndCallbackArg", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithNonCallbackArgAndCallbackArg), (intptr_t) (2) } }, … … 6639 6641 } 6640 6642 6643 static 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 6654 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalPromise(ExecState* state) 6655 { 6656 return IDLOperation<JSTestObj>::call<jsTestObjPrototypeFunctionMethodWithOptionalPromiseBody>(*state, "methodWithOptionalPromise"); 6657 } 6658 6641 6659 static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionMethodWithCallbackArgBody(JSC::ExecState* state, typename IDLOperation<JSTestObj>::ClassParameter castedThis, JSC::ThrowScope& throwScope) 6642 6660 { -
releases/WebKitGTK/webkit-2.20/Source/WebCore/bindings/scripts/test/TestObj.idl
r222454 r228637 240 240 void methodWithOptionalXPathNSResolver(optional XPathNSResolver? resolver); 241 241 void methodWithOptionalRecord(optional record<DOMString, long>? record = null); 242 void methodWithOptionalPromise(optional Promise<void> promise); 242 243 243 244 // Callback interface parameters.
Note: See TracChangeset
for help on using the changeset viewer.