Thu, 12 Apr 2007 11:34:54 -0700
changeset 499 2b0a29c225791caae1a7caf53aa0e4a56dcf644c
parent 1 9b2a99adc05e53cd4010de512f50118594756650
child 3233 ab58bdbde9e03330d3a406d8b95aa3877152cf36
permissions -rw-r--r--
upgrading libpng to 1.2.16. patch from andrew smith. bug 373249. r=me sr=tor

#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__