dom/base/nsDOMJSUtils.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef nsDOMJSUtils_h__
     6 #define nsDOMJSUtils_h__
     8 #include "nsIScriptContext.h"
     9 #include "jsapi.h"
    11 class nsIJSArgArray;
    13 // seems like overkill for just this 1 function - but let's see what else
    14 // falls out first.
    15 inline nsIScriptContext *
    16 GetScriptContextFromJSContext(JSContext *cx)
    17 {
    18   if (!(JS::ContextOptionsRef(cx).privateIsNSISupports())) {
    19     return nullptr;
    20   }
    22   nsCOMPtr<nsIScriptContext> scx =
    23     do_QueryInterface(static_cast<nsISupports *>
    24                                  (::JS_GetContextPrivate(cx)));
    26   // This will return a pointer to something that's about to be
    27   // released, but that's ok here.
    28   return scx;
    29 }
    31 JSObject* GetDefaultScopeFromJSContext(JSContext *cx);
    33 // A factory function for turning a JS::Value argv into an nsIArray
    34 // but also supports an effecient way of extracting the original argv.
    35 // Bug 312003 describes why this must be "void *", but argv will be cast to
    36 // JS::Value* and the args are found at:
    37 //    ((JS::Value*)aArgv)[0], ..., ((JS::Value*)aArgv)[aArgc - 1]
    38 // The resulting object will take a copy of the array, and ensure each
    39 // element is rooted.
    40 // Optionally, aArgv may be nullptr, in which case the array is allocated and
    41 // rooted, but all items remain nullptr.  This presumably means the caller
    42 // will then QI us for nsIJSArgArray, and set our array elements.
    43 nsresult NS_CreateJSArgv(JSContext *aContext, uint32_t aArgc, void *aArgv,
    44                          nsIJSArgArray **aArray);
    46 #endif // nsDOMJSUtils_h__

mercurial