tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MediaResult.cpp (2088B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "MediaResult.h"
      8 
      9 #include "mozilla/Assertions.h"
     10 #include "mozilla/ErrorResult.h"
     11 #include "mozilla/dom/Promise.h"
     12 
     13 namespace mozilla {
     14 
     15 #define EXTENDED_EXCEPTIONS                                              \
     16  DOMEXCEPTION(AbortError, NS_ERROR_ABORT);                              \
     17  DOMEXCEPTION(AbortError, NS_ERROR_DOM_MEDIA_ABORT_ERR);                \
     18  DOMEXCEPTION(RangeError, NS_ERROR_DOM_MEDIA_RANGE_ERR);                \
     19  DOMEXCEPTION(NotAllowedError, NS_ERROR_DOM_MEDIA_NOT_ALLOWED_ERR);     \
     20  DOMEXCEPTION(NotSupportedError, NS_ERROR_DOM_MEDIA_NOT_SUPPORTED_ERR); \
     21  DOMEXCEPTION(TypeError, NS_ERROR_DOM_MEDIA_TYPE_ERR);
     22 
     23 void MediaResult::ThrowTo(ErrorResult& aRv) const {
     24  switch (mCode) {
     25 #define DOMEXCEPTION(name, code) \
     26  case code:                     \
     27    aRv.Throw##name(mMessage);   \
     28    break;
     29 #include "mozilla/dom/DOMExceptionNames.h"
     30    EXTENDED_EXCEPTIONS
     31    default:
     32 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
     33      MOZ_CRASH_UNSAFE_PRINTF("Unhandled result 0x%08x",
     34                              static_cast<uint32_t>(mCode));
     35 #endif
     36      aRv.ThrowUnknownError(mMessage);
     37      break;
     38  }
     39 
     40 #undef DOMEXCEPTION
     41 }
     42 
     43 void MediaResult::RejectTo(dom::Promise* aPromise) const {
     44  switch (mCode) {
     45 #define DOMEXCEPTION(name, code)               \
     46  case code:                                   \
     47    aPromise->MaybeRejectWith##name(mMessage); \
     48    break;
     49 #include "mozilla/dom/DOMExceptionNames.h"
     50    EXTENDED_EXCEPTIONS
     51    default:
     52 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
     53      MOZ_CRASH_UNSAFE_PRINTF("Unhandled result 0x%08x",
     54                              static_cast<uint32_t>(mCode));
     55 #endif
     56      aPromise->MaybeRejectWithUnknownError(mMessage);
     57      break;
     58  }
     59 
     60 #undef DOMEXCEPTION
     61 }
     62 
     63 }  // namespace mozilla