tor-browser

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

WebTransportError.cpp (1422B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      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 "WebTransportError.h"
      8 
      9 namespace mozilla::dom {
     10 
     11 JSObject* WebTransportError::WrapObject(JSContext* aCx,
     12                                        JS::Handle<JSObject*> aGivenProto) {
     13  return WebTransportError_Binding::Wrap(aCx, this, aGivenProto);
     14 }
     15 
     16 /* static */
     17 already_AddRefed<WebTransportError> WebTransportError::Constructor(
     18    const GlobalObject& aGlobal, const WebTransportErrorInit& aInit) {
     19  //  https://w3c.github.io/webtransport/#web-transport-error-constructor1
     20 
     21  // Step 2: Let message be init.message if it exists, and "" otherwise.
     22  nsCString message(""_ns);
     23  if (aInit.mMessage.WasPassed()) {
     24    CopyUTF16toUTF8(aInit.mMessage.Value(), message);
     25  }
     26 
     27  // Step 1: Let error be this.
     28  // Step 3: Set up error with message and "stream".
     29  RefPtr<WebTransportError> error(new WebTransportError(message));
     30 
     31  // Step 4: Set error.[[StreamErrorCode]] to init.streamErrorCode if it exists.
     32  if (aInit.mStreamErrorCode.WasPassed()) {
     33    error->mStreamErrorCode = Nullable(aInit.mStreamErrorCode.Value());
     34  }
     35  return error.forget();
     36 }
     37 
     38 }  // namespace mozilla::dom