1
0
forked from 0ad/0ad

Replace deprecated jsval with JS::Value.

Remove unused SGUIBaseSettings and GUI comment.
Fix indentation of a macro, refs D794.

Differential Revision: https://code.wildfiregames.com/D838
Review by: leper.
Itms came up with the same patch for the SpiderMonkey 45 update
independently.

This was SVN commit r20062.
This commit is contained in:
elexis 2017-08-28 10:27:36 +00:00
parent 8f51469793
commit 1b44946078
22 changed files with 73 additions and 120 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games. /* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -78,7 +78,7 @@ private:
* Thread-safety: * Thread-safety:
* - Initialize and constructor/destructor must be called from the main thread. * - Initialize and constructor/destructor must be called from the main thread.
* - ScriptInterface created and destroyed by thread * - ScriptInterface created and destroyed by thread
* - StructuredClone used to return JS map data - jsvals can't be used across threads/runtimes * - StructuredClone used to return JS map data - JS:Values can't be used across threads/runtimes.
*/ */
class CMapGeneratorWorker class CMapGeneratorWorker
{ {

View File

@ -1240,7 +1240,7 @@ int CMapReader::GenerateMap()
} }
else if (progress == 0) else if (progress == 0)
{ {
// Finished, get results as StructuredClone object, which must be read to obtain the JS val // Finished, get results as StructuredClone object, which must be read to obtain the JS::Value
shared_ptr<ScriptInterface::StructuredClone> results = m_MapGen->GetResults(); shared_ptr<ScriptInterface::StructuredClone> results = m_MapGen->GetResults();
// Parse data into simulation context // Parse data into simulation context

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games. /* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -16,18 +16,9 @@
*/ */
/* /*
CGUI * This is the top class of the whole GUI, all objects
* and settings are stored within this class.
--Overview-- */
This is the top class of the whole GUI, all objects
and settings are stored within this class.
--More info--
Check GUI.h
*/
#ifndef INCLUDED_CGUI #ifndef INCLUDED_CGUI
#define INCLUDED_CGUI #define INCLUDED_CGUI
@ -247,7 +238,7 @@ public:
bool GetPreDefinedColor(const CStr& name, CColor& Output) const; bool GetPreDefinedColor(const CStr& name, CColor& Output) const;
shared_ptr<ScriptInterface> GetScriptInterface() { return m_ScriptInterface; }; shared_ptr<ScriptInterface> GetScriptInterface() { return m_ScriptInterface; };
jsval GetGlobalObject() { return m_ScriptInterface->GetGlobalObject(); }; JS::Value GetGlobalObject() { return m_ScriptInterface->GetGlobalObject(); };
private: private:

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2016 Wildfire Games. /* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -16,29 +16,11 @@
*/ */
/* /*
The base class of an object * The base class of an object.
* All objects are derived from this class.
--Overview-- * It's an abstract data type, so it can't be used per se.
* Also contains a Dummy object which is used for completely blank objects.
All objects are derived from this class, it's an ADT */
so it can't be used per se
Also contains a Dummy object which is used for
completely blank objects.
--Usage--
Write about how to use it here
--Examples--
Provide examples of how to use this code, if necessary
--More info--
Check GUI.h
*/
#ifndef INCLUDED_IGUIOBJECT #ifndef INCLUDED_IGUIOBJECT
#define INCLUDED_IGUIOBJECT #define INCLUDED_IGUIOBJECT
@ -90,26 +72,6 @@ struct SGUISetting
EGUISettingType m_Type; EGUISettingType m_Type;
}; };
/**
* Base settings, all objects possess these settings
* in their m_BaseSettings
* Instructions can be found in the documentations.
*/
/*struct SGUIBaseSettings
{
//int banan;
bool m_Absolute;
CStr m_Caption; // Is usually set within an XML element and not in the attributes
bool m_Enabled;
bool m_Ghost;
bool m_Hidden;
CClientArea m_Size;
CStr m_Style;
float m_Z;
};*/
//////////////////////////////////////////////////////////
/** /**
* GUI object such as a button or an input-box. * GUI object such as a button or an input-box.
* Abstract data type ! * Abstract data type !
@ -124,7 +86,7 @@ class IGUIObject
// Allow getProperty to access things like GetParent() // Allow getProperty to access things like GetParent()
friend bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp); friend bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp);
friend bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, bool UNUSED(strict), JS::MutableHandleValue vp); friend bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, bool UNUSED(strict), JS::MutableHandleValue vp);
friend bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint argc, jsval* vp); friend bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint argc, JS::Value* vp);
public: public:
IGUIObject(); IGUIObject();

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games. /* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -35,7 +35,7 @@ JSFunctionSpec JSI_GUISize::JSI_methods[] =
JS_FS_END JS_FS_END
}; };
bool JSI_GUISize::construct(JSContext* cx, uint argc, jsval* vp) bool JSI_GUISize::construct(JSContext* cx, uint argc, JS::Value* vp)
{ {
JSAutoRequest rq(cx); JSAutoRequest rq(cx);
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
@ -91,7 +91,7 @@ CStr ToPercentString(double pix, double per)
return CStr::FromDouble(per)+"%"+(pix == 0.0 ? CStr() : pix > 0.0 ? CStr("+")+CStr::FromDouble(pix) : CStr::FromDouble(pix)); return CStr::FromDouble(per)+"%"+(pix == 0.0 ? CStr() : pix > 0.0 ? CStr("+")+CStr::FromDouble(pix) : CStr::FromDouble(pix));
} }
bool JSI_GUISize::toString(JSContext* cx, uint argc, jsval* vp) bool JSI_GUISize::toString(JSContext* cx, uint argc, JS::Value* vp)
{ {
UNUSED2(argc); UNUSED2(argc);
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
@ -143,7 +143,7 @@ JSFunctionSpec JSI_GUIColor::JSI_methods[] =
JS_FS_END JS_FS_END
}; };
bool JSI_GUIColor::construct(JSContext* cx, uint argc, jsval* vp) bool JSI_GUIColor::construct(JSContext* cx, uint argc, JS::Value* vp)
{ {
JSAutoRequest rq(cx); JSAutoRequest rq(cx);
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
@ -173,7 +173,7 @@ bool JSI_GUIColor::construct(JSContext* cx, uint argc, jsval* vp)
return true; return true;
} }
bool JSI_GUIColor::toString(JSContext* cx, uint argc, jsval* vp) bool JSI_GUIColor::toString(JSContext* cx, uint argc, JS::Value* vp)
{ {
UNUSED2(argc); UNUSED2(argc);
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
@ -212,7 +212,7 @@ JSFunctionSpec JSI_GUIMouse::JSI_methods[] =
JS_FS_END JS_FS_END
}; };
bool JSI_GUIMouse::construct(JSContext* cx, uint argc, jsval* vp) bool JSI_GUIMouse::construct(JSContext* cx, uint argc, JS::Value* vp)
{ {
JSAutoRequest rq(cx); JSAutoRequest rq(cx);
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
@ -238,7 +238,7 @@ bool JSI_GUIMouse::construct(JSContext* cx, uint argc, jsval* vp)
return true; return true;
} }
bool JSI_GUIMouse::toString(JSContext* cx, uint argc, jsval* vp) bool JSI_GUIMouse::toString(JSContext* cx, uint argc, JS::Value* vp)
{ {
UNUSED2(argc); UNUSED2(argc);
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); JS::CallReceiver rec = JS::CallReceiverFromVp(vp);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2009 Wildfire Games. /* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -26,8 +26,8 @@
extern JSClass JSI_class; \ extern JSClass JSI_class; \
extern JSPropertySpec JSI_props[]; \ extern JSPropertySpec JSI_props[]; \
extern JSFunctionSpec JSI_methods[]; \ extern JSFunctionSpec JSI_methods[]; \
bool construct(JSContext* cx, uint argc, jsval* vp); \ bool construct(JSContext* cx, uint argc, JS::Value* vp); \
bool toString(JSContext* cx, uint argc, jsval* vp); \ bool toString(JSContext* cx, uint argc, JS::Value* vp); \
} }
GUISTDTYPE(Size) GUISTDTYPE(Size)

View File

@ -587,7 +587,7 @@ bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::Handle
} }
bool JSI_IGUIObject::construct(JSContext* cx, uint argc, jsval* vp) bool JSI_IGUIObject::construct(JSContext* cx, uint argc, JS::Value* vp)
{ {
JSAutoRequest rq(cx); JSAutoRequest rq(cx);
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
@ -614,7 +614,7 @@ void JSI_IGUIObject::init(ScriptInterface& scriptInterface)
scriptInterface.DefineCustomObjectType(&JSI_class, construct, 1, JSI_props, JSI_methods, NULL, NULL); scriptInterface.DefineCustomObjectType(&JSI_class, construct, 1, JSI_props, JSI_methods, NULL, NULL);
} }
bool JSI_IGUIObject::toString(JSContext* cx, uint UNUSED(argc), jsval* vp) bool JSI_IGUIObject::toString(JSContext* cx, uint UNUSED(argc), JS::Value* vp)
{ {
JSAutoRequest rq(cx); JSAutoRequest rq(cx);
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
@ -632,7 +632,7 @@ bool JSI_IGUIObject::toString(JSContext* cx, uint UNUSED(argc), jsval* vp)
return true; return true;
} }
bool JSI_IGUIObject::focus(JSContext* cx, uint UNUSED(argc), jsval* vp) bool JSI_IGUIObject::focus(JSContext* cx, uint UNUSED(argc), JS::Value* vp)
{ {
JSAutoRequest rq(cx); JSAutoRequest rq(cx);
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
@ -649,7 +649,7 @@ bool JSI_IGUIObject::focus(JSContext* cx, uint UNUSED(argc), jsval* vp)
return true; return true;
} }
bool JSI_IGUIObject::blur(JSContext* cx, uint UNUSED(argc), jsval* vp) bool JSI_IGUIObject::blur(JSContext* cx, uint UNUSED(argc), JS::Value* vp)
{ {
JSAutoRequest rq(cx); JSAutoRequest rq(cx);
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
@ -666,7 +666,7 @@ bool JSI_IGUIObject::blur(JSContext* cx, uint UNUSED(argc), jsval* vp)
return true; return true;
} }
bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint UNUSED(argc), jsval* vp) bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint UNUSED(argc), JS::Value* vp)
{ {
JSAutoRequest rq(cx); JSAutoRequest rq(cx);
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); JS::CallReceiver rec = JS::CallReceiverFromVp(vp);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2009 Wildfire Games. /* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -27,11 +27,11 @@ namespace JSI_IGUIObject
extern JSFunctionSpec JSI_methods[]; extern JSFunctionSpec JSI_methods[];
bool getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp); bool getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp);
bool setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, bool UNUSED(strict), JS::MutableHandleValue vp); bool setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, bool UNUSED(strict), JS::MutableHandleValue vp);
bool construct(JSContext* cx, uint argc, jsval* vp); bool construct(JSContext* cx, uint argc, JS::Value* vp);
bool toString(JSContext* cx, uint argc, jsval* vp); bool toString(JSContext* cx, uint argc, JS::Value* vp);
bool focus(JSContext* cx, uint argc, jsval* vp); bool focus(JSContext* cx, uint argc, JS::Value* vp);
bool blur(JSContext* cx, uint argc, jsval* vp); bool blur(JSContext* cx, uint argc, JS::Value* vp);
bool getComputedSize(JSContext* cx, uint argc, jsval* vp); bool getComputedSize(JSContext* cx, uint argc, JS::Value* vp);
void init(ScriptInterface& scriptInterface); void init(ScriptInterface& scriptInterface);
} }

View File

@ -70,21 +70,21 @@ BOOST_PP_REPEAT(SCRIPT_INTERFACE_MAX_ARGS, OVERLOADS, ~)
// (Definition comes later, since it depends on some things we haven't defined yet) // (Definition comes later, since it depends on some things we haven't defined yet)
#define OVERLOADS(z, i, data) \ #define OVERLOADS(z, i, data) \
template <typename R, TYPENAME_T0_HEAD(z,i) R (*fptr) ( ScriptInterface::CxPrivate* T0_TAIL_MAYBE_REF(z,i) )> \ template <typename R, TYPENAME_T0_HEAD(z,i) R (*fptr) ( ScriptInterface::CxPrivate* T0_TAIL_MAYBE_REF(z,i) )> \
static bool call(JSContext* cx, uint argc, jsval* vp); static bool call(JSContext* cx, uint argc, JS::Value* vp);
BOOST_PP_REPEAT(SCRIPT_INTERFACE_MAX_ARGS, OVERLOADS, ~) BOOST_PP_REPEAT(SCRIPT_INTERFACE_MAX_ARGS, OVERLOADS, ~)
#undef OVERLOADS #undef OVERLOADS
// Similar, for class methods // Similar, for class methods
#define OVERLOADS(z, i, data) \ #define OVERLOADS(z, i, data) \
template <typename R, TYPENAME_T0_HEAD(z,i) JSClass* CLS, typename TC, R (TC::*fptr) ( T0_MAYBE_REF(z,i) )> \ template <typename R, TYPENAME_T0_HEAD(z,i) JSClass* CLS, typename TC, R (TC::*fptr) ( T0_MAYBE_REF(z,i) )> \
static bool callMethod(JSContext* cx, uint argc, jsval* vp); static bool callMethod(JSContext* cx, uint argc, JS::Value* vp);
BOOST_PP_REPEAT(SCRIPT_INTERFACE_MAX_ARGS, OVERLOADS, ~) BOOST_PP_REPEAT(SCRIPT_INTERFACE_MAX_ARGS, OVERLOADS, ~)
#undef OVERLOADS #undef OVERLOADS
// const methods // const methods
#define OVERLOADS(z, i, data) \ #define OVERLOADS(z, i, data) \
template <typename R, TYPENAME_T0_HEAD(z,i) JSClass* CLS, typename TC, R (TC::*fptr) ( T0_MAYBE_REF(z,i) ) const> \ template <typename R, TYPENAME_T0_HEAD(z,i) JSClass* CLS, typename TC, R (TC::*fptr) ( T0_MAYBE_REF(z,i) ) const> \
static bool callMethodConst(JSContext* cx, uint argc, jsval* vp); static bool callMethodConst(JSContext* cx, uint argc, JS::Value* vp);
BOOST_PP_REPEAT(SCRIPT_INTERFACE_MAX_ARGS, OVERLOADS, ~) BOOST_PP_REPEAT(SCRIPT_INTERFACE_MAX_ARGS, OVERLOADS, ~)
#undef OVERLOADS #undef OVERLOADS

View File

@ -112,7 +112,7 @@ struct ScriptInterface_NativeMethodWrapper<void, TC>
// JSFastNative-compatible function that wraps the function identified in the template argument list // JSFastNative-compatible function that wraps the function identified in the template argument list
#define OVERLOADS(z, i, data) \ #define OVERLOADS(z, i, data) \
template <typename R, TYPENAME_T0_HEAD(z,i) R (*fptr) ( ScriptInterface::CxPrivate* T0_TAIL_MAYBE_REF(z,i) )> \ template <typename R, TYPENAME_T0_HEAD(z,i) R (*fptr) ( ScriptInterface::CxPrivate* T0_TAIL_MAYBE_REF(z,i) )> \
bool ScriptInterface::call(JSContext* cx, uint argc, jsval* vp) \ bool ScriptInterface::call(JSContext* cx, uint argc, JS::Value* vp) \
{ \ { \
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); \ JS::CallArgs args = JS::CallArgsFromVp(argc, vp); \
JSAutoRequest rq(cx); \ JSAutoRequest rq(cx); \
@ -128,7 +128,7 @@ BOOST_PP_REPEAT(SCRIPT_INTERFACE_MAX_ARGS, OVERLOADS, ~)
// Same idea but for methods // Same idea but for methods
#define OVERLOADS(z, i, data) \ #define OVERLOADS(z, i, data) \
template <typename R, TYPENAME_T0_HEAD(z,i) JSClass* CLS, typename TC, R (TC::*fptr) ( T0_MAYBE_REF(z,i) )> \ template <typename R, TYPENAME_T0_HEAD(z,i) JSClass* CLS, typename TC, R (TC::*fptr) ( T0_MAYBE_REF(z,i) )> \
bool ScriptInterface::callMethod(JSContext* cx, uint argc, jsval* vp) \ bool ScriptInterface::callMethod(JSContext* cx, uint argc, JS::Value* vp) \
{ \ { \
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); \ JS::CallArgs args = JS::CallArgsFromVp(argc, vp); \
JSAutoRequest rq(cx); \ JSAutoRequest rq(cx); \
@ -148,7 +148,7 @@ BOOST_PP_REPEAT(SCRIPT_INTERFACE_MAX_ARGS, OVERLOADS, ~)
// const methods // const methods
#define OVERLOADS(z, i, data) \ #define OVERLOADS(z, i, data) \
template <typename R, TYPENAME_T0_HEAD(z,i) JSClass* CLS, typename TC, R (TC::*fptr) ( T0_MAYBE_REF(z,i) ) const> \ template <typename R, TYPENAME_T0_HEAD(z,i) JSClass* CLS, typename TC, R (TC::*fptr) ( T0_MAYBE_REF(z,i) ) const> \
bool ScriptInterface::callMethodConst(JSContext* cx, uint argc, jsval* vp) \ bool ScriptInterface::callMethodConst(JSContext* cx, uint argc, JS::Value* vp) \
{ \ { \
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); \ JS::CallArgs args = JS::CallArgsFromVp(argc, vp); \
JSAutoRequest rq(cx); \ JSAutoRequest rq(cx); \

View File

@ -138,7 +138,7 @@ void ErrorReporter(JSContext* cx, const char* message, JSErrorReport* report)
// Functions in the global namespace: // Functions in the global namespace:
bool print(JSContext* cx, uint argc, jsval* vp) bool print(JSContext* cx, uint argc, JS::Value* vp)
{ {
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
for (uint i = 0; i < args.length(); ++i) for (uint i = 0; i < args.length(); ++i)
@ -153,7 +153,7 @@ bool print(JSContext* cx, uint argc, jsval* vp)
return true; return true;
} }
bool logmsg(JSContext* cx, uint argc, jsval* vp) bool logmsg(JSContext* cx, uint argc, JS::Value* vp)
{ {
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if (args.length() < 1) if (args.length() < 1)
@ -170,7 +170,7 @@ bool logmsg(JSContext* cx, uint argc, jsval* vp)
return true; return true;
} }
bool warn(JSContext* cx, uint argc, jsval* vp) bool warn(JSContext* cx, uint argc, JS::Value* vp)
{ {
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if (args.length() < 1) if (args.length() < 1)
@ -187,7 +187,7 @@ bool warn(JSContext* cx, uint argc, jsval* vp)
return true; return true;
} }
bool error(JSContext* cx, uint argc, jsval* vp) bool error(JSContext* cx, uint argc, JS::Value* vp)
{ {
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if (args.length() < 1) if (args.length() < 1)
@ -204,7 +204,7 @@ bool error(JSContext* cx, uint argc, jsval* vp)
return true; return true;
} }
bool deepcopy(JSContext* cx, uint argc, jsval* vp) bool deepcopy(JSContext* cx, uint argc, JS::Value* vp)
{ {
JSAutoRequest rq(cx); JSAutoRequest rq(cx);
@ -223,7 +223,7 @@ bool deepcopy(JSContext* cx, uint argc, jsval* vp)
return true; return true;
} }
bool ProfileStart(JSContext* cx, uint argc, jsval* vp) bool ProfileStart(JSContext* cx, uint argc, JS::Value* vp)
{ {
const char* name = "(ProfileStart)"; const char* name = "(ProfileStart)";
@ -252,7 +252,7 @@ bool ProfileStart(JSContext* cx, uint argc, jsval* vp)
return true; return true;
} }
bool ProfileStop(JSContext* UNUSED(cx), uint UNUSED(argc), jsval* vp) bool ProfileStop(JSContext* UNUSED(cx), uint UNUSED(argc), JS::Value* vp)
{ {
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
if (CProfileManager::IsInitialised() && ThreadUtil::IsMainThread()) if (CProfileManager::IsInitialised() && ThreadUtil::IsMainThread())
@ -264,7 +264,7 @@ bool ProfileStop(JSContext* UNUSED(cx), uint UNUSED(argc), jsval* vp)
return true; return true;
} }
bool ProfileAttribute(JSContext* cx, uint argc, jsval* vp) bool ProfileAttribute(JSContext* cx, uint argc, JS::Value* vp)
{ {
const char* name = "(ProfileAttribute)"; const char* name = "(ProfileAttribute)";
@ -308,7 +308,7 @@ static double generate_uniform_real(boost::rand48& rng, double min, double max)
} }
} }
bool Math_random(JSContext* cx, uint UNUSED(argc), jsval* vp) bool Math_random(JSContext* cx, uint UNUSED(argc), JS::Value* vp)
{ {
JS::CallReceiver rec = JS::CallReceiverFromVp(vp); JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
double r; double r;
@ -580,7 +580,7 @@ bool ScriptInterface::CallFunction_(JS::HandleValue val, const char* name, JS::H
return ok; return ok;
} }
jsval ScriptInterface::GetGlobalObject() JS::Value ScriptInterface::GetGlobalObject()
{ {
JSAutoRequest rq(m->m_cx); JSAutoRequest rq(m->m_cx);
return JS::ObjectValue(*JS::CurrentGlobalOrNull(m->m_cx)); return JS::ObjectValue(*JS::CurrentGlobalOrNull(m->m_cx));

View File

@ -134,7 +134,7 @@ public:
JSObject* CreateCustomObject(const std::string & typeName) const; JSObject* CreateCustomObject(const std::string & typeName) const;
void DefineCustomObjectType(JSClass *clasp, JSNative constructor, uint minArgs, JSPropertySpec *ps, JSFunctionSpec *fs, JSPropertySpec *static_ps, JSFunctionSpec *static_fs); void DefineCustomObjectType(JSClass *clasp, JSNative constructor, uint minArgs, JSPropertySpec *ps, JSFunctionSpec *fs, JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
jsval GetGlobalObject(); JS::Value GetGlobalObject();
JSClass* GetGlobalClass(); JSClass* GetGlobalClass();
@ -269,12 +269,12 @@ public:
JS::Value CloneValueFromOtherContext(const ScriptInterface& otherContext, JS::HandleValue val) const; JS::Value CloneValueFromOtherContext(const ScriptInterface& otherContext, JS::HandleValue val) const;
/** /**
* Convert a jsval to a C++ type. (This might trigger GC.) * Convert a JS::Value to a C++ type. (This might trigger GC.)
*/ */
template<typename T> static bool FromJSVal(JSContext* cx, const JS::HandleValue val, T& ret); template<typename T> static bool FromJSVal(JSContext* cx, const JS::HandleValue val, T& ret);
/** /**
* Convert a C++ type to a jsval. (This might trigger GC. The return * Convert a C++ type to a JS::Value. (This might trigger GC. The return
* value must be rooted if you don't want it to be collected.) * value must be rooted if you don't want it to be collected.)
* NOTE: We are passing the JS::Value by reference instead of returning it by value. * NOTE: We are passing the JS::Value by reference instead of returning it by value.
* The reason is a memory corruption problem that appears to be caused by a bug in Visual Studio. * The reason is a memory corruption problem that appears to be caused by a bug in Visual Studio.
@ -303,7 +303,7 @@ public:
bool MathRandom(double& nbr); bool MathRandom(double& nbr);
/** /**
* Structured clones are a way to serialize 'simple' JS values into a buffer * Structured clones are a way to serialize 'simple' JS::Values into a buffer
* that can safely be passed between contexts and runtimes and threads. * that can safely be passed between contexts and runtimes and threads.
* A StructuredClone can be stored and read multiple times if desired. * A StructuredClone can be stored and read multiple times if desired.
* We wrap them in shared_ptr so memory management is automatic and * We wrap them in shared_ptr so memory management is automatic and

View File

@ -135,7 +135,7 @@ public:
roundtrip<u32>(1073741823, "1073741823"); // JSVAL_INT_MAX roundtrip<u32>(1073741823, "1073741823"); // JSVAL_INT_MAX
{ {
TestLogger log; // swallow warnings about values not being stored as INT jsvals TestLogger log; // swallow warnings about values not being stored as integer JS::Values
roundtrip<i32>(1073741824, "1073741824"); // JSVAL_INT_MAX+1 roundtrip<i32>(1073741824, "1073741824"); // JSVAL_INT_MAX+1
roundtrip<i32>(-1073741825, "-1073741825"); // JSVAL_INT_MIN-1 roundtrip<i32>(-1073741825, "-1073741825"); // JSVAL_INT_MIN-1
roundtrip<u32>(1073741824, "1073741824"); // JSVAL_INT_MAX+1 roundtrip<u32>(1073741824, "1073741824"); // JSVAL_INT_MAX+1

View File

@ -64,7 +64,7 @@ extern void kill_mainloop();
* will block until it's actually completed, so the rest of the engine should avoid * will block until it's actually completed, so the rest of the engine should avoid
* reading it for as long as possible. * reading it for as long as possible.
* *
* JS values are passed between the game and AI threads using ScriptInterface::StructuredClone. * JS::Values are passed between the game and AI threads using ScriptInterface::StructuredClone.
* *
* TODO: actually the thread isn't implemented yet, because performance hasn't been * TODO: actually the thread isn't implemented yet, because performance hasn't been
* sufficiently problematic to justify the complexity yet, but the CAIWorker interface * sufficiently problematic to justify the complexity yet, but the CAIWorker interface

View File

@ -110,7 +110,7 @@ corresponding to the C++ const method
For methods exposed to scripts like this, the arguments should be simple types or const references. For methods exposed to scripts like this, the arguments should be simple types or const references.
Check scriptinterface/NativeWrapperDefns.h for which simple types are pass-by-value. Check scriptinterface/NativeWrapperDefns.h for which simple types are pass-by-value.
The arguments and return types will be automatically converted between C++ and JS values. The arguments and return types will be automatically converted between C++ and JS::Values.
To do this, @c ToJSVal<ReturnType> and @c FromJSVal<ArgTypeN> must be defined (if they To do this, @c ToJSVal<ReturnType> and @c FromJSVal<ArgTypeN> must be defined (if they
haven't already been defined for another method), as described below. haven't already been defined for another method), as described below.
@ -135,7 +135,7 @@ Non-basic data types from the game engine typically go in simulation2/scripting/
(They could go in different files if that turns out to be cleaner - it doesn't matter where they're (They could go in different files if that turns out to be cleaner - it doesn't matter where they're
defined as long as the linker finds them). defined as long as the linker finds them).
To convert from a C++ type @c T to a JS value, define: To convert from a C++ type @c T to a JS::Value, define:
@code @code
template<> void ScriptInterface::ToJSVal<T>(JSContext* cx, JS::MutableHandleValue ret, const T& val) template<> void ScriptInterface::ToJSVal<T>(JSContext* cx, JS::MutableHandleValue ret, const T& val)
@ -149,7 +149,7 @@ to do the conversion (possibly calling @c ToJSVal recursively).
On error, you should execute @c ret.setUndefined() and probably report an error message somehow. On error, you should execute @c ret.setUndefined() and probably report an error message somehow.
Be careful about JS garbage collection (don't let it collect the objects you're constructing before you return them). Be careful about JS garbage collection (don't let it collect the objects you're constructing before you return them).
To convert from a JS value to a C++ type @c T, define: To convert from a JS::Value to a C++ type @c T, define:
@code @code
template<> bool ScriptInterface::FromJSVal<T>(JSContext* cx, JS::HandleValue v, T& out) template<> bool ScriptInterface::FromJSVal<T>(JSContext* cx, JS::HandleValue v, T& out)

View File

@ -28,7 +28,7 @@ class CDebugSerializer : public ISerializer
NONCOPYABLE(CDebugSerializer); NONCOPYABLE(CDebugSerializer);
public: public:
/** /**
* @param scriptInterface Script interface corresponding to any jsvals passed to ScriptVal() * @param scriptInterface Script interface corresponding to any JS::Value passed to ScriptVal()
* @param stream Stream to receive UTF-8 encoded output * @param stream Stream to receive UTF-8 encoded output
* @param includeDebugInfo If true then additional non-deterministic data will be included in the output * @param includeDebugInfo If true then additional non-deterministic data will be included in the output
*/ */

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2011 Wildfire Games. /* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -55,7 +55,7 @@ public:
virtual void StringASCII(const char* name, std::string& out, uint32_t minlength, uint32_t maxlength); virtual void StringASCII(const char* name, std::string& out, uint32_t minlength, uint32_t maxlength);
virtual void String(const char* name, std::wstring& out, uint32_t minlength, uint32_t maxlength); virtual void String(const char* name, std::wstring& out, uint32_t minlength, uint32_t maxlength);
/// Deserialize a jsval, replacing 'out' /// Deserialize a JS::Value, replacing 'out'
virtual void ScriptVal(const char* name, JS::MutableHandleValue out) = 0; virtual void ScriptVal(const char* name, JS::MutableHandleValue out) = 0;
/// Deserialize an object value, appending properties to object 'objVal' /// Deserialize an object value, appending properties to object 'objVal'

View File

@ -122,7 +122,7 @@ void CStdDeserializer::GetScriptBackref(u32 tag, JS::MutableHandleObject ret)
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
jsval CStdDeserializer::ReadScriptVal(const char* UNUSED(name), JS::HandleObject appendParent) JS::Value CStdDeserializer::ReadScriptVal(const char* UNUSED(name), JS::HandleObject appendParent)
{ {
JSContext* cx = m_ScriptInterface.GetContext(); JSContext* cx = m_ScriptInterface.GetContext();
JSAutoRequest rq(cx); JSAutoRequest rq(cx);

View File

@ -48,7 +48,7 @@ protected:
virtual void Get(const char* name, u8* data, size_t len); virtual void Get(const char* name, u8* data, size_t len);
private: private:
jsval ReadScriptVal(const char* name, JS::HandleObject appendParent); JS::Value ReadScriptVal(const char* name, JS::HandleObject appendParent);
void ReadStringLatin1(const char* name, std::vector<JS::Latin1Char>& str); void ReadStringLatin1(const char* name, std::vector<JS::Latin1Char>& str);
void ReadStringUTF16(const char* name, utf16string& str); void ReadStringUTF16(const char* name, utf16string& str);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games. /* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -48,7 +48,7 @@ const entity_id_t SYSTEM_ENTITY = 1;
// aren't retained in saved games, etc) // aren't retained in saved games, etc)
// The distinction is encoded in the entity ID, so that they're easily distinguished. // The distinction is encoded in the entity ID, so that they're easily distinguished.
// //
// We want all entity_id_ts to fit in jsval ints, i.e. 1-2^30 .. 2^30-1 (inclusive) // We want all entity_id_ts to fit in an integer JS::Value, i.e. 1-2^30 .. 2^30-1 (inclusive)
// We want them to be unsigned ints (actually it shouldn't matter but unsigned seems simpler) // We want them to be unsigned ints (actually it shouldn't matter but unsigned seems simpler)
// We want 1 tag bit // We want 1 tag bit
// So we have 1 JS-reserved bit, 1 unused sign bit, 1 local tag bit, 29 counter bits // So we have 1 JS-reserved bit, 1 unused sign bit, 1 local tag bit, 29 counter bits

View File

@ -186,7 +186,7 @@ public:
*/ */
const CParamNode& GetChild(const char* name) const; const CParamNode& GetChild(const char* name) const;
// (Children are returned as const in order to allow future optimisations, where we assume // (Children are returned as const in order to allow future optimisations, where we assume
// a node is always modified explicitly and not indirectly via its children, e.g. to cache jsvals) // a node is always modified explicitly and not indirectly via its children, e.g. to cache JS::Values)
/** /**
* Returns true if this is a valid CParamNode, false if it represents a non-existent node * Returns true if this is a valid CParamNode, false if it represents a non-existent node
@ -240,8 +240,8 @@ public:
void ToXML(std::wostream& strm) const; void ToXML(std::wostream& strm) const;
/** /**
* Returns a jsval representation of this node and its children. * Returns a JS::Value representation of this node and its children.
* If @p cacheValue is true, then the same jsval will be returned each time * If @p cacheValue is true, then the same JS::Value will be returned each time
* this is called (regardless of whether you passed the same @p cx - be careful * this is called (regardless of whether you passed the same @p cx - be careful
* to only use the cache in one context). * to only use the cache in one context).
* When caching, the lifetime of @p cx must be longer than the lifetime of this node. * When caching, the lifetime of @p cx must be longer than the lifetime of this node.

View File

@ -505,7 +505,7 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent)
wxString helpData; wxString helpData;
helpFile.ReadAll(&helpData); helpFile.ReadAll(&helpData);
AtObj data = AtlasObject::LoadFromJSON(std::string(helpData)); AtObj data = AtlasObject::LoadFromJSON(std::string(helpData));
#define ADD_HELP_ITEM(id) \ #define ADD_HELP_ITEM(id) \
do { \ do { \
if (!data[#id].hasContent()) \ if (!data[#id].hasContent()) \
break; \ break; \
@ -519,7 +519,7 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent)
} while (0) } while (0)
ADD_HELP_ITEM(Manual); ADD_HELP_ITEM(Manual);
ADD_HELP_ITEM(ReportBug); ADD_HELP_ITEM(ReportBug);
#undef ADD_HELP_ITEM #undef ADD_HELP_ITEM
} }
else else
wxLogError(_("'%ls' does not exist"), helpPath.GetFullPath().c_str()); wxLogError(_("'%ls' does not exist"), helpPath.GetFullPath().c_str());