tor-browser

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

ClonedErrorHolder.h (3793B)


      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 #ifndef mozilla_dom_ClonedErrorHolder_h
      8 #define mozilla_dom_ClonedErrorHolder_h
      9 
     10 #include "js/ColumnNumber.h"  // JS::ColumnNumberOneOrigin
     11 #include "js/ErrorReport.h"
     12 #include "js/TypeDecls.h"
     13 #include "mozilla/dom/BindingDeclarations.h"
     14 #include "mozilla/dom/NonRefcountedDOMObject.h"
     15 #include "mozilla/dom/StructuredCloneHolder.h"
     16 #include "nsISupportsImpl.h"
     17 
     18 class nsIGlobalObject;
     19 class nsQueryActorChild;
     20 
     21 namespace mozilla {
     22 class ErrorResult;
     23 
     24 namespace dom {
     25 
     26 class ClonedErrorHolder final : public NonRefcountedDOMObject {
     27 public:
     28  static UniquePtr<ClonedErrorHolder> Constructor(const GlobalObject& aGlobal,
     29                                                  JS::Handle<JSObject*> aError,
     30                                                  ErrorResult& aRv);
     31 
     32  static UniquePtr<ClonedErrorHolder> Create(JSContext* aCx,
     33                                             JS::Handle<JSObject*> aError,
     34                                             ErrorResult& aRv);
     35 
     36  enum class Type : uint8_t {
     37    Uninitialized,
     38    JSError,
     39    Exception,
     40    DOMException,
     41    Max_,
     42  };
     43 
     44  bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto,
     45                  JS::MutableHandle<JSObject*> aReflector);
     46 
     47  bool WriteStructuredClone(JSContext* aCx, JSStructuredCloneWriter* aWriter,
     48                            StructuredCloneHolder* aHolder);
     49 
     50  // Reads the structured clone data for the ClonedErrorHolder and returns the
     51  // wrapped object (either a JS Error or an Exception/DOMException object)
     52  // directly. Never returns an actual ClonedErrorHolder object.
     53  static JSObject* ReadStructuredClone(JSContext* aCx,
     54                                       JSStructuredCloneReader* aReader,
     55                                       StructuredCloneHolder* aHolder);
     56 
     57 private:
     58  ClonedErrorHolder();
     59 
     60  void Init(JSContext* aCx, JS::Handle<JSObject*> aError, ErrorResult& aRv);
     61 
     62  bool Init(JSContext* aCx, JSStructuredCloneReader* aReader);
     63 
     64  // Creates a new JS Error or Exception/DOMException object based on the
     65  // values stored in the holder. Returns false and sets an exception on aCx
     66  // if it fails.
     67  bool ToErrorValue(JSContext* aCx, JS::MutableHandle<JS::Value> aResult);
     68 
     69  class Holder final : public StructuredCloneHolder {
     70   public:
     71    using StructuredCloneHolder::StructuredCloneHolder;
     72 
     73    bool ReadStructuredCloneInternal(JSContext* aCx,
     74                                     JSStructuredCloneReader* aReader);
     75  };
     76 
     77  // Only a subset of the following fields are used, depending on the mType of
     78  // the error stored:
     79  nsCString mName;        // Exception, DOMException
     80  nsCString mMessage;     // JSError, Exception, DOMException
     81  nsCString mFilename;    // JSError only
     82  nsCString mSourceLine;  // JSError only
     83 
     84  uint32_t mLineNumber = 0;           // JSError only
     85  JS::ColumnNumberOneOrigin mColumn;  // JSError only
     86  uint32_t mTokenOffset = 0;          // JSError only
     87  uint32_t mErrorNumber = 0;          // JSError only
     88 
     89  Type mType = Type::Uninitialized;
     90 
     91  uint16_t mCode = 0;                 // DOMException only
     92  JSExnType mExnType = JSExnType(0);  // JSError only
     93  nsresult mResult = NS_OK;           // Exception, DOMException
     94 
     95  // JSError, Exception, DOMException
     96  Holder mStack{Holder::CloningSupported, Holder::TransferringNotSupported,
     97                Holder::StructuredCloneScope::DifferentProcess};
     98 };
     99 
    100 }  // namespace dom
    101 }  // namespace mozilla
    102 
    103 #endif  // !defined(mozilla_dom_ClonedErrorHolder_h)