Modified: branches/safari-605-branch/Source/WebCore/ChangeLog (228203 => 228204)
--- branches/safari-605-branch/Source/WebCore/ChangeLog 2018-02-07 00:53:33 UTC (rev 228203)
+++ branches/safari-605-branch/Source/WebCore/ChangeLog 2018-02-07 00:53:36 UTC (rev 228204)
@@ -1,5 +1,33 @@
2018-02-06 Jason Marcell <jmarc...@apple.com>
+ Cherry-pick r228189. rdar://problem/37292905
+
+ 2018-02-06 Andy Estes <aes...@apple.com>
+
+ [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:
+
+2018-02-06 Jason Marcell <jmarc...@apple.com>
+
Cherry-pick r228180. rdar://problem/37292935
2018-02-06 Chris Dumez <cdu...@apple.com>
Modified: branches/safari-605-branch/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (228203 => 228204)
--- branches/safari-605-branch/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2018-02-07 00:53:33 UTC (rev 228203)
+++ branches/safari-605-branch/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2018-02-07 00:53:36 UTC (rev 228204)
@@ -1538,13 +1538,13 @@
my $type = $context->type;
return "WTFMove(${name})" if $type->isNullable;
-
+
if ($codeGenerator->IsBufferSourceType($type)) {
return "*${name}" if $type->name eq "ArrayBuffer";
return "${name}.releaseNonNull()";
}
- return "${name}.releaseNonNull()" if $codeGenerator->IsCallbackInterface($type) || $codeGenerator->IsCallbackFunction($type) || $codeGenerator->IsPromiseType($type);
+ return "${name}.releaseNonNull()" if $codeGenerator->IsCallbackInterface($type) || $codeGenerator->IsCallbackFunction($type) || ($codeGenerator->IsPromiseType($type) && (ref($context) ne "IDLArgument" || !$context->isOptional));
return "*${name}" if $codeGenerator->IsWrapperType($type);
return "WTFMove(${name})";
}
@@ -5655,11 +5655,17 @@
}
} else {
my $argumentIDLType = GetIDLType($interface, $argument->type);
- my $defaultValue = "std::optional<Converter<$argumentIDLType>::ReturnType>()";
+ my $defaultValue;
+ if ($codeGenerator->IsPromiseType($argument->type)) {
+ $defaultValue = "nullptr";
+ } else {
+ $defaultValue = "std::optional<Converter<$argumentIDLType>::ReturnType>()";
+ $nativeValueCastFunction = "std::optional<Converter<$argumentIDLType>::ReturnType>";
+ }
+
$optionalCheck = "state->argument($argumentIndex).isUndefined() ? $defaultValue : ";
$argumentLookupForConversion = "state->uncheckedArgument($argumentIndex)";
- $nativeValueCastFunction = "std::optional<Converter<$argumentIDLType>::ReturnType>";
}
} else {
if ($argument->extendedAttributes->{ReturnValue}) {
@@ -5669,7 +5675,7 @@
$argumentLookupForConversion = "state->uncheckedArgument($argumentIndex)";
}
}
-
+
my $globalObjectReference = $operation->isStatic ? "*jsCast<JSDOMGlobalObject*>(state->lexicalGlobalObject())" : "*castedThis->globalObject()";
my $argumentExceptionThrower = GetArgumentExceptionThrower($interface, $argument, $argumentIndex, $quotedFunctionName);
Modified: branches/safari-605-branch/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp (228203 => 228204)
--- branches/safari-605-branch/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp 2018-02-07 00:53:33 UTC (rev 228203)
+++ branches/safari-605-branch/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp 2018-02-07 00:53:36 UTC (rev 228204)
@@ -1491,6 +1491,7 @@
JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalNullableWrapperIsNull(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalXPathNSResolver(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalRecord(JSC::ExecState*);
+JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalPromise(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithCallbackArg(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithNonCallbackArgAndCallbackArg(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithCallbackAndOptionalArg(JSC::ExecState*);
@@ -2165,6 +2166,7 @@
{ "methodWithOptionalNullableWrapperIsNull", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithOptionalNullableWrapperIsNull), (intptr_t) (0) } },
{ "methodWithOptionalXPathNSResolver", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithOptionalXPathNSResolver), (intptr_t) (0) } },
{ "methodWithOptionalRecord", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithOptionalRecord), (intptr_t) (0) } },
+ { "methodWithOptionalPromise", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithOptionalPromise), (intptr_t) (0) } },
{ "methodWithCallbackArg", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithCallbackArg), (intptr_t) (1) } },
{ "methodWithNonCallbackArgAndCallbackArg", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithNonCallbackArgAndCallbackArg), (intptr_t) (2) } },
{ "methodWithCallbackAndOptionalArg", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithCallbackAndOptionalArg), (intptr_t) (0) } },
@@ -6637,6 +6639,22 @@
return IDLOperation<JSTestObj>::call<jsTestObjPrototypeFunctionMethodWithOptionalRecordBody>(*state, "methodWithOptionalRecord");
}
+static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionMethodWithOptionalPromiseBody(JSC::ExecState* state, typename IDLOperation<JSTestObj>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
+{
+ UNUSED_PARAM(state);
+ UNUSED_PARAM(throwScope);
+ auto& impl = castedThis->wrapped();
+ auto promise = state->argument(0).isUndefined() ? nullptr : convert<IDLPromise<IDLVoid>>(*state, state->uncheckedArgument(0));
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ impl.methodWithOptionalPromise(WTFMove(promise));
+ return JSValue::encode(jsUndefined());
+}
+
+EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalPromise(ExecState* state)
+{
+ return IDLOperation<JSTestObj>::call<jsTestObjPrototypeFunctionMethodWithOptionalPromiseBody>(*state, "methodWithOptionalPromise");
+}
+
static inline JSC::EncodedJSValue jsTestObjPrototypeFunctionMethodWithCallbackArgBody(JSC::ExecState* state, typename IDLOperation<JSTestObj>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
{
UNUSED_PARAM(state);
Modified: branches/safari-605-branch/Source/WebCore/bindings/scripts/test/TestObj.idl (228203 => 228204)
--- branches/safari-605-branch/Source/WebCore/bindings/scripts/test/TestObj.idl 2018-02-07 00:53:33 UTC (rev 228203)
+++ branches/safari-605-branch/Source/WebCore/bindings/scripts/test/TestObj.idl 2018-02-07 00:53:36 UTC (rev 228204)
@@ -239,6 +239,7 @@
void methodWithOptionalNullableWrapperIsNull(optional TestObj? obj = null);
void methodWithOptionalXPathNSResolver(optional XPathNSResolver? resolver);
void methodWithOptionalRecord(optional record<DOMString, long>? record = null);
+ void methodWithOptionalPromise(optional Promise<void> promise);
// Callback interface parameters.
void methodWithCallbackArg(TestCallbackInterface callback);