Fri, 13 Apr 2007 17:29:26 -0700
changeset 528 c303508f074933fdbaa3747811e01f3417627de8
parent 1 9b2a99adc05e53cd4010de512f50118594756650
child 3233 ab58bdbde9e03330d3a406d8b95aa3877152cf36
permissions -rw-r--r--
l10n tinderbox bustage fix b=375828

#ifndef nsDOMJSUtils_h__
#define nsDOMJSUtils_h__

#include "jsapi.h"
#include "nsIScriptContext.h"

// 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)) {
    return nsnull;

  nsCOMPtr<nsIScriptContext> scx =
    do_QueryInterface(NS_STATIC_CAST(nsISupports *,

  // This will return a pointer to something that's about to be
  // released, but that's ok here.
  return scx;

// 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.
nsresult NS_CreateJSArgv(JSContext *aContext, PRUint32 aArgc, void *aArgv,
                         nsIArray **aArray);

#endif // nsDOMJSUtils_h__