<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[205953] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/205953">205953</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-09-15 00:21:18 -0700 (Thu, 15 Sep 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>callPromiseFunction should be made usable for custom binding code
https://bugs.webkit.org/show_bug.cgi?id=161961

Patch by Youenn Fablet &lt;youenn@apple.com&gt; on 2016-09-15
Reviewed by Darin Adler.

Source/WebCore:

Covered by updated test.

* bindings/js/JSDOMBinding.h:
(WebCore::castThisValue): Utility function to cast this value to a specific type.
* bindings/js/JSDOMPromise.h:
(WebCore::callPromiseFunction): Updated to take real promise function as a template parameter
for improved efficiency. Added workerMode template parameter.
(WebCore::bindingPromiseFunctionAdapter): Function signature adaptor.
* bindings/js/JSMediaDevicesCustom.cpp:
(WebCore::JSMediaDevicesGetUserMediaPromiseFunction):
(WebCore::JSMediaDevices::getUserMedia): Making use of callPromiseFunction to properly handle exceptions.
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateImplementation): Updated to use template parameter.
* bindings/scripts/test/JS/JSTestNode.cpp:
(WebCore::jsTestNodePrototypeFunctionTestWorkerPromise):
(WebCore::jsTestNodePrototypeFunctionTestWorkerPromisePromise):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunction):
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgument):
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithException):
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgument):
(WebCore::jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1):
(WebCore::jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2):
(WebCore::jsTestObjConstructorFunctionTestStaticPromiseFunction):
(WebCore::jsTestObjConstructorFunctionTestStaticPromiseFunctionWithException):
* bindings/scripts/test/TestNode.idl: Adding Worker promise binding test.

LayoutTests:

* fast/mediastream/MediaDevices-getUserMedia-expected.txt:
* fast/mediastream/MediaDevices-getUserMedia.html: Updated to expect a rejected promise in lieu of an exception.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfastmediastreamMediaDevicesgetUserMediaexpectedtxt">trunk/LayoutTests/fast/mediastream/MediaDevices-getUserMedia-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastmediastreamMediaDevicesgetUserMediahtml">trunk/LayoutTests/fast/mediastream/MediaDevices-getUserMedia.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSDOMBindingh">trunk/Source/WebCore/bindings/js/JSDOMBinding.h</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSDOMPromiseh">trunk/Source/WebCore/bindings/js/JSDOMPromise.h</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSMediaDevicesCustomcpp">trunk/Source/WebCore/bindings/js/JSMediaDevicesCustom.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptsCodeGeneratorJSpm">trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptstestJSJSTestNodecpp">trunk/Source/WebCore/bindings/scripts/test/JS/JSTestNode.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptstestJSJSTestObjcpp">trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptstestTestNodeidl">trunk/Source/WebCore/bindings/scripts/test/TestNode.idl</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (205952 => 205953)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-09-15 06:57:12 UTC (rev 205952)
+++ trunk/LayoutTests/ChangeLog        2016-09-15 07:21:18 UTC (rev 205953)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2016-09-15  Youenn Fablet  &lt;youenn@apple.com&gt;
+
+        callPromiseFunction should be made usable for custom binding code
+        https://bugs.webkit.org/show_bug.cgi?id=161961
+
+        Reviewed by Darin Adler.
+
+        * fast/mediastream/MediaDevices-getUserMedia-expected.txt:
+        * fast/mediastream/MediaDevices-getUserMedia.html: Updated to expect a rejected promise in lieu of an exception.
+
</ins><span class="cx"> 2016-09-14  Jiewen Tan  &lt;jiewen_tan@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, update ios-simulator-wk1 test expectations after migrating to iOS 10
</span></span></pre></div>
<a id="trunkLayoutTestsfastmediastreamMediaDevicesgetUserMediaexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/mediastream/MediaDevices-getUserMedia-expected.txt (205952 => 205953)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/mediastream/MediaDevices-getUserMedia-expected.txt        2016-09-15 06:57:12 UTC (rev 205952)
+++ trunk/LayoutTests/fast/mediastream/MediaDevices-getUserMedia-expected.txt        2016-09-15 07:21:18 UTC (rev 205953)
</span><span class="lines">@@ -3,10 +3,10 @@
</span><span class="cx"> On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-PASS navigator.mediaDevices.getUserMedia().then(invalidGotStream); threw exception TypeError: Not enough arguments.
</del><span class="cx"> PASS typeof navigator.mediaDevices.webkitGetUserMedia is 'undefined'
</span><span class="cx"> PASS navigator.mediaDevices.getUserMedia({audio:true}).then(gotStream1); did not throw exception.
</span><del>-PASS  navigator.mediaDevices.getUserMedia({}) rejected with error: TypeError: Type error
</del><ins>+PASS navigator.mediaDevices.getUserMedia() rejected with error: TypeError: Not enough arguments
+PASS navigator.mediaDevices.getUserMedia({}) rejected with error: TypeError: Type error
</ins><span class="cx"> PASS Stream generated.
</span><span class="cx"> PASS stream.getAudioTracks().length is 1
</span><span class="cx"> PASS stream.getVideoTracks().length is 0
</span></span></pre></div>
<a id="trunkLayoutTestsfastmediastreamMediaDevicesgetUserMediahtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/mediastream/MediaDevices-getUserMedia.html (205952 => 205953)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/mediastream/MediaDevices-getUserMedia.html        2016-09-15 06:57:12 UTC (rev 205952)
+++ trunk/LayoutTests/fast/mediastream/MediaDevices-getUserMedia.html        2016-09-15 07:21:18 UTC (rev 205953)
</span><span class="lines">@@ -136,9 +136,11 @@
</span><span class="cx">                 shouldNotThrow(&quot;navigator.mediaDevices.getUserMedia({video:true}).then(gotStream2);&quot;)
</span><span class="cx">             }
</span><span class="cx"> 
</span><del>-            shouldThrow(&quot;navigator.mediaDevices.getUserMedia().then(invalidGotStream);&quot;);
</del><ins>+            navigator.mediaDevices.getUserMedia().then(invalidGotStream, function(error) {
+                testPassed(&quot;navigator.mediaDevices.getUserMedia() rejected with error: &quot; + error);
+            });
</ins><span class="cx">             navigator.mediaDevices.getUserMedia({}).then(invalidGotStream, function(error) {
</span><del>-                testPassed(&quot; navigator.mediaDevices.getUserMedia({}) rejected with error: &quot; + error);
</del><ins>+                testPassed(&quot;navigator.mediaDevices.getUserMedia({}) rejected with error: &quot; + error);
</ins><span class="cx">             });
</span><span class="cx">             shouldBe(&quot;typeof navigator.mediaDevices.webkitGetUserMedia&quot;, &quot;'undefined'&quot;);
</span><span class="cx">             setUserMediaPermission(true);
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (205952 => 205953)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-09-15 06:57:12 UTC (rev 205952)
+++ trunk/Source/WebCore/ChangeLog        2016-09-15 07:21:18 UTC (rev 205953)
</span><span class="lines">@@ -1,3 +1,37 @@
</span><ins>+2016-09-15  Youenn Fablet  &lt;youenn@apple.com&gt;
+
+        callPromiseFunction should be made usable for custom binding code
+        https://bugs.webkit.org/show_bug.cgi?id=161961
+
+        Reviewed by Darin Adler.
+
+        Covered by updated test.
+
+        * bindings/js/JSDOMBinding.h:
+        (WebCore::castThisValue): Utility function to cast this value to a specific type.
+        * bindings/js/JSDOMPromise.h:
+        (WebCore::callPromiseFunction): Updated to take real promise function as a template parameter
+        for improved efficiency. Added workerMode template parameter.
+        (WebCore::bindingPromiseFunctionAdapter): Function signature adaptor.
+        * bindings/js/JSMediaDevicesCustom.cpp:
+        (WebCore::JSMediaDevicesGetUserMediaPromiseFunction):
+        (WebCore::JSMediaDevices::getUserMedia): Making use of callPromiseFunction to properly handle exceptions.
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateImplementation): Updated to use template parameter.
+        * bindings/scripts/test/JS/JSTestNode.cpp:
+        (WebCore::jsTestNodePrototypeFunctionTestWorkerPromise):
+        (WebCore::jsTestNodePrototypeFunctionTestWorkerPromisePromise):
+        * bindings/scripts/test/JS/JSTestObj.cpp:
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunction):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgument):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithException):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgument):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2):
+        (WebCore::jsTestObjConstructorFunctionTestStaticPromiseFunction):
+        (WebCore::jsTestObjConstructorFunctionTestStaticPromiseFunctionWithException):
+        * bindings/scripts/test/TestNode.idl: Adding Worker promise binding test.
+
</ins><span class="cx"> 2016-09-14  Jiewen Tan  &lt;jiewen_tan@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         WebCrypto algorithms should be exposed via KeyAlgorithm dictionary
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSDOMBindingh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSDOMBinding.h (205952 => 205953)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSDOMBinding.h        2016-09-15 06:57:12 UTC (rev 205952)
+++ trunk/Source/WebCore/bindings/js/JSDOMBinding.h        2016-09-15 07:21:18 UTC (rev 205953)
</span><span class="lines">@@ -173,6 +173,8 @@
</span><span class="cx"> 
</span><span class="cx"> template&lt;typename DOMClass&gt; JSC::JSValue wrap(JSC::ExecState*, JSDOMGlobalObject*, DOMClass&amp;);
</span><span class="cx"> 
</span><ins>+template&lt;typename JSClass&gt; JSClass&amp; castThisValue(JSC::ExecState&amp;);
+
</ins><span class="cx"> void addImpureProperty(const AtomicString&amp;);
</span><span class="cx"> 
</span><span class="cx"> const JSC::HashTable&amp; getHashTableForGlobalData(JSC::VM&amp;, const JSC::HashTable&amp; staticTable);
</span><span class="lines">@@ -529,6 +531,14 @@
</span><span class="cx">     return toJSNewlyCreated(state, globalObject, Ref&lt;DOMClass&gt;(domObject));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+template&lt;typename JSClass&gt; inline JSClass&amp; castThisValue(JSC::ExecState&amp; state)
+{
+    auto thisValue = state.thisValue();
+    auto castedThis = JSC::jsDynamicCast&lt;JSClass*&gt;(thisValue);
+    ASSERT(castedThis);
+    return *castedThis;
+}
+
</ins><span class="cx"> inline int32_t finiteInt32Value(JSC::JSValue value, JSC::ExecState* exec, bool&amp; okay)
</span><span class="cx"> {
</span><span class="cx">     double number = value.toNumber(exec);
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSDOMPromiseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSDOMPromise.h (205952 => 205953)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSDOMPromise.h        2016-09-15 06:57:12 UTC (rev 205952)
+++ trunk/Source/WebCore/bindings/js/JSDOMPromise.h        2016-09-15 07:21:18 UTC (rev 205953)
</span><span class="lines">@@ -157,7 +157,12 @@
</span><span class="cx"> void fulfillPromiseWithArrayBuffer(Ref&lt;DeferredWrapper&gt;&amp;&amp;, const void*, size_t);
</span><span class="cx"> void rejectPromiseWithExceptionIfAny(JSC::ExecState&amp;, JSDOMGlobalObject&amp;, JSC::JSPromiseDeferred&amp;);
</span><span class="cx"> 
</span><del>-inline JSC::JSValue callPromiseFunction(JSC::ExecState&amp; state, JSC::EncodedJSValue promiseFunction(JSC::ExecState*, Ref&lt;DeferredWrapper&gt;&amp;&amp;))
</del><ins>+using PromiseFunction = void(JSC::ExecState&amp;, Ref&lt;DeferredWrapper&gt;&amp;&amp;);
+
+enum class PromiseExecutionScope { WindowOnly, WindowOrWorker };
+
+template&lt;PromiseFunction promiseFunction, PromiseExecutionScope executionScope&gt;
+inline JSC::JSValue callPromiseFunction(JSC::ExecState&amp; state)
</ins><span class="cx"> {
</span><span class="cx">     JSC::VM&amp; vm = state.vm();
</span><span class="cx">     auto scope = DECLARE_CATCH_SCOPE(vm);
</span><span class="lines">@@ -166,10 +171,10 @@
</span><span class="cx">     JSC::JSPromiseDeferred* promiseDeferred = JSC::JSPromiseDeferred::create(&amp;state, &amp;globalObject);
</span><span class="cx"> 
</span><span class="cx">     // promiseDeferred can be null when terminating a Worker abruptly.
</span><del>-    if (!promiseDeferred)
</del><ins>+    if (executionScope == PromiseExecutionScope::WindowOrWorker &amp;&amp; !promiseDeferred)
</ins><span class="cx">         return JSC::jsUndefined();
</span><span class="cx"> 
</span><del>-    promiseFunction(&amp;state, DeferredWrapper::create(&amp;state, &amp;globalObject, promiseDeferred));
</del><ins>+    promiseFunction(state, DeferredWrapper::create(&amp;state, &amp;globalObject, promiseDeferred));
</ins><span class="cx"> 
</span><span class="cx">     rejectPromiseWithExceptionIfAny(state, globalObject, *promiseDeferred);
</span><span class="cx">     ASSERT_UNUSED(scope, !scope.exception());
</span><span class="lines">@@ -176,6 +181,19 @@
</span><span class="cx">     return promiseDeferred-&gt;promise();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+using BindingPromiseFunction = JSC::EncodedJSValue(JSC::ExecState*, Ref&lt;DeferredWrapper&gt;&amp;&amp;);
+template&lt;BindingPromiseFunction bindingFunction&gt;
+inline void bindingPromiseFunctionAdapter(JSC::ExecState&amp; state, Ref&lt;DeferredWrapper&gt;&amp;&amp; promise)
+{
+    bindingFunction(&amp;state, WTFMove(promise));
+}
+
+template&lt;BindingPromiseFunction bindingPromiseFunction, PromiseExecutionScope executionScope&gt;
+inline JSC::JSValue callPromiseFunction(JSC::ExecState&amp; state)
+{
+    return callPromiseFunction&lt;bindingPromiseFunctionAdapter&lt;bindingPromiseFunction&gt;, executionScope&gt;(state);
+}
+
</ins><span class="cx"> // At the moment, Value cannot be a Ref&lt;T&gt; or RefPtr&lt;T&gt;, it should be a DOM class.
</span><span class="cx"> template &lt;typename Value&gt;
</span><span class="cx"> class DOMPromise {
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSMediaDevicesCustomcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSMediaDevicesCustom.cpp (205952 => 205953)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSMediaDevicesCustom.cpp        2016-09-15 06:57:12 UTC (rev 205952)
+++ trunk/Source/WebCore/bindings/js/JSMediaDevicesCustom.cpp        2016-09-15 07:21:18 UTC (rev 205953)
</span><span class="lines">@@ -340,13 +340,16 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-JSValue JSMediaDevices::getUserMedia(ExecState&amp; state)
</del><ins>+static void JSMediaDevicesGetUserMediaPromiseFunction(ExecState&amp; state, Ref&lt;DeferredWrapper&gt;&amp;&amp; promise)
</ins><span class="cx"> {
</span><span class="cx">     VM&amp; vm = state.vm();
</span><span class="cx">     auto scope = DECLARE_THROW_SCOPE(vm);
</span><span class="cx"> 
</span><del>-    if (UNLIKELY(state.argumentCount() &lt; 1))
-        return JSValue::decode(throwVMError(&amp;state, scope, createNotEnoughArgumentsError(&amp;state)));
</del><ins>+    if (UNLIKELY(state.argumentCount() &lt; 1)) {
+        throwVMError(&amp;state, scope, createNotEnoughArgumentsError(&amp;state));
+        return;
+    }
+
</ins><span class="cx">     ExceptionCode ec = 0;
</span><span class="cx">     auto constraintsDictionary = Dictionary(&amp;state, state.uncheckedArgument(0));
</span><span class="cx"> 
</span><span class="lines">@@ -374,12 +377,15 @@
</span><span class="cx"> 
</span><span class="cx">     auto audioConstraints = MediaConstraintsImpl::create(WTFMove(mandatoryAudioConstraints), WTFMove(advancedAudioConstraints), areAudioConstraintsValid);
</span><span class="cx">     auto videoConstraints = MediaConstraintsImpl::create(WTFMove(mandatoryVideoConstraints), WTFMove(advancedVideoConstraints), areVideoConstraintsValid);
</span><del>-    JSC::JSPromiseDeferred* promiseDeferred = JSC::JSPromiseDeferred::create(&amp;state, globalObject());
-    wrapped().getUserMedia(WTFMove(audioConstraints), WTFMove(videoConstraints), DeferredWrapper::create(&amp;state, globalObject(), promiseDeferred), ec);
</del><ins>+    castThisValue&lt;JSMediaDevices&gt;(state).wrapped().getUserMedia(WTFMove(audioConstraints), WTFMove(videoConstraints), WTFMove(promise), ec);
</ins><span class="cx">     setDOMException(&amp;state, ec);
</span><del>-    return promiseDeferred-&gt;promise();
</del><span class="cx"> }
</span><span class="cx"> 
</span><ins>+JSValue JSMediaDevices::getUserMedia(ExecState&amp; state)
+{
+    return callPromiseFunction&lt;JSMediaDevicesGetUserMediaPromiseFunction, PromiseExecutionScope::WindowOnly&gt;(state);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+}
+
</ins><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptsCodeGeneratorJSpm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (205952 => 205953)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm        2016-09-15 06:57:12 UTC (rev 205952)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm        2016-09-15 07:21:18 UTC (rev 205953)
</span><span class="lines">@@ -3421,14 +3421,17 @@
</span><span class="cx">             if (IsReturningPromise($function) &amp;&amp; !$isCustom) {
</span><span class="cx">                 AddToImplIncludes(&quot;JSDOMPromise.h&quot;);
</span><span class="cx"> 
</span><ins>+                my $scope = $interface-&gt;extendedAttributes-&gt;{&quot;Exposed&quot;} ? &quot;WindowOrWorker&quot; : &quot;WindowOnly&quot;;
</ins><span class="cx">                 push(@implContent, &lt;&lt;END);
</span><span class="cx"> static EncodedJSValue ${functionName}Promise(ExecState*, Ref&lt;DeferredWrapper&gt;&amp;&amp;);
</span><ins>+
</ins><span class="cx"> ${functionReturn} ${functionName}(ExecState* state)
</span><span class="cx"> {
</span><del>-    return JSValue::encode(callPromiseFunction(*state, ${functionName}Promise));
</del><ins>+    ASSERT(state);
+    return JSValue::encode(callPromiseFunction&lt;${functionName}Promise, PromiseExecutionScope::${scope}&gt;(*state));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static inline EncodedJSValue ${functionName}Promise(ExecState* state, Ref&lt;DeferredWrapper&gt;&amp;&amp;  deferredWrapper)
</del><ins>+static inline EncodedJSValue ${functionName}Promise(ExecState* state, Ref&lt;DeferredWrapper&gt;&amp;&amp; deferredWrapper)
</ins><span class="cx"> END
</span><span class="cx">             }
</span><span class="cx">             else {
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptstestJSJSTestNodecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestNode.cpp (205952 => 205953)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestNode.cpp        2016-09-15 06:57:12 UTC (rev 205952)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestNode.cpp        2016-09-15 07:21:18 UTC (rev 205953)
</span><span class="lines">@@ -25,6 +25,7 @@
</span><span class="cx"> #include &quot;JSDOMBinding.h&quot;
</span><span class="cx"> #include &quot;JSDOMConstructor.h&quot;
</span><span class="cx"> #include &quot;JSDOMIterator.h&quot;
</span><ins>+#include &quot;JSDOMPromise.h&quot;
</ins><span class="cx"> #include &quot;RuntimeEnabledFeatures.h&quot;
</span><span class="cx"> #include &quot;URL.h&quot;
</span><span class="cx"> #include &lt;runtime/Error.h&gt;
</span><span class="lines">@@ -37,6 +38,7 @@
</span><span class="cx"> 
</span><span class="cx"> // Functions
</span><span class="cx"> 
</span><ins>+JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionTestWorkerPromise(JSC::ExecState*);
</ins><span class="cx"> JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionSymbolIterator(JSC::ExecState*);
</span><span class="cx"> JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionEntries(JSC::ExecState*);
</span><span class="cx"> JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionKeys(JSC::ExecState*);
</span><span class="lines">@@ -108,6 +110,7 @@
</span><span class="cx"> {
</span><span class="cx">     { &quot;constructor&quot;, DontEnum, NoIntrinsic, { (intptr_t)static_cast&lt;PropertySlot::GetValueFunc&gt;(jsTestNodeConstructor), (intptr_t) static_cast&lt;PutPropertySlot::PutValueFunc&gt;(setJSTestNodeConstructor) } },
</span><span class="cx">     { &quot;name&quot;, CustomAccessor, NoIntrinsic, { (intptr_t)static_cast&lt;PropertySlot::GetValueFunc&gt;(jsTestNodeName), (intptr_t) static_cast&lt;PutPropertySlot::PutValueFunc&gt;(setJSTestNodeName) } },
</span><ins>+    { &quot;testWorkerPromise&quot;, JSC::Function, NoIntrinsic, { (intptr_t)static_cast&lt;NativeFunction&gt;(jsTestNodePrototypeFunctionTestWorkerPromise), (intptr_t) (0) } },
</ins><span class="cx">     { &quot;entries&quot;, JSC::Function, NoIntrinsic, { (intptr_t)static_cast&lt;NativeFunction&gt;(jsTestNodePrototypeFunctionEntries), (intptr_t) (0) } },
</span><span class="cx">     { &quot;keys&quot;, JSC::Function, NoIntrinsic, { (intptr_t)static_cast&lt;NativeFunction&gt;(jsTestNodePrototypeFunctionKeys), (intptr_t) (0) } },
</span><span class="cx">     { &quot;values&quot;, JSC::Function, NoIntrinsic, { (intptr_t)static_cast&lt;NativeFunction&gt;(jsTestNodePrototypeFunctionValues), (intptr_t) (0) } },
</span><span class="lines">@@ -228,6 +231,28 @@
</span><span class="cx">     return getDOMConstructor&lt;JSTestNodeConstructor&gt;(vm, *jsCast&lt;const JSDOMGlobalObject*&gt;(globalObject));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromisePromise(ExecState*, Ref&lt;DeferredWrapper&gt;&amp;&amp;);
+EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionTestWorkerPromise(ExecState* state)
+{
+    ASSERT(state);
+    return JSValue::encode(callPromiseFunction&lt;jsTestNodePrototypeFunctionTestWorkerPromisePromise, true&gt;(*state));
+}
+
+static inline EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromisePromise(ExecState* state, Ref&lt;DeferredWrapper&gt;&amp;&amp;  deferredWrapper)
+{
+    VM&amp; vm = state-&gt;vm();
+    auto throwScope = DECLARE_THROW_SCOPE(vm);
+    UNUSED_PARAM(throwScope);
+    JSValue thisValue = state-&gt;thisValue();
+    auto castedThis = jsDynamicCast&lt;JSTestNode*&gt;(thisValue);
+    if (UNLIKELY(!castedThis))
+        return throwThisTypeError(*state, throwScope, &quot;TestNode&quot;, &quot;testWorkerPromise&quot;);
+    ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestNode::info());
+    auto&amp; impl = castedThis-&gt;wrapped();
+    impl.testWorkerPromise(WTFMove(deferredWrapper));
+    return JSValue::encode(jsUndefined());
+}
+
</ins><span class="cx"> using TestNodeIterator = JSDOMIterator&lt;JSTestNode&gt;;
</span><span class="cx"> using TestNodeIteratorPrototype = JSDOMIteratorPrototype&lt;JSTestNode&gt;;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptstestJSJSTestObjcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp (205952 => 205953)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp        2016-09-15 06:57:12 UTC (rev 205952)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp        2016-09-15 07:21:18 UTC (rev 205953)
</span><span class="lines">@@ -7160,7 +7160,8 @@
</span><span class="cx"> static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionPromise(ExecState*, Ref&lt;DeferredWrapper&gt;&amp;&amp;);
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunction(ExecState* state)
</span><span class="cx"> {
</span><del>-    return JSValue::encode(callPromiseFunction(*state, jsTestObjPrototypeFunctionTestPromiseFunctionPromise));
</del><ins>+    ASSERT(state);
+    return JSValue::encode(callPromiseFunction&lt;jsTestObjPrototypeFunctionTestPromiseFunctionPromise, false&gt;(*state));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionPromise(ExecState* state, Ref&lt;DeferredWrapper&gt;&amp;&amp;  deferredWrapper)
</span><span class="lines">@@ -7181,7 +7182,8 @@
</span><span class="cx"> static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise(ExecState*, Ref&lt;DeferredWrapper&gt;&amp;&amp;);
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgument(ExecState* state)
</span><span class="cx"> {
</span><del>-    return JSValue::encode(callPromiseFunction(*state, jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise));
</del><ins>+    ASSERT(state);
+    return JSValue::encode(callPromiseFunction&lt;jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise, false&gt;(*state));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise(ExecState* state, Ref&lt;DeferredWrapper&gt;&amp;&amp;  deferredWrapper)
</span><span class="lines">@@ -7207,7 +7209,8 @@
</span><span class="cx"> static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise(ExecState*, Ref&lt;DeferredWrapper&gt;&amp;&amp;);
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithException(ExecState* state)
</span><span class="cx"> {
</span><del>-    return JSValue::encode(callPromiseFunction(*state, jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise));
</del><ins>+    ASSERT(state);
+    return JSValue::encode(callPromiseFunction&lt;jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise, false&gt;(*state));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise(ExecState* state, Ref&lt;DeferredWrapper&gt;&amp;&amp;  deferredWrapper)
</span><span class="lines">@@ -7230,7 +7233,8 @@
</span><span class="cx"> static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise(ExecState*, Ref&lt;DeferredWrapper&gt;&amp;&amp;);
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgument(ExecState* state)
</span><span class="cx"> {
</span><del>-    return JSValue::encode(callPromiseFunction(*state, jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise));
</del><ins>+    ASSERT(state);
+    return JSValue::encode(callPromiseFunction&lt;jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise, false&gt;(*state));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise(ExecState* state, Ref&lt;DeferredWrapper&gt;&amp;&amp;  deferredWrapper)
</span><span class="lines">@@ -7254,7 +7258,8 @@
</span><span class="cx"> static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1Promise(ExecState*, Ref&lt;DeferredWrapper&gt;&amp;&amp;);
</span><span class="cx"> static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1(ExecState* state)
</span><span class="cx"> {
</span><del>-    return JSValue::encode(callPromiseFunction(*state, jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1Promise));
</del><ins>+    ASSERT(state);
+    return JSValue::encode(callPromiseFunction&lt;jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1Promise, false&gt;(*state));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1Promise(ExecState* state, Ref&lt;DeferredWrapper&gt;&amp;&amp;  deferredWrapper)
</span><span class="lines">@@ -7280,7 +7285,8 @@
</span><span class="cx"> static EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2Promise(ExecState*, Ref&lt;DeferredWrapper&gt;&amp;&amp;);
</span><span class="cx"> static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2(ExecState* state)
</span><span class="cx"> {
</span><del>-    return JSValue::encode(callPromiseFunction(*state, jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2Promise));
</del><ins>+    ASSERT(state);
+    return JSValue::encode(callPromiseFunction&lt;jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2Promise, false&gt;(*state));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2Promise(ExecState* state, Ref&lt;DeferredWrapper&gt;&amp;&amp;  deferredWrapper)
</span><span class="lines">@@ -7323,7 +7329,8 @@
</span><span class="cx"> static EncodedJSValue jsTestObjConstructorFunctionTestStaticPromiseFunctionPromise(ExecState*, Ref&lt;DeferredWrapper&gt;&amp;&amp;);
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionTestStaticPromiseFunction(ExecState* state)
</span><span class="cx"> {
</span><del>-    return JSValue::encode(callPromiseFunction(*state, jsTestObjConstructorFunctionTestStaticPromiseFunctionPromise));
</del><ins>+    ASSERT(state);
+    return JSValue::encode(callPromiseFunction&lt;jsTestObjConstructorFunctionTestStaticPromiseFunctionPromise, false&gt;(*state));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static inline EncodedJSValue jsTestObjConstructorFunctionTestStaticPromiseFunctionPromise(ExecState* state, Ref&lt;DeferredWrapper&gt;&amp;&amp;  deferredWrapper)
</span><span class="lines">@@ -7338,7 +7345,8 @@
</span><span class="cx"> static EncodedJSValue jsTestObjConstructorFunctionTestStaticPromiseFunctionWithExceptionPromise(ExecState*, Ref&lt;DeferredWrapper&gt;&amp;&amp;);
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionTestStaticPromiseFunctionWithException(ExecState* state)
</span><span class="cx"> {
</span><del>-    return JSValue::encode(callPromiseFunction(*state, jsTestObjConstructorFunctionTestStaticPromiseFunctionWithExceptionPromise));
</del><ins>+    ASSERT(state);
+    return JSValue::encode(callPromiseFunction&lt;jsTestObjConstructorFunctionTestStaticPromiseFunctionWithExceptionPromise, false&gt;(*state));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static inline EncodedJSValue jsTestObjConstructorFunctionTestStaticPromiseFunctionWithExceptionPromise(ExecState* state, Ref&lt;DeferredWrapper&gt;&amp;&amp;  deferredWrapper)
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptstestTestNodeidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/test/TestNode.idl (205952 => 205953)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/scripts/test/TestNode.idl        2016-09-15 06:57:12 UTC (rev 205952)
+++ trunk/Source/WebCore/bindings/scripts/test/TestNode.idl        2016-09-15 07:21:18 UTC (rev 205953)
</span><span class="lines">@@ -21,9 +21,10 @@
</span><span class="cx"> [
</span><span class="cx">     Constructor,
</span><span class="cx">     ExportMacro=WEBCORE_TESTSUPPORT_EXPORT,
</span><ins>+    Exposed=(Window,Worker)
</ins><span class="cx"> ] interface TestNode : Node {
</span><span class="cx">     attribute DOMString name;
</span><span class="cx"> 
</span><span class="cx">     [EnabledAtRuntime=DOMIterator] iterable&lt;TestNode&gt;;
</span><ins>+    Promise testWorkerPromise();
</ins><span class="cx"> };
</span><del>-
</del></span></pre>
</div>
</div>

</body>
</html>