Bug 1728955: part 3) Add logging to `nsBaseClipboard`. r=masayuki
[gecko.git] / dom / base / nsIScriptGlobalObject.h
blob37bd59af148fb17aef319a64880d6f71f15cc24d
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 {
19 namespace dom {
20 struct ErrorEventInit;
21 } // namespace dom
22 } // namespace mozilla
24 // A helper function for nsIScriptGlobalObject implementations to use
25 // when handling a script error. Generally called by the global when a context
26 // notifies it of an error via nsIScriptGlobalObject::HandleScriptError.
27 // Returns true if HandleDOMEvent was actually called, in which case
28 // aStatus will be filled in with the status.
29 bool NS_HandleScriptError(nsIScriptGlobalObject* aScriptGlobal,
30 const mozilla::dom::ErrorEventInit& aErrorEvent,
31 nsEventStatus* aStatus);
33 // Must be kept in sync with xpcom/rust/xpcom/src/interfaces/nonidl.rs
34 #define NS_ISCRIPTGLOBALOBJECT_IID \
35 { \
36 0x876f83bd, 0x6314, 0x460a, { \
37 0xa0, 0x45, 0x1c, 0x8f, 0x46, 0x2f, 0xb8, 0xe1 \
38 } \
41 /**
42 * The global object which keeps a script context for each supported script
43 * language. This often used to store per-window global state.
44 * This is a heavyweight interface implemented only by DOM globals, and
45 * it might go away some time in the future.
48 class nsIScriptGlobalObject : public nsIGlobalObject {
49 public:
50 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECT_IID)
52 /**
53 * Ensure that the script global object is initialized for working with the
54 * specified script language ID. This will set up the nsIScriptContext
55 * and 'script global' for that language, allowing these to be fetched
56 * and manipulated.
57 * @return NS_OK if successful; error conditions include that the language
58 * has not been registered, as well as 'normal' errors, such as
59 * out-of-memory
61 virtual nsresult EnsureScriptEnvironment() = 0;
62 /**
63 * Get a script context (WITHOUT added reference) for the specified language.
65 virtual nsIScriptContext* GetScriptContext() = 0;
67 nsIScriptContext* GetContext() { return GetScriptContext(); }
69 /**
70 * Handle a script error. Generally called by a script context.
72 bool HandleScriptError(const mozilla::dom::ErrorEventInit& aErrorEventInit,
73 nsEventStatus* aEventStatus) {
74 return NS_HandleScriptError(this, aErrorEventInit, aEventStatus);
77 virtual bool IsBlackForCC(bool aTracingNeeded = true) { return false; }
79 protected:
80 virtual ~nsIScriptGlobalObject() = default;
83 NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptGlobalObject, NS_ISCRIPTGLOBALOBJECT_IID)
85 #endif