mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 23:04:02 +00:00
Changes our JSNative functions to use JS::CallReceiver/JS::CallArgs.
This is the new way for working with arguments in JSNative functions. JS_THIS_VALUE, JS_ARGV, JS_SET_RVAL and direct access to vp or argc are deprecated and will probably be removed in future versions of SpiderMonkey. CallArgs also takes care of proper rooting and you can get the values as Handles or MutableHandles. The interface changes a little bit for ESR 31, but commiting this now still makes it easier and the changes shout be straigtforward (search and replace more or less). Refs #2462 Refs #2415 This was SVN commit r15516.
This commit is contained in:
@@ -464,80 +464,82 @@ void ErrorReporter(JSContext* cx, const char* message, JSErrorReport* report)
|
||||
|
||||
JSBool print(JSContext* cx, uint argc, jsval* vp)
|
||||
{
|
||||
for (uint i = 0; i < argc; ++i)
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
for (uint i = 0; i < args.length(); ++i)
|
||||
{
|
||||
std::wstring str;
|
||||
if (!ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[i], str))
|
||||
if (!ScriptInterface::FromJSVal(cx, args[i], str))
|
||||
return JS_FALSE;
|
||||
debug_printf(L"%ls", str.c_str());
|
||||
}
|
||||
fflush(stdout);
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
args.rval().setUndefined();
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool logmsg(JSContext* cx, uint argc, jsval* vp)
|
||||
{
|
||||
if (argc < 1)
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
if (args.length() < 1)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
args.rval().setUndefined();
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
std::wstring str;
|
||||
if (!ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[0], str))
|
||||
if (!ScriptInterface::FromJSVal(cx, args[0], str))
|
||||
return JS_FALSE;
|
||||
LOGMESSAGE(L"%ls", str.c_str());
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
args.rval().setUndefined();
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool warn(JSContext* cx, uint argc, jsval* vp)
|
||||
{
|
||||
if (argc < 1)
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
if (args.length() < 1)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
args.rval().setUndefined();
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
std::wstring str;
|
||||
if (!ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[0], str))
|
||||
if (!ScriptInterface::FromJSVal(cx, args[0], str))
|
||||
return JS_FALSE;
|
||||
LOGWARNING(L"%ls", str.c_str());
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
args.rval().setUndefined();
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool error(JSContext* cx, uint argc, jsval* vp)
|
||||
{
|
||||
if (argc < 1)
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
if (args.length() < 1)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
args.rval().setUndefined();
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
std::wstring str;
|
||||
if (!ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[0], str))
|
||||
if (!ScriptInterface::FromJSVal(cx, args[0], str))
|
||||
return JS_FALSE;
|
||||
LOGERROR(L"%ls", str.c_str());
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
args.rval().setUndefined();
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool deepcopy(JSContext* cx, uint argc, jsval* vp)
|
||||
{
|
||||
if (argc < 1)
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
if (args.length() < 1)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
args.rval().setUndefined();
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
jsval ret;
|
||||
|
||||
if (!JS_StructuredClone(cx, JS_ARGV(cx, vp)[0], &ret, NULL, NULL))
|
||||
if (!JS_StructuredClone(cx, args[0], args.rval().address(), NULL, NULL))
|
||||
return JS_FALSE;
|
||||
|
||||
JS_SET_RVAL(cx, vp, ret);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
@@ -545,10 +547,11 @@ JSBool ProfileStart(JSContext* cx, uint argc, jsval* vp)
|
||||
{
|
||||
const char* name = "(ProfileStart)";
|
||||
|
||||
if (argc >= 1)
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
if (args.length() >= 1)
|
||||
{
|
||||
std::string str;
|
||||
if (!ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[0], str))
|
||||
if (!ScriptInterface::FromJSVal(cx, args[0], str))
|
||||
return JS_FALSE;
|
||||
|
||||
typedef boost::flyweight<
|
||||
@@ -565,18 +568,19 @@ JSBool ProfileStart(JSContext* cx, uint argc, jsval* vp)
|
||||
|
||||
g_Profiler2.RecordRegionEnter(name);
|
||||
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
args.rval().setUndefined();
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool ProfileStop(JSContext* UNUSED(cx), uint UNUSED(argc), jsval* vp)
|
||||
{
|
||||
JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
|
||||
if (CProfileManager::IsInitialised() && ThreadUtil::IsMainThread())
|
||||
g_Profiler.Stop();
|
||||
|
||||
g_Profiler2.RecordRegionLeave("(ProfileStop)");
|
||||
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
rec.rval().setUndefined();
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
@@ -600,12 +604,12 @@ static double generate_uniform_real(boost::rand48& rng, double min, double max)
|
||||
|
||||
JSBool Math_random(JSContext* cx, uint UNUSED(argc), jsval* vp)
|
||||
{
|
||||
JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
|
||||
double r;
|
||||
if(!ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface->MathRandom(r))
|
||||
return JS_FALSE;
|
||||
|
||||
jsval rv = JS::NumberValue(r);
|
||||
JS_SET_RVAL(cx, vp, rv);
|
||||
rec.rval().setNumber(r);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user