JSValue JSMediaDevices::getUserMedia(ExecState* exec) { JSPromiseDeferred* promiseDeferred = JSPromiseDeferred::create(exec, globalObject()); DeferredWrapper wrapper(exec, globalObject(), promiseDeferred); Dictionary options(exec, exec->argument(0)); if (exec->hadException()) { Exception* exception = exec->exception(); exec->clearException(); wrapper.reject(exception->value()); return promiseDeferred->promise(); } if (!options.isObject()) { JSValue error = createTypeError(exec, "First argument of getUserMedia must be a valid Dictionary"); wrapper.reject(error); return promiseDeferred->promise(); } auto resolveCallback = [wrapper](MediaStream& stream) mutable { wrapper.resolve(&stream); }; auto rejectCallback = [wrapper](NavigatorUserMediaError& error) mutable { wrapper.reject(&error); }; ExceptionCode ec = 0; impl().getUserMedia(options, WTF::move(resolveCallback), WTF::move(rejectCallback), ec); if (ec) wrapper.reject(ec); return promiseDeferred->promise(); }
static ExceptionStatus handleExceptionIfNeeded(ExecState* exec, JSValueRef* returnedExceptionRef) { if (exec->hadException()) { Exception* exception = exec->exception(); if (returnedExceptionRef) *returnedExceptionRef = toRef(exec, exception->value()); exec->clearException(); #if ENABLE(REMOTE_INSPECTOR) exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exception); #endif return ExceptionStatus::DidThrow; } return ExceptionStatus::DidNotThrow; }