dom/base/nsIScriptGlobalObject.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set ts=2 sw=2 et 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
    30 NS_HandleScriptError(nsIScriptGlobalObject *aScriptGlobal,
    31                      const mozilla::dom::ErrorEventInit &aErrorEvent,
    32                      nsEventStatus *aStatus);
    35 #define NS_ISCRIPTGLOBALOBJECT_IID \
    36 { 0x876f83bd, 0x6314, 0x460a, \
    37   { 0xa0, 0x45, 0x1c, 0x8f, 0x46, 0x2f, 0xb8, 0xe1 } }
    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  */
    46 class nsIScriptGlobalObject : public nsIGlobalObject
    47 {
    48 public:
    49   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECT_IID)
    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;
    66   nsIScriptContext* GetContext() {
    67     return GetScriptContext();
    68   }
    70   /**
    71    * Handle a script error.  Generally called by a script context.
    72    */
    73   virtual nsresult HandleScriptError(
    74                      const mozilla::dom::ErrorEventInit &aErrorEventInit,
    75                      nsEventStatus *aEventStatus) {
    76     NS_ENSURE_STATE(NS_HandleScriptError(this, aErrorEventInit, aEventStatus));
    77     return NS_OK;
    78   }
    80   virtual bool IsBlackForCC(bool aTracingNeeded = true) { return false; }
    81 };
    83 NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptGlobalObject,
    84                               NS_ISCRIPTGLOBALOBJECT_IID)
    86 #endif

mercurial