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