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 "nsISupportsImpl.h"
11 #include "js/ColumnNumber.h" // JS::ColumnNumberOneOrigin
12 #include "js/ErrorReport.h"
13 #include "js/TypeDecls.h"
14 #include "mozilla/dom/BindingDeclarations.h"
15 #include "mozilla/dom/StructuredCloneHolder.h"
16 #include "mozilla/Attributes.h"
18 class nsIGlobalObject
;
19 class nsQueryActorChild
;
26 class ClonedErrorHolder final
{
27 NS_INLINE_DECL_REFCOUNTING(ClonedErrorHolder
)
30 static already_AddRefed
<ClonedErrorHolder
> Constructor(
31 const GlobalObject
& aGlobal
, JS::Handle
<JSObject
*> aError
,
34 static already_AddRefed
<ClonedErrorHolder
> Create(
35 JSContext
* aCx
, JS::Handle
<JSObject
*> aError
, ErrorResult
& aRv
);
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
);
60 ~ClonedErrorHolder() = default;
62 void Init(JSContext
* aCx
, JS::Handle
<JSObject
*> aError
, ErrorResult
& aRv
);
64 bool Init(JSContext
* aCx
, JSStructuredCloneReader
* aReader
);
66 // Creates a new JS Error or Exception/DOMException object based on the
67 // values stored in the holder. Returns false and sets an exception on aCx
69 bool ToErrorValue(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aResult
);
71 class Holder final
: public StructuredCloneHolder
{
73 using StructuredCloneHolder::StructuredCloneHolder
;
75 bool ReadStructuredCloneInternal(JSContext
* aCx
,
76 JSStructuredCloneReader
* aReader
);
79 // Only a subset of the following fields are used, depending on the mType of
81 nsCString mName
; // Exception, DOMException
82 nsCString mMessage
; // JSError, Exception, DOMException
83 nsCString mFilename
; // JSError only
84 nsCString mSourceLine
; // JSError only
86 uint32_t mLineNumber
= 0; // JSError only
87 JS::ColumnNumberOneOrigin mColumn
; // JSError only
88 uint32_t mTokenOffset
= 0; // JSError only
89 uint32_t mErrorNumber
= 0; // JSError only
91 Type mType
= Type::Uninitialized
;
93 uint16_t mCode
= 0; // DOMException only
94 JSExnType mExnType
= JSExnType(0); // JSError only
95 nsresult mResult
= NS_OK
; // Exception, DOMException
97 // JSError, Exception, DOMException
98 Holder mStack
{Holder::CloningSupported
, Holder::TransferringNotSupported
,
99 Holder::StructuredCloneScope::DifferentProcess
};
103 } // namespace mozilla
105 #endif // !defined(mozilla_dom_ClonedErrorHolder_h)