Changeset View
Changeset View
Standalone View
Standalone View
source/gui/Scripting/JSInterface_GUIProxy_impl.h
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2022 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 | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 13 Lines | |||||
#include "gui/CGUISetting.h" | #include "gui/CGUISetting.h" | ||||
#include "gui/ObjectBases/IGUIObject.h" | #include "gui/ObjectBases/IGUIObject.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "scriptinterface/FunctionWrapper.h" | #include "scriptinterface/FunctionWrapper.h" | ||||
#include "scriptinterface/ScriptExtraHeaders.h" | #include "scriptinterface/ScriptExtraHeaders.h" | ||||
#include "scriptinterface/ScriptRequest.h" | #include "scriptinterface/ScriptRequest.h" | ||||
#include <string> | #include <string> | ||||
#include <string_view> | |||||
template <typename T> | template <typename T> | ||||
JSI_GUIProxy<T>& JSI_GUIProxy<T>::Singleton() | JSI_GUIProxy<T>& JSI_GUIProxy<T>::Singleton() | ||||
{ | { | ||||
static JSI_GUIProxy<T> s; | static JSI_GUIProxy<T> s; | ||||
return s; | return s; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 263 Lines • ▼ Show 20 Lines | bool JSI_GUIProxy<T>::delete_(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, JS::ObjectOpResult& result) const | ||||
if (!JS_IdToValue(rq.cx, id, &idval)) | if (!JS_IdToValue(rq.cx, id, &idval)) | ||||
return result.fail(JSMSG_BAD_PROP_ID); | return result.fail(JSMSG_BAD_PROP_ID); | ||||
std::string propName; | std::string propName; | ||||
if (!Script::FromJSVal(rq, idval, propName)) | if (!Script::FromJSVal(rq, idval, propName)) | ||||
return result.fail(JSMSG_BAD_PROP_ID); | return result.fail(JSMSG_BAD_PROP_ID); | ||||
// event handlers | // event handlers | ||||
if (propName.substr(0, 2) == "on") | if (std::string_view{propName}.substr(0, 2) == "on") | ||||
{ | { | ||||
CStr eventName(propName.substr(2)); | CStr eventName(propName.substr(2)); | ||||
e->UnsetScriptHandler(eventName); | e->UnsetScriptHandler(eventName); | ||||
return result.succeed(); | return result.succeed(); | ||||
} | } | ||||
LOGERROR("Only event handlers can be deleted from GUI objects!"); | LOGERROR("Only event handlers can be deleted from GUI objects!"); | ||||
return result.fail(JSMSG_BAD_PROP_ID); | return result.fail(JSMSG_BAD_PROP_ID); | ||||
} | } |
Wildfire Games · Phabricator