From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/ipc/ClonedErrorHolder.h | 104 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 dom/ipc/ClonedErrorHolder.h (limited to 'dom/ipc/ClonedErrorHolder.h') diff --git a/dom/ipc/ClonedErrorHolder.h b/dom/ipc/ClonedErrorHolder.h new file mode 100644 index 0000000000..862b43c78b --- /dev/null +++ b/dom/ipc/ClonedErrorHolder.h @@ -0,0 +1,104 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_dom_ClonedErrorHolder_h +#define mozilla_dom_ClonedErrorHolder_h + +#include "mozilla/dom/NonRefcountedDOMObject.h" +#include "nsISupportsImpl.h" +#include "js/ColumnNumber.h" // JS::ColumnNumberOneOrigin +#include "js/ErrorReport.h" +#include "js/TypeDecls.h" +#include "mozilla/dom/BindingDeclarations.h" +#include "mozilla/dom/StructuredCloneHolder.h" +#include "mozilla/Attributes.h" + +class nsIGlobalObject; +class nsQueryActorChild; + +namespace mozilla { +class ErrorResult; + +namespace dom { + +class ClonedErrorHolder final : public NonRefcountedDOMObject { + public: + static UniquePtr Constructor(const GlobalObject& aGlobal, + JS::Handle aError, + ErrorResult& aRv); + + static UniquePtr Create(JSContext* aCx, + JS::Handle aError, + ErrorResult& aRv); + + enum class Type : uint8_t { + Uninitialized, + JSError, + Exception, + DOMException, + Max_, + }; + + bool WrapObject(JSContext* aCx, JS::Handle aGivenProto, + JS::MutableHandle aReflector); + + bool WriteStructuredClone(JSContext* aCx, JSStructuredCloneWriter* aWriter, + StructuredCloneHolder* aHolder); + + // Reads the structured clone data for the ClonedErrorHolder and returns the + // wrapped object (either a JS Error or an Exception/DOMException object) + // directly. Never returns an actual ClonedErrorHolder object. + static JSObject* ReadStructuredClone(JSContext* aCx, + JSStructuredCloneReader* aReader, + StructuredCloneHolder* aHolder); + + private: + ClonedErrorHolder(); + + void Init(JSContext* aCx, JS::Handle aError, ErrorResult& aRv); + + bool Init(JSContext* aCx, JSStructuredCloneReader* aReader); + + // Creates a new JS Error or Exception/DOMException object based on the + // values stored in the holder. Returns false and sets an exception on aCx + // if it fails. + bool ToErrorValue(JSContext* aCx, JS::MutableHandle aResult); + + class Holder final : public StructuredCloneHolder { + public: + using StructuredCloneHolder::StructuredCloneHolder; + + bool ReadStructuredCloneInternal(JSContext* aCx, + JSStructuredCloneReader* aReader); + }; + + // Only a subset of the following fields are used, depending on the mType of + // the error stored: + nsCString mName; // Exception, DOMException + nsCString mMessage; // JSError, Exception, DOMException + nsCString mFilename; // JSError only + nsCString mSourceLine; // JSError only + + uint32_t mLineNumber = 0; // JSError only + JS::ColumnNumberOneOrigin mColumn; // JSError only + uint32_t mTokenOffset = 0; // JSError only + uint32_t mErrorNumber = 0; // JSError only + + Type mType = Type::Uninitialized; + + uint16_t mCode = 0; // DOMException only + JSExnType mExnType = JSExnType(0); // JSError only + nsresult mResult = NS_OK; // Exception, DOMException + + // JSError, Exception, DOMException + Holder mStack{Holder::CloningSupported, Holder::TransferringNotSupported, + Holder::StructuredCloneScope::DifferentProcess}; +}; + +} // namespace dom +} // namespace mozilla + +#endif // !defined(mozilla_dom_ClonedErrorHolder_h) -- cgit v1.2.3