michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsDOMJSUtils_h__ michael@0: #define nsDOMJSUtils_h__ michael@0: michael@0: #include "nsIScriptContext.h" michael@0: #include "jsapi.h" michael@0: michael@0: class nsIJSArgArray; michael@0: michael@0: // seems like overkill for just this 1 function - but let's see what else michael@0: // falls out first. michael@0: inline nsIScriptContext * michael@0: GetScriptContextFromJSContext(JSContext *cx) michael@0: { michael@0: if (!(JS::ContextOptionsRef(cx).privateIsNSISupports())) { michael@0: return nullptr; michael@0: } michael@0: michael@0: nsCOMPtr scx = michael@0: do_QueryInterface(static_cast michael@0: (::JS_GetContextPrivate(cx))); michael@0: michael@0: // This will return a pointer to something that's about to be michael@0: // released, but that's ok here. michael@0: return scx; michael@0: } michael@0: michael@0: JSObject* GetDefaultScopeFromJSContext(JSContext *cx); michael@0: michael@0: // A factory function for turning a JS::Value argv into an nsIArray michael@0: // but also supports an effecient way of extracting the original argv. michael@0: // Bug 312003 describes why this must be "void *", but argv will be cast to michael@0: // JS::Value* and the args are found at: michael@0: // ((JS::Value*)aArgv)[0], ..., ((JS::Value*)aArgv)[aArgc - 1] michael@0: // The resulting object will take a copy of the array, and ensure each michael@0: // element is rooted. michael@0: // Optionally, aArgv may be nullptr, in which case the array is allocated and michael@0: // rooted, but all items remain nullptr. This presumably means the caller michael@0: // will then QI us for nsIJSArgArray, and set our array elements. michael@0: nsresult NS_CreateJSArgv(JSContext *aContext, uint32_t aArgc, void *aArgv, michael@0: nsIJSArgArray **aArray); michael@0: michael@0: #endif // nsDOMJSUtils_h__