2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsDOMJSUtils_h__
|
|
|
|
#define nsDOMJSUtils_h__
|
|
|
|
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
|
2012-03-11 00:53:05 -08:00
|
|
|
class nsIJSArgArray;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// seems like overkill for just this 1 function - but let's see what else
|
|
|
|
// falls out first.
|
|
|
|
inline nsIScriptContext *
|
|
|
|
GetScriptContextFromJSContext(JSContext *cx)
|
|
|
|
{
|
|
|
|
if (!(::JS_GetOptions(cx) & JSOPTION_PRIVATE_IS_NSISUPPORTS)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptContext> scx =
|
2007-07-08 00:08:04 -07:00
|
|
|
do_QueryInterface(static_cast<nsISupports *>
|
|
|
|
(::JS_GetContextPrivate(cx)));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// This will return a pointer to something that's about to be
|
|
|
|
// released, but that's ok here.
|
|
|
|
return scx;
|
|
|
|
}
|
|
|
|
|
2010-05-18 05:28:37 -07:00
|
|
|
inline nsIScriptContextPrincipal*
|
|
|
|
GetScriptContextPrincipalFromJSContext(JSContext *cx)
|
|
|
|
{
|
|
|
|
if (!(::JS_GetOptions(cx) & JSOPTION_PRIVATE_IS_NSISUPPORTS)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-05-18 05:28:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptContextPrincipal> scx =
|
|
|
|
do_QueryInterface(static_cast<nsISupports *>
|
|
|
|
(::JS_GetContextPrivate(cx)));
|
|
|
|
|
|
|
|
// This will return a pointer to something that's about to be
|
|
|
|
// released, but that's ok here.
|
|
|
|
return scx;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// A factory function for turning a jsval argv into an nsIArray
|
|
|
|
// but also supports an effecient way of extracting the original argv.
|
|
|
|
// Bug 312003 describes why this must be "void *", but argv will be cast to
|
|
|
|
// jsval* and the args are found at:
|
|
|
|
// ((jsval*)aArgv)[0], ..., ((jsval*)aArgv)[aArgc - 1]
|
|
|
|
// The resulting object will take a copy of the array, and ensure each
|
|
|
|
// element is rooted.
|
|
|
|
// Optionally, aArgv may be NULL, in which case the array is allocated and
|
|
|
|
// rooted, but all items remain NULL. This presumably means the caller will
|
|
|
|
// then QI us for nsIJSArgArray, and set our array elements.
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult NS_CreateJSArgv(JSContext *aContext, uint32_t aArgc, void *aArgv,
|
2012-03-11 00:53:05 -08:00
|
|
|
nsIJSArgArray **aArray);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#endif // nsDOMJSUtils_h__
|