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 nsIScriptGlobalObject_h__
8 : #define nsIScriptGlobalObject_h__
9 :
10 : #include "nsISupports.h"
11 : #include "nsIGlobalObject.h"
12 : #include "js/TypeDecls.h"
13 : #include "mozilla/EventForwards.h"
14 :
15 : class nsIScriptContext;
16 : class nsIScriptGlobalObject;
17 :
18 : namespace mozilla {
19 : namespace dom {
20 : struct ErrorEventInit;
21 : } // namespace dom
22 : } // namespace mozilla
23 :
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
30 : NS_HandleScriptError(nsIScriptGlobalObject *aScriptGlobal,
31 : const mozilla::dom::ErrorEventInit &aErrorEvent,
32 : nsEventStatus *aStatus);
33 :
34 :
35 : #define NS_ISCRIPTGLOBALOBJECT_IID \
36 : { 0x876f83bd, 0x6314, 0x460a, \
37 : { 0xa0, 0x45, 0x1c, 0x8f, 0x46, 0x2f, 0xb8, 0xe1 } }
38 :
39 : /**
40 : * The global object which keeps a script context for each supported script
41 : * language. This often used to store per-window global state.
42 : * This is a heavyweight interface implemented only by DOM globals, and
43 : * it might go away some time in the future.
44 : */
45 :
46 12 : class nsIScriptGlobalObject : public nsIGlobalObject
47 : {
48 : public:
49 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECT_IID)
50 :
51 : /**
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
55 : * and manipulated.
56 : * @return NS_OK if successful; error conditions include that the language
57 : * has not been registered, as well as 'normal' errors, such as
58 : * out-of-memory
59 : */
60 : virtual nsresult EnsureScriptEnvironment() = 0;
61 : /**
62 : * Get a script context (WITHOUT added reference) for the specified language.
63 : */
64 : virtual nsIScriptContext *GetScriptContext() = 0;
65 :
66 0 : nsIScriptContext* GetContext() {
67 0 : return GetScriptContext();
68 : }
69 :
70 : /**
71 : * Handle a script error. Generally called by a script context.
72 : */
73 0 : virtual nsresult HandleScriptError(
74 : const mozilla::dom::ErrorEventInit &aErrorEventInit,
75 : nsEventStatus *aEventStatus) {
76 0 : NS_ENSURE_STATE(NS_HandleScriptError(this, aErrorEventInit, aEventStatus));
77 0 : return NS_OK;
78 : }
79 :
80 0 : virtual bool IsBlackForCC(bool aTracingNeeded = true) { return false; }
81 :
82 : protected:
83 0 : virtual ~nsIScriptGlobalObject() {}
84 : };
85 :
86 : NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptGlobalObject,
87 : NS_ISCRIPTGLOBALOBJECT_IID)
88 :
89 : #endif
|