1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/nsIScriptGlobalObject.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 sw=2 et tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef nsIScriptGlobalObject_h__ 1.11 +#define nsIScriptGlobalObject_h__ 1.12 + 1.13 +#include "nsISupports.h" 1.14 +#include "nsIGlobalObject.h" 1.15 +#include "js/TypeDecls.h" 1.16 +#include "mozilla/EventForwards.h" 1.17 + 1.18 +class nsIScriptContext; 1.19 +class nsIScriptGlobalObject; 1.20 + 1.21 +namespace mozilla { 1.22 +namespace dom { 1.23 +struct ErrorEventInit; 1.24 +} // namespace dom 1.25 +} // namespace mozilla 1.26 + 1.27 +// A helper function for nsIScriptGlobalObject implementations to use 1.28 +// when handling a script error. Generally called by the global when a context 1.29 +// notifies it of an error via nsIScriptGlobalObject::HandleScriptError. 1.30 +// Returns true if HandleDOMEvent was actually called, in which case 1.31 +// aStatus will be filled in with the status. 1.32 +bool 1.33 +NS_HandleScriptError(nsIScriptGlobalObject *aScriptGlobal, 1.34 + const mozilla::dom::ErrorEventInit &aErrorEvent, 1.35 + nsEventStatus *aStatus); 1.36 + 1.37 + 1.38 +#define NS_ISCRIPTGLOBALOBJECT_IID \ 1.39 +{ 0x876f83bd, 0x6314, 0x460a, \ 1.40 + { 0xa0, 0x45, 0x1c, 0x8f, 0x46, 0x2f, 0xb8, 0xe1 } } 1.41 + 1.42 +/** 1.43 + * The global object which keeps a script context for each supported script 1.44 + * language. This often used to store per-window global state. 1.45 + * This is a heavyweight interface implemented only by DOM globals, and 1.46 + * it might go away some time in the future. 1.47 + */ 1.48 + 1.49 +class nsIScriptGlobalObject : public nsIGlobalObject 1.50 +{ 1.51 +public: 1.52 + NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECT_IID) 1.53 + 1.54 + /** 1.55 + * Ensure that the script global object is initialized for working with the 1.56 + * specified script language ID. This will set up the nsIScriptContext 1.57 + * and 'script global' for that language, allowing these to be fetched 1.58 + * and manipulated. 1.59 + * @return NS_OK if successful; error conditions include that the language 1.60 + * has not been registered, as well as 'normal' errors, such as 1.61 + * out-of-memory 1.62 + */ 1.63 + virtual nsresult EnsureScriptEnvironment() = 0; 1.64 + /** 1.65 + * Get a script context (WITHOUT added reference) for the specified language. 1.66 + */ 1.67 + virtual nsIScriptContext *GetScriptContext() = 0; 1.68 + 1.69 + nsIScriptContext* GetContext() { 1.70 + return GetScriptContext(); 1.71 + } 1.72 + 1.73 + /** 1.74 + * Handle a script error. Generally called by a script context. 1.75 + */ 1.76 + virtual nsresult HandleScriptError( 1.77 + const mozilla::dom::ErrorEventInit &aErrorEventInit, 1.78 + nsEventStatus *aEventStatus) { 1.79 + NS_ENSURE_STATE(NS_HandleScriptError(this, aErrorEventInit, aEventStatus)); 1.80 + return NS_OK; 1.81 + } 1.82 + 1.83 + virtual bool IsBlackForCC(bool aTracingNeeded = true) { return false; } 1.84 +}; 1.85 + 1.86 +NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptGlobalObject, 1.87 + NS_ISCRIPTGLOBALOBJECT_IID) 1.88 + 1.89 +#endif