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 "nsIScriptContext.h"
|
2013-10-10 15:22:35 -07:00
|
|
|
#include "jsapi.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
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)
|
|
|
|
{
|
2013-10-28 04:51:05 -07:00
|
|
|
if (!(JS::ContextOptionsRef(cx).privateIsNSISupports())) {
|
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;
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:06:55 -07:00
|
|
|
JSObject* GetDefaultScopeFromJSContext(JSContext *cx);
|
|
|
|
|
2013-04-11 15:52:10 -07:00
|
|
|
// A factory function for turning a JS::Value argv into an nsIArray
|
2007-03-22 10:30:00 -07:00
|
|
|
// 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
|
2013-04-11 15:52:10 -07:00
|
|
|
// JS::Value* and the args are found at:
|
|
|
|
// ((JS::Value*)aArgv)[0], ..., ((JS::Value*)aArgv)[aArgc - 1]
|
2007-03-22 10:30:00 -07:00
|
|
|
// The resulting object will take a copy of the array, and ensure each
|
|
|
|
// element is rooted.
|
2013-10-28 07:04:12 -07:00
|
|
|
// Optionally, aArgv may be nullptr, in which case the array is allocated and
|
|
|
|
// rooted, but all items remain nullptr. 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__
|