From 227957cd99faad753632e24af5ba2c7d4bd603f7 Mon Sep 17 00:00:00 2001 From: elexis Date: Tue, 23 Jul 2019 01:24:49 +0000 Subject: [PATCH] Delete unused broken JSI_IGUIObject::construct. The constructor is invalid, because one cannot create or obtain and pass an IGUIObject C++ class instance pointer via JS, only triggering a crash when doing something with it. If there was a use case, the GUIObject should be created with a GUIObject type specific constructor. Remove obsolete getProperty comments. From D1699, refs #5369 and wraitiis equivalent: Differential Revision: https://code.wildfiregames.com/D1933 This was SVN commit r22530. --- .../gui/scripting/JSInterface_IGUIObject.cpp | 33 ++----------------- source/gui/scripting/JSInterface_IGUIObject.h | 1 - 2 files changed, 3 insertions(+), 31 deletions(-) diff --git a/source/gui/scripting/JSInterface_IGUIObject.cpp b/source/gui/scripting/JSInterface_IGUIObject.cpp index 49c058866e..2054a85cf5 100644 --- a/source/gui/scripting/JSInterface_IGUIObject.cpp +++ b/source/gui/scripting/JSInterface_IGUIObject.cpp @@ -36,7 +36,7 @@ JSClass JSI_IGUIObject::JSI_class = { nullptr, nullptr, JSI_IGUIObject::getProperty, JSI_IGUIObject::setProperty, nullptr, nullptr, nullptr, nullptr, - nullptr, nullptr, JSI_IGUIObject::construct, nullptr + nullptr, nullptr, nullptr, nullptr }; JSFunctionSpec JSI_IGUIObject::JSI_methods[] = @@ -66,11 +66,7 @@ bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::Handle if (!ScriptInterface::FromJSVal(cx, idval, propName)) return false; - // Skip some things which are known to be functions rather than properties. - // ("constructor" *must* be here, else it'll try to GetSettingType before - // the private IGUIObject* has been set (and thus crash). The others are - // partly for efficiency, and also to allow correct reporting of attempts to - // access nonexistent properties.) + // Skip registered functions and inherited properties if (propName == "constructor" || propName == "prototype" || propName == "toString" || @@ -602,32 +598,9 @@ bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::Handle return !JS_IsExceptionPending(cx); } - -bool JSI_IGUIObject::construct(JSContext* cx, uint argc, JS::Value* vp) -{ - JSAutoRequest rq(cx); - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; - - if (args.length() == 0) - { - JS_ReportError(cx, "GUIObject has no default constructor"); - return false; - } - - JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUIObject")); - - // Store the IGUIObject in the JS object's 'private' area - IGUIObject* guiObject = (IGUIObject*)args[0].get().toPrivate(); - JS_SetPrivate(obj, guiObject); - - args.rval().setObject(*obj); - return true; -} - void JSI_IGUIObject::init(ScriptInterface& scriptInterface) { - scriptInterface.DefineCustomObjectType(&JSI_class, construct, 1, nullptr, JSI_methods, nullptr, nullptr); + scriptInterface.DefineCustomObjectType(&JSI_class, nullptr, 1, nullptr, JSI_methods, nullptr, nullptr); } bool JSI_IGUIObject::toString(JSContext* cx, uint UNUSED(argc), JS::Value* vp) diff --git a/source/gui/scripting/JSInterface_IGUIObject.h b/source/gui/scripting/JSInterface_IGUIObject.h index dbae6d7a6d..5649db0fdd 100644 --- a/source/gui/scripting/JSInterface_IGUIObject.h +++ b/source/gui/scripting/JSInterface_IGUIObject.h @@ -26,7 +26,6 @@ namespace JSI_IGUIObject extern JSFunctionSpec JSI_methods[]; 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 construct(JSContext* cx, uint argc, JS::Value* vp); bool toString(JSContext* cx, uint argc, JS::Value* vp); bool focus(JSContext* cx, uint argc, JS::Value* vp); bool blur(JSContext* cx, uint argc, JS::Value* vp);