Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / dom / base / nsDOMJSUtils.h
blob3d1d1ab5a6277c03fd0dffbfb2db0b5101f99b18
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef nsDOMJSUtils_h__
6 #define nsDOMJSUtils_h__
8 #include "nsIScriptContext.h"
9 #include "jsapi.h"
11 class nsIJSArgArray;
13 // seems like overkill for just this 1 function - but let's see what else
14 // falls out first.
15 inline nsIScriptContext *
16 GetScriptContextFromJSContext(JSContext *cx)
18 if (!(JS::ContextOptionsRef(cx).privateIsNSISupports())) {
19 return nullptr;
22 nsCOMPtr<nsIScriptContext> scx =
23 do_QueryInterface(static_cast<nsISupports *>
24 (::JS_GetContextPrivate(cx)));
26 // This will return a pointer to something that's about to be
27 // released, but that's ok here.
28 return scx;
31 JSObject* GetDefaultScopeFromJSContext(JSContext *cx);
33 // A factory function for turning a JS::Value argv into an nsIArray
34 // but also supports an effecient way of extracting the original argv.
35 // Bug 312003 describes why this must be "void *", but argv will be cast to
36 // JS::Value* and the args are found at:
37 // ((JS::Value*)aArgv)[0], ..., ((JS::Value*)aArgv)[aArgc - 1]
38 // The resulting object will take a copy of the array, and ensure each
39 // element is rooted.
40 // Optionally, aArgv may be nullptr, in which case the array is allocated and
41 // rooted, but all items remain nullptr. This presumably means the caller
42 // will then QI us for nsIJSArgArray, and set our array elements.
43 nsresult NS_CreateJSArgv(JSContext *aContext, uint32_t aArgc, void *aArgv,
44 nsIJSArgArray **aArray);
46 #endif // nsDOMJSUtils_h__