2015-05-03 22:32:37 +03: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 15:12:37 +04: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 07:07:47 +04:00
|
|
|
#ifndef nsDOMJSUtils_h__
|
|
|
|
#define nsDOMJSUtils_h__
|
|
|
|
|
|
|
|
#include "nsIScriptContext.h"
|
2013-10-11 02:22:35 +04:00
|
|
|
#include "jsapi.h"
|
2006-06-13 07:07:47 +04:00
|
|
|
|
2012-03-11 12:53:05 +04:00
|
|
|
class nsIJSArgArray;
|
|
|
|
|
2006-06-13 07:07:47 +04: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 15:51:05 +04:00
|
|
|
if (!(JS::ContextOptionsRef(cx).privateIsNSISupports())) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-06-13 07:07:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptContext> scx =
|
2007-07-08 11:08:04 +04:00
|
|
|
do_QueryInterface(static_cast<nsISupports *>
|
|
|
|
(::JS_GetContextPrivate(cx)));
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
// This will return a pointer to something that's about to be
|
|
|
|
// released, but that's ok here.
|
|
|
|
return scx;
|
|
|
|
}
|
|
|
|
|
2013-09-05 01:06:55 +04:00
|
|
|
JSObject* GetDefaultScopeFromJSContext(JSContext *cx);
|
|
|
|
|
2013-04-12 02:52:10 +04:00
|
|
|
// A factory function for turning a JS::Value argv into an nsIArray
|
2006-06-13 07:07:47 +04: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 18:04:12 +04: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 12:23:00 +03:00
|
|
|
nsresult NS_CreateJSArgv(JSContext *aContext, uint32_t aArgc,
|
|
|
|
const JS::Value* aArgv, nsIJSArgArray **aArray);
|
2006-06-13 07:07:47 +04:00
|
|
|
|
|
|
|
#endif // nsDOMJSUtils_h__
|