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 nsIScriptGlobalObject_h__
8 #define nsIScriptGlobalObject_h__
10 #include "nsISupports.h"
11 #include "nsIGlobalObject.h"
12 #include "js/TypeDecls.h"
13 #include "mozilla/EventForwards.h"
15 class nsIScriptContext
;
16 class nsIScriptGlobalObject
;
18 namespace mozilla::dom
{
19 struct ErrorEventInit
;
20 } // namespace mozilla::dom
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
);
32 // Must be kept in sync with xpcom/rust/xpcom/src/interfaces/nonidl.rs
33 #define NS_ISCRIPTGLOBALOBJECT_IID \
35 0x876f83bd, 0x6314, 0x460a, { \
36 0xa0, 0x45, 0x1c, 0x8f, 0x46, 0x2f, 0xb8, 0xe1 \
41 * The global object which keeps a script context for each supported script
42 * language. This often used to store per-window global state.
43 * This is a heavyweight interface implemented only by DOM globals, and
44 * it might go away some time in the future.
47 class nsIScriptGlobalObject
: public nsIGlobalObject
{
49 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECT_IID
)
52 * Ensure that the script global object is initialized for working with the
53 * specified script language ID. This will set up the nsIScriptContext
54 * and 'script global' for that language, allowing these to be fetched
56 * @return NS_OK if successful; error conditions include that the language
57 * has not been registered, as well as 'normal' errors, such as
60 virtual nsresult
EnsureScriptEnvironment() = 0;
62 * Get a script context (WITHOUT added reference) for the specified language.
64 virtual nsIScriptContext
* GetScriptContext() = 0;
66 nsIScriptContext
* GetContext() { return GetScriptContext(); }
69 * Handle a script error. Generally called by a script context.
71 bool HandleScriptError(const mozilla::dom::ErrorEventInit
& aErrorEventInit
,
72 nsEventStatus
* aEventStatus
) {
73 return NS_HandleScriptError(this, aErrorEventInit
, aEventStatus
);
76 virtual bool IsBlackForCC(bool aTracingNeeded
= true) { return false; }
79 virtual ~nsIScriptGlobalObject() = default;
82 NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptGlobalObject
, NS_ISCRIPTGLOBALOBJECT_IID
)