Exceptions.h (2349B)
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 14 #include "jsapi.h" 15 #include "jspubtd.h" 16 #include "nsString.h" 17 18 class nsIStackFrame; 19 class nsPIDOMWindowInner; 20 template <class T> 21 struct already_AddRefed; 22 23 namespace mozilla::dom { 24 25 class Exception; 26 27 // If we're throwing a DOMException and message is empty, the default 28 // message for the nsresult in question will be used. 29 bool Throw(JSContext* cx, nsresult rv, const nsACString& message = ""_ns); 30 31 // Create, throw and report an exception to a given window. 32 void ThrowAndReport(nsPIDOMWindowInner* aWindow, nsresult aRv); 33 34 // Both signatures of ThrowExceptionObject guarantee that an exception is set on 35 // aCx before they return. 36 void ThrowExceptionObject(JSContext* aCx, Exception* aException); 37 38 // Create an exception object for the given nsresult and message. If we're 39 // throwing a DOMException and aMessage is empty, the default message for the 40 // nsresult in question will be used. 41 // 42 // This never returns null. 43 already_AddRefed<Exception> CreateException(nsresult aRv, 44 const nsACString& aMessage = ""_ns); 45 46 // aMaxDepth can be used to define a maximal depth for the stack trace. If the 47 // value is -1, a default maximal depth will be selected. Will return null if 48 // there is no JS stack right now. 49 already_AddRefed<nsIStackFrame> GetCurrentJSStack(int32_t aMaxDepth = -1); 50 51 // Internal stuff not intended to be widely used. 52 namespace exceptions { 53 54 already_AddRefed<nsIStackFrame> CreateStack(JSContext* aCx, 55 JS::StackCapture&& aCaptureMode); 56 57 // Like the above, but creates a JSStackFrame wrapper for an existing 58 // JS::SavedFrame object, passed as aStack. 59 already_AddRefed<nsIStackFrame> CreateStack(JSContext* aCx, 60 JS::Handle<JSObject*> aStack); 61 62 } // namespace exceptions 63 } // namespace mozilla::dom 64 65 #endif