Changeset 205953 in webkit
- Timestamp:
- Sep 15, 2016 12:21:18 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r205945 r205953 1 2016-09-15 Youenn Fablet <youenn@apple.com> 2 3 callPromiseFunction should be made usable for custom binding code 4 https://bugs.webkit.org/show_bug.cgi?id=161961 5 6 Reviewed by Darin Adler. 7 8 * fast/mediastream/MediaDevices-getUserMedia-expected.txt: 9 * fast/mediastream/MediaDevices-getUserMedia.html: Updated to expect a rejected promise in lieu of an exception. 10 1 11 2016-09-14 Jiewen Tan <jiewen_tan@apple.com> 2 12 -
trunk/LayoutTests/fast/mediastream/MediaDevices-getUserMedia-expected.txt
r204516 r205953 4 4 5 5 6 PASS navigator.mediaDevices.getUserMedia().then(invalidGotStream); threw exception TypeError: Not enough arguments.7 6 PASS typeof navigator.mediaDevices.webkitGetUserMedia is 'undefined' 8 7 PASS navigator.mediaDevices.getUserMedia({audio:true}).then(gotStream1); did not throw exception. 9 PASS navigator.mediaDevices.getUserMedia({}) rejected with error: TypeError: Type error 8 PASS navigator.mediaDevices.getUserMedia() rejected with error: TypeError: Not enough arguments 9 PASS navigator.mediaDevices.getUserMedia({}) rejected with error: TypeError: Type error 10 10 PASS Stream generated. 11 11 PASS stream.getAudioTracks().length is 1 -
trunk/LayoutTests/fast/mediastream/MediaDevices-getUserMedia.html
r204516 r205953 137 137 } 138 138 139 shouldThrow("navigator.mediaDevices.getUserMedia().then(invalidGotStream);"); 139 navigator.mediaDevices.getUserMedia().then(invalidGotStream, function(error) { 140 testPassed("navigator.mediaDevices.getUserMedia() rejected with error: " + error); 141 }); 140 142 navigator.mediaDevices.getUserMedia({}).then(invalidGotStream, function(error) { 141 testPassed(" 143 testPassed("navigator.mediaDevices.getUserMedia({}) rejected with error: " + error); 142 144 }); 143 145 shouldBe("typeof navigator.mediaDevices.webkitGetUserMedia", "'undefined'"); -
trunk/Source/WebCore/ChangeLog
r205941 r205953 1 2016-09-15 Youenn Fablet <youenn@apple.com> 2 3 callPromiseFunction should be made usable for custom binding code 4 https://bugs.webkit.org/show_bug.cgi?id=161961 5 6 Reviewed by Darin Adler. 7 8 Covered by updated test. 9 10 * bindings/js/JSDOMBinding.h: 11 (WebCore::castThisValue): Utility function to cast this value to a specific type. 12 * bindings/js/JSDOMPromise.h: 13 (WebCore::callPromiseFunction): Updated to take real promise function as a template parameter 14 for improved efficiency. Added workerMode template parameter. 15 (WebCore::bindingPromiseFunctionAdapter): Function signature adaptor. 16 * bindings/js/JSMediaDevicesCustom.cpp: 17 (WebCore::JSMediaDevicesGetUserMediaPromiseFunction): 18 (WebCore::JSMediaDevices::getUserMedia): Making use of callPromiseFunction to properly handle exceptions. 19 * bindings/scripts/CodeGeneratorJS.pm: 20 (GenerateImplementation): Updated to use template parameter. 21 * bindings/scripts/test/JS/JSTestNode.cpp: 22 (WebCore::jsTestNodePrototypeFunctionTestWorkerPromise): 23 (WebCore::jsTestNodePrototypeFunctionTestWorkerPromisePromise): 24 * bindings/scripts/test/JS/JSTestObj.cpp: 25 (WebCore::jsTestObjPrototypeFunctionTestPromiseFunction): 26 (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgument): 27 (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithException): 28 (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgument): 29 (WebCore::jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1): 30 (WebCore::jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2): 31 (WebCore::jsTestObjConstructorFunctionTestStaticPromiseFunction): 32 (WebCore::jsTestObjConstructorFunctionTestStaticPromiseFunctionWithException): 33 * bindings/scripts/test/TestNode.idl: Adding Worker promise binding test. 34 1 35 2016-09-14 Jiewen Tan <jiewen_tan@apple.com> 2 36 -
trunk/Source/WebCore/bindings/js/JSDOMBinding.h
r205744 r205953 174 174 template<typename DOMClass> JSC::JSValue wrap(JSC::ExecState*, JSDOMGlobalObject*, DOMClass&); 175 175 176 template<typename JSClass> JSClass& castThisValue(JSC::ExecState&); 177 176 178 void addImpureProperty(const AtomicString&); 177 179 … … 528 530 return wrapper; 529 531 return toJSNewlyCreated(state, globalObject, Ref<DOMClass>(domObject)); 532 } 533 534 template<typename JSClass> inline JSClass& castThisValue(JSC::ExecState& state) 535 { 536 auto thisValue = state.thisValue(); 537 auto castedThis = JSC::jsDynamicCast<JSClass*>(thisValue); 538 ASSERT(castedThis); 539 return *castedThis; 530 540 } 531 541 -
trunk/Source/WebCore/bindings/js/JSDOMPromise.h
r205729 r205953 158 158 void rejectPromiseWithExceptionIfAny(JSC::ExecState&, JSDOMGlobalObject&, JSC::JSPromiseDeferred&); 159 159 160 inline JSC::JSValue callPromiseFunction(JSC::ExecState& state, JSC::EncodedJSValue promiseFunction(JSC::ExecState*, Ref<DeferredWrapper>&&)) 160 using PromiseFunction = void(JSC::ExecState&, Ref<DeferredWrapper>&&); 161 162 enum class PromiseExecutionScope { WindowOnly, WindowOrWorker }; 163 164 template<PromiseFunction promiseFunction, PromiseExecutionScope executionScope> 165 inline JSC::JSValue callPromiseFunction(JSC::ExecState& state) 161 166 { 162 167 JSC::VM& vm = state.vm(); … … 167 172 168 173 // promiseDeferred can be null when terminating a Worker abruptly. 169 if ( !promiseDeferred)174 if (executionScope == PromiseExecutionScope::WindowOrWorker && !promiseDeferred) 170 175 return JSC::jsUndefined(); 171 176 172 promiseFunction( &state, DeferredWrapper::create(&state, &globalObject, promiseDeferred));177 promiseFunction(state, DeferredWrapper::create(&state, &globalObject, promiseDeferred)); 173 178 174 179 rejectPromiseWithExceptionIfAny(state, globalObject, *promiseDeferred); 175 180 ASSERT_UNUSED(scope, !scope.exception()); 176 181 return promiseDeferred->promise(); 182 } 183 184 using BindingPromiseFunction = JSC::EncodedJSValue(JSC::ExecState*, Ref<DeferredWrapper>&&); 185 template<BindingPromiseFunction bindingFunction> 186 inline void bindingPromiseFunctionAdapter(JSC::ExecState& state, Ref<DeferredWrapper>&& promise) 187 { 188 bindingFunction(&state, WTFMove(promise)); 189 } 190 191 template<BindingPromiseFunction bindingPromiseFunction, PromiseExecutionScope executionScope> 192 inline JSC::JSValue callPromiseFunction(JSC::ExecState& state) 193 { 194 return callPromiseFunction<bindingPromiseFunctionAdapter<bindingPromiseFunction>, executionScope>(state); 177 195 } 178 196 -
trunk/Source/WebCore/bindings/js/JSMediaDevicesCustom.cpp
r205348 r205953 341 341 } 342 342 343 JSValue JSMediaDevices::getUserMedia(ExecState& state)343 static void JSMediaDevicesGetUserMediaPromiseFunction(ExecState& state, Ref<DeferredWrapper>&& promise) 344 344 { 345 345 VM& vm = state.vm(); 346 346 auto scope = DECLARE_THROW_SCOPE(vm); 347 347 348 if (UNLIKELY(state.argumentCount() < 1)) 349 return JSValue::decode(throwVMError(&state, scope, createNotEnoughArgumentsError(&state))); 348 if (UNLIKELY(state.argumentCount() < 1)) { 349 throwVMError(&state, scope, createNotEnoughArgumentsError(&state)); 350 return; 351 } 352 350 353 ExceptionCode ec = 0; 351 354 auto constraintsDictionary = Dictionary(&state, state.uncheckedArgument(0)); … … 375 378 auto audioConstraints = MediaConstraintsImpl::create(WTFMove(mandatoryAudioConstraints), WTFMove(advancedAudioConstraints), areAudioConstraintsValid); 376 379 auto videoConstraints = MediaConstraintsImpl::create(WTFMove(mandatoryVideoConstraints), WTFMove(advancedVideoConstraints), areVideoConstraintsValid); 377 JSC::JSPromiseDeferred* promiseDeferred = JSC::JSPromiseDeferred::create(&state, globalObject()); 378 wrapped().getUserMedia(WTFMove(audioConstraints), WTFMove(videoConstraints), DeferredWrapper::create(&state, globalObject(), promiseDeferred), ec); 380 castThisValue<JSMediaDevices>(state).wrapped().getUserMedia(WTFMove(audioConstraints), WTFMove(videoConstraints), WTFMove(promise), ec); 379 381 setDOMException(&state, ec); 380 return promiseDeferred->promise(); 382 } 383 384 JSValue JSMediaDevices::getUserMedia(ExecState& state) 385 { 386 return callPromiseFunction<JSMediaDevicesGetUserMediaPromiseFunction, PromiseExecutionScope::WindowOnly>(state); 381 387 } 382 388 -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
r205913 r205953 3422 3422 AddToImplIncludes("JSDOMPromise.h"); 3423 3423 3424 my $scope = $interface->extendedAttributes->{"Exposed"} ? "WindowOrWorker" : "WindowOnly"; 3424 3425 push(@implContent, <<END); 3425 3426 static EncodedJSValue ${functionName}Promise(ExecState*, Ref<DeferredWrapper>&&); 3427 3426 3428 ${functionReturn} ${functionName}(ExecState* state) 3427 3429 { 3428 return JSValue::encode(callPromiseFunction(*state, ${functionName}Promise)); 3429 } 3430 3431 static inline EncodedJSValue ${functionName}Promise(ExecState* state, Ref<DeferredWrapper>&& deferredWrapper) 3430 ASSERT(state); 3431 return JSValue::encode(callPromiseFunction<${functionName}Promise, PromiseExecutionScope::${scope}>(*state)); 3432 } 3433 3434 static inline EncodedJSValue ${functionName}Promise(ExecState* state, Ref<DeferredWrapper>&& deferredWrapper) 3432 3435 END 3433 3436 } -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestNode.cpp
r205569 r205953 26 26 #include "JSDOMConstructor.h" 27 27 #include "JSDOMIterator.h" 28 #include "JSDOMPromise.h" 28 29 #include "RuntimeEnabledFeatures.h" 29 30 #include "URL.h" … … 38 39 // Functions 39 40 41 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionTestWorkerPromise(JSC::ExecState*); 40 42 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionSymbolIterator(JSC::ExecState*); 41 43 JSC::EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionEntries(JSC::ExecState*); … … 109 111 { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNodeConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNodeConstructor) } }, 110 112 { "name", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNodeName), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNodeName) } }, 113 { "testWorkerPromise", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionTestWorkerPromise), (intptr_t) (0) } }, 111 114 { "entries", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionEntries), (intptr_t) (0) } }, 112 115 { "keys", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNodePrototypeFunctionKeys), (intptr_t) (0) } }, … … 227 230 { 228 231 return getDOMConstructor<JSTestNodeConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject)); 232 } 233 234 static EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromisePromise(ExecState*, Ref<DeferredWrapper>&&); 235 EncodedJSValue JSC_HOST_CALL jsTestNodePrototypeFunctionTestWorkerPromise(ExecState* state) 236 { 237 ASSERT(state); 238 return JSValue::encode(callPromiseFunction<jsTestNodePrototypeFunctionTestWorkerPromisePromise, true>(*state)); 239 } 240 241 static inline EncodedJSValue jsTestNodePrototypeFunctionTestWorkerPromisePromise(ExecState* state, Ref<DeferredWrapper>&& deferredWrapper) 242 { 243 VM& vm = state->vm(); 244 auto throwScope = DECLARE_THROW_SCOPE(vm); 245 UNUSED_PARAM(throwScope); 246 JSValue thisValue = state->thisValue(); 247 auto castedThis = jsDynamicCast<JSTestNode*>(thisValue); 248 if (UNLIKELY(!castedThis)) 249 return throwThisTypeError(*state, throwScope, "TestNode", "testWorkerPromise"); 250 ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestNode::info()); 251 auto& impl = castedThis->wrapped(); 252 impl.testWorkerPromise(WTFMove(deferredWrapper)); 253 return JSValue::encode(jsUndefined()); 229 254 } 230 255 -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
r205897 r205953 7161 7161 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunction(ExecState* state) 7162 7162 { 7163 return JSValue::encode(callPromiseFunction(*state, jsTestObjPrototypeFunctionTestPromiseFunctionPromise)); 7163 ASSERT(state); 7164 return JSValue::encode(callPromiseFunction<jsTestObjPrototypeFunctionTestPromiseFunctionPromise, false>(*state)); 7164 7165 } 7165 7166 … … 7182 7183 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgument(ExecState* state) 7183 7184 { 7184 return JSValue::encode(callPromiseFunction(*state, jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise)); 7185 ASSERT(state); 7186 return JSValue::encode(callPromiseFunction<jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise, false>(*state)); 7185 7187 } 7186 7188 … … 7208 7210 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithException(ExecState* state) 7209 7211 { 7210 return JSValue::encode(callPromiseFunction(*state, jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise)); 7212 ASSERT(state); 7213 return JSValue::encode(callPromiseFunction<jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise, false>(*state)); 7211 7214 } 7212 7215 … … 7231 7234 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgument(ExecState* state) 7232 7235 { 7233 return JSValue::encode(callPromiseFunction(*state, jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise)); 7236 ASSERT(state); 7237 return JSValue::encode(callPromiseFunction<jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise, false>(*state)); 7234 7238 } 7235 7239 … … 7255 7259 static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1(ExecState* state) 7256 7260 { 7257 return JSValue::encode(callPromiseFunction(*state, jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1Promise)); 7261 ASSERT(state); 7262 return JSValue::encode(callPromiseFunction<jsTestObjPrototypeFunctionTestPromiseOverloadedFunction1Promise, false>(*state)); 7258 7263 } 7259 7264 … … 7281 7286 static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2(ExecState* state) 7282 7287 { 7283 return JSValue::encode(callPromiseFunction(*state, jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2Promise)); 7288 ASSERT(state); 7289 return JSValue::encode(callPromiseFunction<jsTestObjPrototypeFunctionTestPromiseOverloadedFunction2Promise, false>(*state)); 7284 7290 } 7285 7291 … … 7324 7330 EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionTestStaticPromiseFunction(ExecState* state) 7325 7331 { 7326 return JSValue::encode(callPromiseFunction(*state, jsTestObjConstructorFunctionTestStaticPromiseFunctionPromise)); 7332 ASSERT(state); 7333 return JSValue::encode(callPromiseFunction<jsTestObjConstructorFunctionTestStaticPromiseFunctionPromise, false>(*state)); 7327 7334 } 7328 7335 … … 7339 7346 EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionTestStaticPromiseFunctionWithException(ExecState* state) 7340 7347 { 7341 return JSValue::encode(callPromiseFunction(*state, jsTestObjConstructorFunctionTestStaticPromiseFunctionWithExceptionPromise)); 7348 ASSERT(state); 7349 return JSValue::encode(callPromiseFunction<jsTestObjConstructorFunctionTestStaticPromiseFunctionWithExceptionPromise, false>(*state)); 7342 7350 } 7343 7351 -
trunk/Source/WebCore/bindings/scripts/test/TestNode.idl
r202728 r205953 22 22 Constructor, 23 23 ExportMacro=WEBCORE_TESTSUPPORT_EXPORT, 24 Exposed=(Window,Worker) 24 25 ] interface TestNode : Node { 25 26 attribute DOMString name; 26 27 27 28 [EnabledAtRuntime=DOMIterator] iterable<TestNode>; 29 Promise testWorkerPromise(); 28 30 }; 29
Note: See TracChangeset
for help on using the changeset viewer.