зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1749048 - Part 1. Expose methods to throw/reject based on a MediaResult. r=media-playback-reviewers,padenot
This patch adds convenience methods to throw on ErrorResult and reject on Promise directly from a MediaResult which has an nsresult and a message. Differential Revision: https://phabricator.services.mozilla.com/D212834
This commit is contained in:
Родитель
ced3221cfb
Коммит
e03ffb0c58
|
@ -0,0 +1,62 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#include "MediaResult.h"
|
||||||
|
#include "mozilla/Assertions.h"
|
||||||
|
#include "mozilla/ErrorResult.h"
|
||||||
|
#include "mozilla/dom/Promise.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
|
||||||
|
#define EXTENDED_EXCEPTIONS \
|
||||||
|
DOMEXCEPTION(AbortError, NS_ERROR_ABORT); \
|
||||||
|
DOMEXCEPTION(AbortError, NS_ERROR_DOM_MEDIA_ABORT_ERR); \
|
||||||
|
DOMEXCEPTION(RangeError, NS_ERROR_DOM_MEDIA_RANGE_ERR); \
|
||||||
|
DOMEXCEPTION(NotAllowedError, NS_ERROR_DOM_MEDIA_NOT_ALLOWED_ERR); \
|
||||||
|
DOMEXCEPTION(NotSupportedError, NS_ERROR_DOM_MEDIA_NOT_SUPPORTED_ERR); \
|
||||||
|
DOMEXCEPTION(TypeError, NS_ERROR_DOM_MEDIA_TYPE_ERR);
|
||||||
|
|
||||||
|
void MediaResult::ThrowTo(ErrorResult& aRv) const {
|
||||||
|
switch (mCode) {
|
||||||
|
#define DOMEXCEPTION(name, code) \
|
||||||
|
case code: \
|
||||||
|
aRv.Throw##name(mMessage); \
|
||||||
|
break;
|
||||||
|
#include "mozilla/dom/DOMExceptionNames.h"
|
||||||
|
EXTENDED_EXCEPTIONS
|
||||||
|
default:
|
||||||
|
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
||||||
|
MOZ_CRASH_UNSAFE_PRINTF("Unhandled result 0x%08x",
|
||||||
|
static_cast<uint32_t>(mCode));
|
||||||
|
#endif
|
||||||
|
aRv.ThrowUnknownError(mMessage);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef DOMEXCEPTION
|
||||||
|
}
|
||||||
|
|
||||||
|
void MediaResult::RejectTo(dom::Promise* aPromise) const {
|
||||||
|
switch (mCode) {
|
||||||
|
#define DOMEXCEPTION(name, code) \
|
||||||
|
case code: \
|
||||||
|
aPromise->MaybeRejectWith##name(mMessage); \
|
||||||
|
break;
|
||||||
|
#include "mozilla/dom/DOMExceptionNames.h"
|
||||||
|
EXTENDED_EXCEPTIONS
|
||||||
|
default:
|
||||||
|
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
||||||
|
MOZ_CRASH_UNSAFE_PRINTF("Unhandled result 0x%08x",
|
||||||
|
static_cast<uint32_t>(mCode));
|
||||||
|
#endif
|
||||||
|
aPromise->MaybeRejectWithUnknownError(mMessage);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef DOMEXCEPTION
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace mozilla
|
|
@ -19,7 +19,12 @@
|
||||||
// MediaResult const references is recommended.
|
// MediaResult const references is recommended.
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
|
namespace dom {
|
||||||
|
class Promise;
|
||||||
|
}
|
||||||
|
|
||||||
class CDMProxy;
|
class CDMProxy;
|
||||||
|
class ErrorResult;
|
||||||
|
|
||||||
class MediaResult {
|
class MediaResult {
|
||||||
public:
|
public:
|
||||||
|
@ -63,6 +68,9 @@ class MediaResult {
|
||||||
|
|
||||||
CDMProxy* GetCDMProxy() const { return mCDMProxy; }
|
CDMProxy* GetCDMProxy() const { return mCDMProxy; }
|
||||||
|
|
||||||
|
void ThrowTo(ErrorResult& aRv) const;
|
||||||
|
void RejectTo(dom::Promise* aPromise) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nsresult mCode;
|
nsresult mCode;
|
||||||
nsCString mMessage;
|
nsCString mMessage;
|
||||||
|
|
|
@ -297,6 +297,7 @@ UNIFIED_SOURCES += [
|
||||||
"MediaPlaybackDelayPolicy.cpp",
|
"MediaPlaybackDelayPolicy.cpp",
|
||||||
"MediaRecorder.cpp",
|
"MediaRecorder.cpp",
|
||||||
"MediaResource.cpp",
|
"MediaResource.cpp",
|
||||||
|
"MediaResult.cpp",
|
||||||
"MediaShutdownManager.cpp",
|
"MediaShutdownManager.cpp",
|
||||||
"MediaStreamError.cpp",
|
"MediaStreamError.cpp",
|
||||||
"MediaStreamTrack.cpp",
|
"MediaStreamTrack.cpp",
|
||||||
|
|
|
@ -1187,6 +1187,8 @@ with modules["DOM_MEDIA"]:
|
||||||
errors["NS_ERROR_DOM_MEDIA_EXTERNAL_ENGINE_NOT_SUPPORTED_ERR"] = FAILURE(102)
|
errors["NS_ERROR_DOM_MEDIA_EXTERNAL_ENGINE_NOT_SUPPORTED_ERR"] = FAILURE(102)
|
||||||
errors["NS_ERROR_DOM_MEDIA_CDM_PROXY_NOT_SUPPORTED_ERR"] = FAILURE(103)
|
errors["NS_ERROR_DOM_MEDIA_CDM_PROXY_NOT_SUPPORTED_ERR"] = FAILURE(103)
|
||||||
errors["NS_ERROR_DOM_MEDIA_DENIED_IN_NON_UTILITY"] = FAILURE(104)
|
errors["NS_ERROR_DOM_MEDIA_DENIED_IN_NON_UTILITY"] = FAILURE(104)
|
||||||
|
errors["NS_ERROR_DOM_MEDIA_RANGE_ERR"] = FAILURE(105)
|
||||||
|
errors["NS_ERROR_DOM_MEDIA_TYPE_ERR"] = FAILURE(106)
|
||||||
|
|
||||||
# =======================================================================
|
# =======================================================================
|
||||||
# 42: NS_ERROR_MODULE_URL_CLASSIFIER
|
# 42: NS_ERROR_MODULE_URL_CLASSIFIER
|
||||||
|
|
Загрузка…
Ссылка в новой задаче