2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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/. */
|
|
|
|
|
2006-06-13 03:07:47 +00:00
|
|
|
#ifndef nsDOMJSUtils_h__
|
|
|
|
#define nsDOMJSUtils_h__
|
|
|
|
|
|
|
|
#include "nsIScriptContext.h"
|
2013-10-10 22:22:35 +00:00
|
|
|
#include "jsapi.h"
|
2006-06-13 03:07:47 +00:00
|
|
|
|
2012-03-11 08:53:05 +00:00
|
|
|
class nsIJSArgArray;
|
|
|
|
|
2006-06-13 03:07:47 +00: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 11:51:05 +00:00
|
|
|
if (!(JS::ContextOptionsRef(cx).privateIsNSISupports())) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2006-06-13 03:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptContext> scx =
|
2007-07-08 07:08:04 +00:00
|
|
|
do_QueryInterface(static_cast<nsISupports *>
|
|
|
|
(::JS_GetContextPrivate(cx)));
|
2006-06-13 03:07:47 +00:00
|
|
|
|
|
|
|
// This will return a pointer to something that's about to be
|
|
|
|
// released, but that's ok here.
|
|
|
|
return scx;
|
|
|
|
}
|
|
|
|
|
2013-09-04 21:06:55 +00:00
|
|
|
JSObject* GetDefaultScopeFromJSContext(JSContext *cx);
|
|
|
|
|
2013-04-11 22:52:10 +00:00
|
|
|
// A factory function for turning a JS::Value argv into an nsIArray
|
2006-06-13 03:07:47 +00:00
|
|
|
// but also supports an effecient way of extracting the original argv.
|
|
|
|
// The resulting object will take a copy of the array, and ensure each
|
|
|
|
// element is rooted.
|
2013-10-28 14:04:12 +00: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.
|
2015-06-05 09:23:00 +00:00
|
|
|
nsresult NS_CreateJSArgv(JSContext *aContext, uint32_t aArgc,
|
|
|
|
const JS::Value* aArgv, nsIJSArgArray **aArray);
|
2006-06-13 03:07:47 +00:00
|
|
|
|
|
|
|
#endif // nsDOMJSUtils_h__
|