2026-05-18 12:11:00 -07:00
|
|
|
/* Copyright (C) 2026 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2010-01-09 11:20:14 -08:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2010-01-09 11:20:14 -08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2010-01-09 11:20:14 -08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-09 11:20:14 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
#include "scriptinterface/Conversions.h"
|
2025-06-19 15:06:41 -07:00
|
|
|
|
|
|
|
|
#include "gui/CGUISprite.h"
|
2019-10-02 02:44:00 -07:00
|
|
|
#include "gui/ObjectBases/IGUIObject.h"
|
2025-06-19 15:06:41 -07:00
|
|
|
#include "gui/Scripting/JSInterface_GUIProxy.h"
|
2019-10-02 02:44:00 -07:00
|
|
|
#include "gui/SettingTypes/CGUIColor.h"
|
|
|
|
|
#include "gui/SettingTypes/CGUIList.h"
|
|
|
|
|
#include "gui/SettingTypes/CGUISeries.h"
|
2025-06-19 15:06:41 -07:00
|
|
|
#include "gui/SettingTypes/CGUIString.h"
|
2025-06-19 15:06:41 -07:00
|
|
|
#include "gui/SettingTypes/EAlign.h"
|
|
|
|
|
#include "gui/SettingTypes/EScrollOrientation.h"
|
2025-06-19 15:06:41 -07:00
|
|
|
#include "lib/code_generation.h"
|
2012-01-12 15:32:27 -08:00
|
|
|
#include "lib/external_libraries/libsdl.h"
|
2025-06-19 15:06:41 -07:00
|
|
|
#include "maths/Rect.h"
|
2021-03-27 09:08:06 -07:00
|
|
|
#include "maths/Size2D.h"
|
2017-01-06 03:14:03 -08:00
|
|
|
#include "maths/Vector2D.h"
|
2020-11-18 03:35:36 -08:00
|
|
|
#include "ps/CLogger.h"
|
2025-06-19 15:06:41 -07:00
|
|
|
#include "ps/Hotkey.h"
|
2021-05-13 10:23:52 -07:00
|
|
|
#include "scriptinterface/Object.h"
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
#include "scriptinterface/Exceptions.h"
|
|
|
|
|
#include "scriptinterface/Request.h"
|
2010-01-09 11:20:14 -08:00
|
|
|
|
2025-06-19 15:06:41 -07:00
|
|
|
#include <js/CallArgs.h>
|
|
|
|
|
#include <js/PropertyAndElement.h>
|
|
|
|
|
#include <js/RootingAPI.h>
|
|
|
|
|
#include <js/TypeDecls.h>
|
|
|
|
|
#include <js/Value.h>
|
|
|
|
|
#include <jsapi.h>
|
|
|
|
|
#include <SDL_events.h>
|
2019-09-20 06:11:18 -07:00
|
|
|
#include <string>
|
2025-06-19 15:06:41 -07:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
struct CColor;
|
2019-09-20 06:11:18 -07:00
|
|
|
|
2021-05-13 02:43:33 -07:00
|
|
|
#define SET(obj, name, value) STMT(JS::RootedValue v_(rq.cx); Script::ToJSVal(rq, &v_, (value)); JS_SetProperty(rq.cx, obj, (name), v_))
|
2010-01-09 11:20:14 -08:00
|
|
|
// ignore JS_SetProperty return value, because errors should be impossible
|
|
|
|
|
// and we can't do anything useful in the case of errors anyway
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> void Script::ToJSVal<SDL_Event>(const Script::Request& rq, JS::MutableHandleValue ret, SDL_Event const& ev)
|
2010-01-09 11:20:14 -08:00
|
|
|
{
|
|
|
|
|
const char* typeName;
|
|
|
|
|
|
2026-05-18 12:11:00 -07:00
|
|
|
switch (ev.type)
|
2010-01-09 11:20:14 -08:00
|
|
|
{
|
2012-02-06 14:47:35 -08:00
|
|
|
case SDL_WINDOWEVENT: typeName = "windowevent"; break;
|
2010-01-09 11:20:14 -08:00
|
|
|
case SDL_KEYDOWN: typeName = "keydown"; break;
|
|
|
|
|
case SDL_KEYUP: typeName = "keyup"; break;
|
|
|
|
|
case SDL_MOUSEMOTION: typeName = "mousemotion"; break;
|
|
|
|
|
case SDL_MOUSEBUTTONDOWN: typeName = "mousebuttondown"; break;
|
|
|
|
|
case SDL_MOUSEBUTTONUP: typeName = "mousebuttonup"; break;
|
2011-11-09 05:09:01 -08:00
|
|
|
case SDL_QUIT: typeName = "quit"; break;
|
2021-03-31 08:50:25 -07:00
|
|
|
case SDL_HOTKEYPRESS: typeName = "hotkeypress"; break;
|
2010-01-09 11:20:14 -08:00
|
|
|
case SDL_HOTKEYDOWN: typeName = "hotkeydown"; break;
|
|
|
|
|
case SDL_HOTKEYUP: typeName = "hotkeyup"; break;
|
2021-03-31 08:50:25 -07:00
|
|
|
case SDL_HOTKEYPRESS_SILENT: typeName = "hotkeypresssilent"; break;
|
|
|
|
|
case SDL_HOTKEYUP_SILENT: typeName = "hotkeyupsilent"; break;
|
2010-01-09 11:20:14 -08:00
|
|
|
default: typeName = "(unknown)"; break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedObject obj(rq.cx, JS_NewPlainObject(rq.cx));
|
2014-07-14 12:52:35 -07:00
|
|
|
if (!obj)
|
2014-03-28 13:26:32 -07:00
|
|
|
{
|
2014-07-14 12:52:35 -07:00
|
|
|
ret.setUndefined();
|
2014-03-28 13:26:32 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2010-01-09 11:20:14 -08:00
|
|
|
|
|
|
|
|
SET(obj, "type", typeName);
|
|
|
|
|
|
2026-05-18 12:11:00 -07:00
|
|
|
switch (ev.type)
|
2010-01-09 11:20:14 -08:00
|
|
|
{
|
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
|
case SDL_KEYUP:
|
|
|
|
|
{
|
2026-05-18 12:11:00 -07:00
|
|
|
// SET(obj, "which", static_cast<int>(ev.key.which)); // (not in wsdl.h)
|
|
|
|
|
// SET(obj, "state", static_cast<int>(ev.key.state)); // (not in wsdl.h)
|
2010-01-09 11:20:14 -08:00
|
|
|
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedObject keysym(rq.cx, JS_NewPlainObject(rq.cx));
|
2016-08-02 09:12:11 -07:00
|
|
|
if (!keysym)
|
2014-03-28 13:26:32 -07:00
|
|
|
{
|
2014-07-14 12:52:35 -07:00
|
|
|
ret.setUndefined();
|
2014-03-28 13:26:32 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2020-11-13 05:18:22 -08:00
|
|
|
JS::RootedValue keysymVal(rq.cx, JS::ObjectValue(*keysym));
|
|
|
|
|
JS_SetProperty(rq.cx, obj, "keysym", keysymVal);
|
2010-01-09 11:20:14 -08:00
|
|
|
|
2026-05-18 12:11:00 -07:00
|
|
|
// SET(keysym, "scancode", static_cast<int>(ev.key.keysym.scancode)); // (not in wsdl.h)
|
|
|
|
|
SET(keysym, "sym", static_cast<int>(ev.key.keysym.sym));
|
|
|
|
|
// SET(keysym, "mod", static_cast<int>(ev.key.keysym.mod)); // (not in wsdl.h)
|
2010-01-09 11:20:14 -08:00
|
|
|
{
|
2015-01-24 06:46:52 -08:00
|
|
|
SET(keysym, "unicode", JS::UndefinedHandleValue);
|
2010-01-09 11:20:14 -08:00
|
|
|
}
|
|
|
|
|
// TODO: scripts have no idea what all the key/mod enum values are;
|
|
|
|
|
// we should probably expose them as constants if we expect scripts to use them
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SDL_MOUSEMOTION:
|
|
|
|
|
{
|
2026-05-18 12:11:00 -07:00
|
|
|
// SET(obj, "which", static_cast<int>(ev.motion.which)); // (not in wsdl.h)
|
|
|
|
|
// SET(obj, "state", static_cast<int>(ev.motion.state)); // (not in wsdl.h)
|
|
|
|
|
SET(obj, "x", static_cast<int>(ev.motion.x));
|
|
|
|
|
SET(obj, "y", static_cast<int>(ev.motion.y));
|
|
|
|
|
// SET(obj, "xrel", static_cast<int>(ev.motion.xrel)); // (not in wsdl.h)
|
|
|
|
|
// SET(obj, "yrel", static_cast<int>(ev.motion.yrel)); // (not in wsdl.h)
|
2010-01-09 11:20:14 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
|
|
|
|
{
|
2026-05-18 12:11:00 -07:00
|
|
|
// SET(obj, "which", static_cast<int>(ev.button.which)); // (not in wsdl.h)
|
|
|
|
|
SET(obj, "button", static_cast<int>(ev.button.button));
|
|
|
|
|
SET(obj, "state", static_cast<int>(ev.button.state));
|
|
|
|
|
SET(obj, "x", static_cast<int>(ev.button.x));
|
|
|
|
|
SET(obj, "y", static_cast<int>(ev.button.y));
|
|
|
|
|
SET(obj, "clicks", static_cast<int>(ev.button.clicks));
|
2010-01-09 11:20:14 -08:00
|
|
|
break;
|
|
|
|
|
}
|
2021-03-31 08:50:25 -07:00
|
|
|
case SDL_HOTKEYPRESS:
|
2010-01-09 11:20:14 -08:00
|
|
|
case SDL_HOTKEYDOWN:
|
|
|
|
|
case SDL_HOTKEYUP:
|
2021-03-31 08:50:25 -07:00
|
|
|
case SDL_HOTKEYPRESS_SILENT:
|
|
|
|
|
case SDL_HOTKEYUP_SILENT:
|
2010-01-09 11:20:14 -08:00
|
|
|
{
|
2026-05-18 12:11:00 -07:00
|
|
|
SET(obj, "hotkey", static_cast<const char*>(ev.user.data1));
|
2010-01-09 11:20:14 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 12:52:35 -07:00
|
|
|
ret.setObject(*obj);
|
2010-01-09 11:20:14 -08:00
|
|
|
}
|
2010-08-21 16:58:08 -07:00
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> void Script::ToJSVal<IGUIObject*>(const Script::Request&, JS::MutableHandleValue ret,
|
2025-06-03 23:10:15 -07:00
|
|
|
IGUIObject* const& val)
|
2010-08-21 16:58:08 -07:00
|
|
|
{
|
2019-09-22 16:28:25 -07:00
|
|
|
if (val == nullptr)
|
2014-07-14 12:52:35 -07:00
|
|
|
ret.setNull();
|
2014-03-28 13:26:32 -07:00
|
|
|
else
|
2014-07-14 12:52:35 -07:00
|
|
|
ret.setObject(*val->GetJSObject());
|
2010-08-21 16:58:08 -07:00
|
|
|
}
|
2017-01-06 03:14:03 -08:00
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> bool Script::FromJSVal<IGUIObject*>(const Script::Request& rq, JS::HandleValue v, IGUIObject*& out)
|
2021-04-30 06:20:43 -07:00
|
|
|
{
|
|
|
|
|
if (!v.isObject())
|
|
|
|
|
{
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
Script::Exception::Raise(rq, "Value is not an IGUIObject.");
|
2021-04-30 06:20:43 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
out = IGUIProxyObject::FromPrivateSlot<IGUIObject>(v.toObjectOrNull());
|
|
|
|
|
if (!out)
|
|
|
|
|
{
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
Script::Exception::Raise(rq, "Value is not an IGUIObject.");
|
2021-04-30 06:20:43 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> void Script::ToJSVal<CGUIString>(const Script::Request& rq, JS::MutableHandleValue ret, const CGUIString& val)
|
2017-01-06 03:14:03 -08:00
|
|
|
{
|
2021-05-13 02:43:33 -07:00
|
|
|
Script::ToJSVal(rq, ret, val.GetOriginalString());
|
2017-01-06 03:14:03 -08:00
|
|
|
}
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> bool Script::FromJSVal<CGUIString>(const Script::Request& rq, JS::HandleValue v, CGUIString& out)
|
2017-01-06 03:14:03 -08:00
|
|
|
{
|
|
|
|
|
std::wstring val;
|
2020-11-13 05:18:22 -08:00
|
|
|
if (!FromJSVal(rq, v, val))
|
2017-01-06 03:14:03 -08:00
|
|
|
return false;
|
|
|
|
|
out.SetValue(val);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSVAL_VECTOR(CVector2D)
|
|
|
|
|
JSVAL_VECTOR(std::vector<CVector2D>)
|
|
|
|
|
JSVAL_VECTOR(CGUIString)
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> void Script::ToJSVal<CGUIColor>(const Script::Request& rq, JS::MutableHandleValue ret, const CGUIColor& val)
|
2019-07-26 11:57:28 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
ToJSVal<CColor>(rq, ret, val);
|
2019-07-26 11:57:28 -07:00
|
|
|
}
|
|
|
|
|
|
Delete wrongful proxy CGUIManager::GetPreDefinedColor from f0d9806b3f.
It is wrong because the predefined colors should be loaded from the GUI
page that requests to have the color parsed, which may be different from
the topmost page.
Similar to FindObjectByName removed in f9b529f2fb.
Achieve this by implementing the CGUISetting<CGUIColor>::FromJSVal
specialization, moved from ScriptInterface::FromJSVal<CGUIColor>,
instead of adding a CGUI pointer to CGUIColor.
Mark ScriptInterface::FromJSVal<GUIColor> and inherited
CColor::ParseString explicitly as deleted, so that people get a compile
error if they forget to check for predefined colors when parsing a
color.
Refs #5387, D1746 > D1684 > this > f9b529f2fb, 9be8a560a9, 415939b59b,
2c47fbd66a, 85a622b13a.
Differential Revision: https://code.wildfiregames.com/D2108
Tested on: clang 8, VS2015
This was SVN commit r22663.
2019-08-13 11:00:41 -07:00
|
|
|
/**
|
|
|
|
|
* The color depends on the predefined color database stored in the current GUI page.
|
|
|
|
|
*/
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> bool Script::FromJSVal<CGUIColor>(const Script::Request& rq, JS::HandleValue v, CGUIColor& out) = delete;
|
2019-07-26 11:57:28 -07:00
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> void Script::ToJSVal<CRect>(const Script::Request& rq, JS::MutableHandleValue ret, const CRect& val)
|
2019-09-04 09:15:37 -07:00
|
|
|
{
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::CreateObject(
|
2020-11-13 05:18:22 -08:00
|
|
|
rq,
|
2019-09-04 09:15:37 -07:00
|
|
|
ret,
|
|
|
|
|
"left", val.left,
|
|
|
|
|
"right", val.right,
|
|
|
|
|
"top", val.top,
|
|
|
|
|
"bottom", val.bottom);
|
|
|
|
|
}
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> void Script::ToJSVal<CGUIList>(const Script::Request& rq, JS::MutableHandleValue ret, const CGUIList& val)
|
2019-07-23 18:40:30 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
ToJSVal(rq, ret, val.m_Items);
|
2019-07-23 18:40:30 -07:00
|
|
|
}
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> bool Script::FromJSVal<CGUIList>(const Script::Request& rq, JS::HandleValue v, CGUIList& out)
|
2019-07-23 18:40:30 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
return FromJSVal(rq, v, out.m_Items);
|
2019-07-23 18:40:30 -07:00
|
|
|
}
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> void Script::ToJSVal<CGUISeries>(const Script::Request& rq, JS::MutableHandleValue ret, const CGUISeries& val)
|
2019-07-23 18:40:30 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
ToJSVal(rq, ret, val.m_Series);
|
2019-07-23 18:40:30 -07:00
|
|
|
}
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> bool Script::FromJSVal<CGUISeries>(const Script::Request& rq, JS::HandleValue v, CGUISeries& out)
|
2019-07-23 18:40:30 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
return FromJSVal(rq, v, out.m_Series);
|
2019-07-23 18:40:30 -07:00
|
|
|
}
|
2019-07-26 06:45:14 -07:00
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> void Script::ToJSVal<EVAlign>(const Script::Request& rq, JS::MutableHandleValue ret, const EVAlign& val)
|
2019-07-26 06:45:14 -07:00
|
|
|
{
|
|
|
|
|
std::string word;
|
|
|
|
|
switch (val)
|
|
|
|
|
{
|
2021-03-27 05:07:38 -07:00
|
|
|
case EVAlign::TOP:
|
2019-07-26 06:45:14 -07:00
|
|
|
word = "top";
|
|
|
|
|
break;
|
|
|
|
|
|
2021-03-27 05:07:38 -07:00
|
|
|
case EVAlign::BOTTOM:
|
2019-07-26 06:45:14 -07:00
|
|
|
word = "bottom";
|
|
|
|
|
break;
|
|
|
|
|
|
2021-03-27 05:07:38 -07:00
|
|
|
case EVAlign::CENTER:
|
2019-07-26 06:45:14 -07:00
|
|
|
word = "center";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
word = "error";
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
Script::Exception::Raise(rq, "Invalid EVAlign");
|
2019-07-26 06:45:14 -07:00
|
|
|
break;
|
|
|
|
|
}
|
2020-11-13 05:18:22 -08:00
|
|
|
ToJSVal(rq, ret, word);
|
2019-07-26 06:45:14 -07:00
|
|
|
}
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> bool Script::FromJSVal<EVAlign>(const Script::Request& rq, JS::HandleValue v, EVAlign& out)
|
2019-07-26 06:45:14 -07:00
|
|
|
{
|
|
|
|
|
std::string word;
|
2020-11-13 05:18:22 -08:00
|
|
|
FromJSVal(rq, v, word);
|
2019-07-26 06:45:14 -07:00
|
|
|
|
|
|
|
|
if (word == "top")
|
2021-03-27 05:07:38 -07:00
|
|
|
out = EVAlign::TOP;
|
2019-07-26 06:45:14 -07:00
|
|
|
else if (word == "bottom")
|
2021-03-27 05:07:38 -07:00
|
|
|
out = EVAlign::BOTTOM;
|
2019-07-26 06:45:14 -07:00
|
|
|
else if (word == "center")
|
2021-03-27 05:07:38 -07:00
|
|
|
out = EVAlign::CENTER;
|
2019-07-26 06:45:14 -07:00
|
|
|
else
|
|
|
|
|
{
|
2021-03-27 05:07:38 -07:00
|
|
|
out = EVAlign::TOP;
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
|
|
|
LOGERROR("Invalid alignment (should be 'left', 'right' or 'center')");
|
2019-07-26 06:45:14 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> void Script::ToJSVal<EAlign>(const Script::Request& rq, JS::MutableHandleValue ret, const EAlign& val)
|
2019-07-26 06:45:14 -07:00
|
|
|
{
|
|
|
|
|
std::string word;
|
|
|
|
|
switch (val)
|
|
|
|
|
{
|
2021-03-27 05:07:38 -07:00
|
|
|
case EAlign::LEFT:
|
2019-07-26 06:45:14 -07:00
|
|
|
word = "left";
|
|
|
|
|
break;
|
2021-03-27 05:07:38 -07:00
|
|
|
case EAlign::RIGHT:
|
2019-07-26 06:45:14 -07:00
|
|
|
word = "right";
|
|
|
|
|
break;
|
2021-03-27 05:07:38 -07:00
|
|
|
case EAlign::CENTER:
|
2019-07-26 06:45:14 -07:00
|
|
|
word = "center";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
word = "error";
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
Script::Exception::Raise(rq, "Invalid alignment (should be 'left', 'right' or 'center')");
|
2019-07-26 06:45:14 -07:00
|
|
|
break;
|
|
|
|
|
}
|
2020-11-13 05:18:22 -08:00
|
|
|
ToJSVal(rq, ret, word);
|
2019-07-26 06:45:14 -07:00
|
|
|
}
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> bool Script::FromJSVal<EAlign>(const Script::Request& rq, JS::HandleValue v, EAlign& out)
|
2019-07-26 06:45:14 -07:00
|
|
|
{
|
|
|
|
|
std::string word;
|
2020-11-13 05:18:22 -08:00
|
|
|
FromJSVal(rq, v, word);
|
2019-07-26 06:45:14 -07:00
|
|
|
|
|
|
|
|
if (word == "left")
|
2021-03-27 05:07:38 -07:00
|
|
|
out = EAlign::LEFT;
|
2019-07-26 06:45:14 -07:00
|
|
|
else if (word == "right")
|
2021-03-27 05:07:38 -07:00
|
|
|
out = EAlign::RIGHT;
|
2019-07-26 06:45:14 -07:00
|
|
|
else if (word == "center")
|
2021-03-27 05:07:38 -07:00
|
|
|
out = EAlign::CENTER;
|
2019-07-26 06:45:14 -07:00
|
|
|
else
|
|
|
|
|
{
|
2021-03-27 05:07:38 -07:00
|
|
|
out = EAlign::LEFT;
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
|
|
|
LOGERROR("Invalid alignment (should be 'left', 'right' or 'center')");
|
2019-07-26 06:45:14 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-07-28 15:40:58 -07:00
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> void Script::ToJSVal<EScrollOrientation>(const Script::Request& rq, JS::MutableHandleValue ret, const EScrollOrientation& val)
|
2024-10-19 11:17:30 -07:00
|
|
|
{
|
|
|
|
|
std::string word;
|
|
|
|
|
switch (val)
|
|
|
|
|
{
|
|
|
|
|
case EScrollOrientation::HORIZONTAL:
|
|
|
|
|
word = "horizontal";
|
|
|
|
|
break;
|
|
|
|
|
case EScrollOrientation::VERTICAL:
|
|
|
|
|
word = "vertical";
|
|
|
|
|
break;
|
|
|
|
|
case EScrollOrientation::BOTH:
|
|
|
|
|
word = "both";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
word = "error";
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
Script::Exception::Raise(rq, "Invalid scroll orientation (should be 'vertical', 'horizontal' or 'both')");
|
2024-10-19 11:17:30 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
ToJSVal(rq, ret, word);
|
|
|
|
|
}
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template <> bool Script::FromJSVal<EScrollOrientation>(const Script::Request& rq, JS::HandleValue v, EScrollOrientation& out)
|
2024-10-19 11:17:30 -07:00
|
|
|
{
|
|
|
|
|
std::string word;
|
|
|
|
|
FromJSVal(rq, v, word);
|
|
|
|
|
|
|
|
|
|
if (word == "horizontal")
|
|
|
|
|
out = EScrollOrientation::HORIZONTAL;
|
|
|
|
|
else if (word == "vertical")
|
|
|
|
|
out = EScrollOrientation::VERTICAL;
|
|
|
|
|
else if (word == "both")
|
|
|
|
|
out = EScrollOrientation::BOTH;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
out = EScrollOrientation::VERTICAL;
|
|
|
|
|
LOGERROR("Invalid scroll orientation (should be 'vertical', 'horizontal' or 'both')");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> void Script::ToJSVal<CGUISpriteInstance>(const Script::Request& rq, JS::MutableHandleValue ret, const CGUISpriteInstance& val)
|
2019-07-28 15:40:58 -07:00
|
|
|
{
|
2020-11-13 05:18:22 -08:00
|
|
|
ToJSVal(rq, ret, val.GetName());
|
2019-07-28 15:40:58 -07:00
|
|
|
}
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> bool Script::FromJSVal<CGUISpriteInstance>(const Script::Request& rq, JS::HandleValue v, CGUISpriteInstance& out)
|
2019-07-28 15:40:58 -07:00
|
|
|
{
|
|
|
|
|
std::string name;
|
2020-11-13 05:18:22 -08:00
|
|
|
if (!FromJSVal(rq, v, name))
|
2019-07-28 15:40:58 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
out.SetName(name);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-07-29 04:56:11 -07:00
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> void Script::ToJSVal<CSize2D>(const Script::Request& rq, JS::MutableHandleValue ret, const CSize2D& val)
|
2021-03-28 14:55:13 -07:00
|
|
|
{
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::CreateObject(rq, ret, "width", val.Width, "height", val.Height);
|
2021-03-28 14:55:13 -07:00
|
|
|
}
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> bool Script::FromJSVal<CSize2D>(const Script::Request& rq, JS::HandleValue v, CSize2D& out)
|
2021-03-28 14:55:13 -07:00
|
|
|
{
|
|
|
|
|
if (!v.isObject())
|
|
|
|
|
{
|
|
|
|
|
LOGERROR("CSize2D value must be an object!");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!FromJSProperty(rq, v, "width", out.Width))
|
|
|
|
|
{
|
|
|
|
|
LOGERROR("Failed to get CSize2D.Width property");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!FromJSProperty(rq, v, "height", out.Height))
|
|
|
|
|
{
|
|
|
|
|
LOGERROR("Failed to get CSize2D.Height property");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> void Script::ToJSVal<CVector2D>(const Script::Request& rq, JS::MutableHandleValue ret, const CVector2D& val)
|
2021-03-28 14:55:13 -07:00
|
|
|
{
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::CreateObject(rq, ret, "x", val.X, "y", val.Y);
|
2021-03-28 14:55:13 -07:00
|
|
|
}
|
|
|
|
|
|
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
2026-06-02 14:06:50 -07:00
|
|
|
template<> bool Script::FromJSVal<CVector2D>(const Script::Request& rq, JS::HandleValue v, CVector2D& out)
|
2021-03-28 14:55:13 -07:00
|
|
|
{
|
|
|
|
|
if (!v.isObject())
|
|
|
|
|
{
|
|
|
|
|
LOGERROR("CVector2D value must be an object!");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!FromJSProperty(rq, v, "x", out.X))
|
|
|
|
|
{
|
|
|
|
|
LOGERROR("Failed to get CVector2D.X property");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!FromJSProperty(rq, v, "y", out.Y))
|
|
|
|
|
{
|
|
|
|
|
LOGERROR("Failed to get CVector2D.Y property");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-29 04:56:11 -07:00
|
|
|
#undef SET
|