Backed out changeset 5238c09bf764 (bug 1911562) for causing android no-fis wpt failur...
[gecko.git] / dom / bindings / Exceptions.h
blob19084aee2f1e28bdbf94ef08e60b38dd561ecc8e
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/. */
7 #ifndef mozilla_dom_Exceptions_h__
8 #define mozilla_dom_Exceptions_h__
10 // DOM exception throwing machinery (for both main thread and workers).
12 #include <stdint.h>
13 #include "jspubtd.h"
14 #include "nsString.h"
15 #include "jsapi.h"
17 class nsIStackFrame;
18 class nsPIDOMWindowInner;
19 template <class T>
20 struct already_AddRefed;
22 namespace mozilla::dom {
24 class Exception;
26 // If we're throwing a DOMException and message is empty, the default
27 // message for the nsresult in question will be used.
28 bool Throw(JSContext* cx, nsresult rv, const nsACString& message = ""_ns);
30 // Create, throw and report an exception to a given window.
31 void ThrowAndReport(nsPIDOMWindowInner* aWindow, nsresult aRv);
33 // Both signatures of ThrowExceptionObject guarantee that an exception is set on
34 // aCx before they return.
35 void ThrowExceptionObject(JSContext* aCx, Exception* aException);
37 // Create an exception object for the given nsresult and message. If we're
38 // throwing a DOMException and aMessage is empty, the default message for the
39 // nsresult in question will be used.
41 // This never returns null.
42 already_AddRefed<Exception> CreateException(nsresult aRv,
43 const nsACString& aMessage = ""_ns);
45 // aMaxDepth can be used to define a maximal depth for the stack trace. If the
46 // value is -1, a default maximal depth will be selected. Will return null if
47 // there is no JS stack right now.
48 already_AddRefed<nsIStackFrame> GetCurrentJSStack(int32_t aMaxDepth = -1);
50 // Internal stuff not intended to be widely used.
51 namespace exceptions {
53 already_AddRefed<nsIStackFrame> CreateStack(JSContext* aCx,
54 JS::StackCapture&& aCaptureMode);
56 // Like the above, but creates a JSStackFrame wrapper for an existing
57 // JS::SavedFrame object, passed as aStack.
58 already_AddRefed<nsIStackFrame> CreateStack(JSContext* aCx,
59 JS::Handle<JSObject*> aStack);
61 } // namespace exceptions
62 } // namespace mozilla::dom
64 #endif