Line data Source code
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/. */
6 :
7 : #ifndef mozilla_dom_Exceptions_h__
8 : #define mozilla_dom_Exceptions_h__
9 :
10 : // DOM exception throwing machinery (for both main thread and workers).
11 :
12 : #include <stdint.h>
13 : #include "jspubtd.h"
14 : #include "nsIException.h"
15 : #include "nsStringGlue.h"
16 : #include "jsapi.h"
17 :
18 : class nsIStackFrame;
19 : class nsPIDOMWindowInner;
20 : template <class T>
21 : struct already_AddRefed;
22 :
23 : namespace mozilla {
24 : namespace dom {
25 :
26 : class Exception;
27 :
28 : // If we're throwing a DOMException and message is empty, the default
29 : // message for the nsresult in question will be used.
30 : bool
31 1 : Throw(JSContext* cx, nsresult rv, const nsACString& message = EmptyCString());
32 :
33 : // Create, throw and report an exception to a given window.
34 : void
35 : ThrowAndReport(nsPIDOMWindowInner* aWindow, nsresult aRv);
36 :
37 : // Both signatures of ThrowExceptionObject guarantee that an exception is set on
38 : // aCx before they return.
39 : void
40 : ThrowExceptionObject(JSContext* aCx, Exception* aException);
41 : void
42 : ThrowExceptionObject(JSContext* aCx, nsIException* aException);
43 :
44 : // Create an exception object for the given nsresult and message. If we're
45 : // throwing a DOMException and aMessage is empty, the default message for the
46 : // nsresult in question will be used.
47 : //
48 : // This never returns null.
49 : already_AddRefed<Exception>
50 0 : CreateException(nsresult aRv, const nsACString& aMessage = EmptyCString());
51 :
52 : // aMaxDepth can be used to define a maximal depth for the stack trace. If the
53 : // value is -1, a default maximal depth will be selected. Will return null if
54 : // there is no JS stack right now.
55 : already_AddRefed<nsIStackFrame>
56 : GetCurrentJSStack(int32_t aMaxDepth = -1);
57 :
58 : // Internal stuff not intended to be widely used.
59 : namespace exceptions {
60 :
61 : already_AddRefed<nsIStackFrame>
62 : CreateStack(JSContext* aCx, JS::StackCapture&& aCaptureMode);
63 :
64 : } // namespace exceptions
65 : } // namespace dom
66 : } // namespace mozilla
67 :
68 : #endif
|