2 #ifndef nsDOMJSUtils_h__
3 #define nsDOMJSUtils_h__
6 #include "nsIScriptContext.h"
8 // seems like overkill for just this 1 function - but let's see what else
10 inline nsIScriptContext
*
11 GetScriptContextFromJSContext(JSContext
*cx
)
13 if (!(::JS_GetOptions(cx
) & JSOPTION_PRIVATE_IS_NSISUPPORTS
)) {
17 nsCOMPtr
<nsIScriptContext
> scx
=
18 do_QueryInterface(static_cast<nsISupports
*>
19 (::JS_GetContextPrivate(cx
)));
21 // This will return a pointer to something that's about to be
22 // released, but that's ok here.
26 inline nsIScriptContextPrincipal
*
27 GetScriptContextPrincipalFromJSContext(JSContext
*cx
)
29 if (!(::JS_GetOptions(cx
) & JSOPTION_PRIVATE_IS_NSISUPPORTS
)) {
33 nsCOMPtr
<nsIScriptContextPrincipal
> scx
=
34 do_QueryInterface(static_cast<nsISupports
*>
35 (::JS_GetContextPrivate(cx
)));
37 // This will return a pointer to something that's about to be
38 // released, but that's ok here.
42 // A factory function for turning a jsval argv into an nsIArray
43 // but also supports an effecient way of extracting the original argv.
44 // Bug 312003 describes why this must be "void *", but argv will be cast to
45 // jsval* and the args are found at:
46 // ((jsval*)aArgv)[0], ..., ((jsval*)aArgv)[aArgc - 1]
47 // The resulting object will take a copy of the array, and ensure each
49 // Optionally, aArgv may be NULL, in which case the array is allocated and
50 // rooted, but all items remain NULL. This presumably means the caller will
51 // then QI us for nsIJSArgArray, and set our array elements.
52 nsresult
NS_CreateJSArgv(JSContext
*aContext
, PRUint32 aArgc
, void *aArgv
,
55 #endif // nsDOMJSUtils_h__