nsIScriptGlobalObject.h (2905B)
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 nsIScriptGlobalObject_h__ 8 #define nsIScriptGlobalObject_h__ 9 10 #include "js/TypeDecls.h" 11 #include "mozilla/EventForwards.h" 12 #include "nsIGlobalObject.h" 13 #include "nsISupports.h" 14 15 class nsIScriptContext; 16 class nsIScriptGlobalObject; 17 18 namespace mozilla::dom { 19 struct ErrorEventInit; 20 } // namespace mozilla::dom 21 22 // A helper function for nsIScriptGlobalObject implementations to use 23 // when handling a script error. Generally called by the global when a context 24 // notifies it of an error via nsIScriptGlobalObject::HandleScriptError. 25 // Returns true if HandleDOMEvent was actually called, in which case 26 // aStatus will be filled in with the status. 27 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230) 28 MOZ_CAN_RUN_SCRIPT_BOUNDARY bool NS_HandleScriptError( 29 nsIScriptGlobalObject* aScriptGlobal, 30 const mozilla::dom::ErrorEventInit& aErrorEvent, nsEventStatus* aStatus); 31 32 // Must be kept in sync with xpcom/rust/xpcom/src/interfaces/nonidl.rs 33 #define NS_ISCRIPTGLOBALOBJECT_IID \ 34 {0x876f83bd, 0x6314, 0x460a, {0xa0, 0x45, 0x1c, 0x8f, 0x46, 0x2f, 0xb8, 0xe1}} 35 36 /** 37 * The global object which keeps a script context for each supported script 38 * language. This often used to store per-window global state. 39 * This is a heavyweight interface implemented only by DOM globals, and 40 * it might go away some time in the future. 41 */ 42 43 class nsIScriptGlobalObject : public nsIGlobalObject { 44 public: 45 NS_INLINE_DECL_STATIC_IID(NS_ISCRIPTGLOBALOBJECT_IID) 46 47 /** 48 * Ensure that the script global object is initialized for working with the 49 * specified script language ID. This will set up the nsIScriptContext 50 * and 'script global' for that language, allowing these to be fetched 51 * and manipulated. 52 * @return NS_OK if successful; error conditions include that the language 53 * has not been registered, as well as 'normal' errors, such as 54 * out-of-memory 55 */ 56 virtual nsresult EnsureScriptEnvironment() = 0; 57 /** 58 * Get a script context (WITHOUT added reference) for the specified language. 59 */ 60 virtual nsIScriptContext* GetScriptContext() = 0; 61 62 nsIScriptContext* GetContext() { return GetScriptContext(); } 63 64 /** 65 * Handle a script error. Generally called by a script context. 66 */ 67 bool HandleScriptError(const mozilla::dom::ErrorEventInit& aErrorEventInit, 68 nsEventStatus* aEventStatus) { 69 return NS_HandleScriptError(this, aErrorEventInit, aEventStatus); 70 } 71 72 virtual bool IsBlackForCC(bool aTracingNeeded = true) { return false; } 73 74 protected: 75 virtual ~nsIScriptGlobalObject() = default; 76 }; 77 78 #endif