Index: ps/trunk/source/gui/scripting/JSInterface_GUITypes.cpp =================================================================== --- ps/trunk/source/gui/scripting/JSInterface_GUITypes.cpp +++ ps/trunk/source/gui/scripting/JSInterface_GUITypes.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -33,7 +33,7 @@ JSFunctionSpec JSI_GUISize::JSI_methods[] = { - JS_FS("toString", JSI_GUISize::toString, 0, 0), + JS_FN("toString", JSI_GUISize::toString, 0, 0), JS_FS_END }; @@ -57,7 +57,7 @@ } else if (args.length() == 4) { - JS::RootedValue zero(cx, JSVAL_ZERO); + JS::RootedValue zero(cx, JS::NumberValue(0)); JS_SetProperty(cx, obj, "left", args[0]); JS_SetProperty(cx, obj, "top", args[1]); JS_SetProperty(cx, obj, "right", args[2]); @@ -69,7 +69,7 @@ } else { - JS::RootedValue zero(cx, JSVAL_ZERO); + JS::RootedValue zero(cx, JS::NumberValue(0)); JS_SetProperty(cx, obj, "left", zero); JS_SetProperty(cx, obj, "top", zero); JS_SetProperty(cx, obj, "right", zero); @@ -141,7 +141,7 @@ JSFunctionSpec JSI_GUIColor::JSI_methods[] = { - JS_FS("toString", JSI_GUIColor::toString, 0, 0), + JS_FN("toString", JSI_GUIColor::toString, 0, 0), JS_FS_END }; @@ -210,7 +210,7 @@ JSFunctionSpec JSI_GUIMouse::JSI_methods[] = { - JS_FS("toString", JSI_GUIMouse::toString, 0, 0), + JS_FN("toString", JSI_GUIMouse::toString, 0, 0), JS_FS_END }; Index: ps/trunk/source/gui/scripting/JSInterface_IGUIObject.h =================================================================== --- ps/trunk/source/gui/scripting/JSInterface_IGUIObject.h +++ ps/trunk/source/gui/scripting/JSInterface_IGUIObject.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -23,7 +23,6 @@ namespace JSI_IGUIObject { extern JSClass JSI_class; - extern JSPropertySpec JSI_props[]; 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); Index: ps/trunk/source/gui/scripting/JSInterface_IGUIObject.cpp =================================================================== --- ps/trunk/source/gui/scripting/JSInterface_IGUIObject.cpp +++ ps/trunk/source/gui/scripting/JSInterface_IGUIObject.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -39,17 +39,12 @@ nullptr, nullptr, JSI_IGUIObject::construct, nullptr }; -JSPropertySpec JSI_IGUIObject::JSI_props[] = -{ - { 0 } -}; - JSFunctionSpec JSI_IGUIObject::JSI_methods[] = { - JS_FS("toString", JSI_IGUIObject::toString, 0, 0), - JS_FS("focus", JSI_IGUIObject::focus, 0, 0), - JS_FS("blur", JSI_IGUIObject::blur, 0, 0), - JS_FS("getComputedSize", JSI_IGUIObject::getComputedSize, 0, 0), + JS_FN("toString", JSI_IGUIObject::toString, 0, 0), + JS_FN("focus", JSI_IGUIObject::focus, 0, 0), + JS_FN("blur", JSI_IGUIObject::blur, 0, 0), + JS_FN("getComputedSize", JSI_IGUIObject::getComputedSize, 0, 0), JS_FS_END }; @@ -635,7 +630,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, nullptr, JSI_methods, nullptr, nullptr); } bool JSI_IGUIObject::toString(JSContext* cx, uint UNUSED(argc), JS::Value* vp) Index: ps/trunk/source/ps/GameSetup/GameSetup.cpp =================================================================== --- ps/trunk/source/ps/GameSetup/GameSetup.cpp +++ ps/trunk/source/ps/GameSetup/GameSetup.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -183,8 +183,8 @@ // display progress / description in loading screen void GUI_DisplayLoadProgress(int percent, const wchar_t* pending_task) { - g_GUI->GetActiveGUI()->GetScriptInterface()->SetGlobal("g_Progress", percent, true); - g_GUI->GetActiveGUI()->GetScriptInterface()->SetGlobal("g_LoadDescription", pending_task, true); + g_GUI->GetActiveGUI()->GetScriptInterface()->SetGlobal("g_Progress", percent, true, false, true); + g_GUI->GetActiveGUI()->GetScriptInterface()->SetGlobal("g_LoadDescription", pending_task, true, false, true); g_GUI->GetActiveGUI()->SendEventToAll("progress"); } Index: ps/trunk/source/ps/VisualReplay.cpp =================================================================== --- ps/trunk/source/ps/VisualReplay.cpp +++ ps/trunk/source/ps/VisualReplay.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -328,7 +328,7 @@ const OsPath replayFile = GetDirectoryName() / directory / L"commands.txt"; if (!FileExists(replayFile)) - return JSVAL_NULL; + return JS::NullValue(); // Get file size and modification date CFileInfo fileInfo; @@ -336,7 +336,7 @@ const off_t fileSize = fileInfo.Size(); if (fileSize == 0) - return JSVAL_NULL; + return JS::NullValue(); std::ifstream* replayStream = new std::ifstream(OsString(replayFile).c_str()); @@ -345,14 +345,14 @@ { LOGERROR("Couldn't open %s.", replayFile.string8().c_str()); SAFE_DELETE(replayStream); - return JSVAL_NULL; + return JS::NullValue(); } if (type != "start") { LOGWARNING("The replay %s doesn't begin with 'start'!", replayFile.string8().c_str()); SAFE_DELETE(replayStream); - return JSVAL_NULL; + return JS::NullValue(); } // Parse header / first line @@ -365,14 +365,14 @@ { LOGERROR("Couldn't parse replay header of %s", replayFile.string8().c_str()); SAFE_DELETE(replayStream); - return JSVAL_NULL; + return JS::NullValue(); } // Ensure "turn" after header if (!(*replayStream >> type).good() || type != "turn") { SAFE_DELETE(replayStream); - return JSVAL_NULL; // there are no turns at all + return JS::NullValue(); // there are no turns at all } // Don't process files of rejoined clients @@ -381,7 +381,7 @@ if (turn != 0) { SAFE_DELETE(replayStream); - return JSVAL_NULL; + return JS::NullValue(); } int duration = getReplayDuration(replayStream, replayFile, fileSize); @@ -390,7 +390,7 @@ // Ensure minimum duration if (duration < minimumReplayDuration) - return JSVAL_NULL; + return JS::NullValue(); // Return the actual data JS::RootedValue replayData(cx); @@ -497,7 +497,7 @@ JS::Value VisualReplay::GetReplayMetadata(ScriptInterface::CxPrivate* pCxPrivate, const OsPath& directoryName) { if (!HasReplayMetadata(directoryName)) - return JSVAL_NULL; + return JS::NullValue(); JSContext* cx = pCxPrivate->pScriptInterface->GetContext(); JSAutoRequest rq(cx); Index: ps/trunk/source/ps/scripting/JSInterface_VFS.cpp =================================================================== --- ps/trunk/source/ps/scripting/JSInterface_VFS.cpp +++ ps/trunk/source/ps/scripting/JSInterface_VFS.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -99,7 +99,7 @@ BuildDirEntListState state(cx); vfs::ForEachFile(g_VFS, path, BuildDirEntListCB, (uintptr_t)&state, filter, flags); - return OBJECT_TO_JSVAL(state.filename_array); + return JS::ObjectValue(*state.filename_array); } // Return true iff the file exits @@ -157,7 +157,7 @@ CVFSFile file; if (file.Load(g_VFS, filename) != PSRETURN_OK) - return JSVAL_NULL; + return JS::NullValue(); CStr contents = file.DecodeUTF8(); // assume it's UTF-8 Index: ps/trunk/source/scriptinterface/ScriptInterface.h =================================================================== --- ps/trunk/source/scriptinterface/ScriptInterface.h +++ ps/trunk/source/scriptinterface/ScriptInterface.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -142,7 +142,7 @@ * to set an already-defined value will fail. */ template - bool SetGlobal(const char* name, const T& value, bool replace = false); + bool SetGlobal(const char* name, const T& value, bool replace = false, bool constant = true, bool enumerate = true); /** * Set the named property on the given object. @@ -362,7 +362,7 @@ bool CallFunction_(JS::HandleValue val, const char* name, JS::HandleValueArray argv, JS::MutableHandleValue ret) const; bool Eval_(const char* code, JS::MutableHandleValue ret) const; bool Eval_(const wchar_t* code, JS::MutableHandleValue ret) const; - bool SetGlobal_(const char* name, JS::HandleValue value, bool replace); + bool SetGlobal_(const char* name, JS::HandleValue value, bool replace, bool constant, bool enumerate); bool SetProperty_(JS::HandleValue obj, const char* name, JS::HandleValue value, bool readonly, bool enumerate) const; bool SetProperty_(JS::HandleValue obj, const wchar_t* name, JS::HandleValue value, bool readonly, bool enumerate) const; bool SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleValue value, bool readonly, bool enumerate) const; @@ -488,12 +488,12 @@ } template -bool ScriptInterface::SetGlobal(const char* name, const T& value, bool replace) +bool ScriptInterface::SetGlobal(const char* name, const T& value, bool replace, bool constant, bool enumerate) { JSAutoRequest rq(GetContext()); JS::RootedValue val(GetContext()); AssignOrToJSVal(GetContext(), &val, value); - return SetGlobal_(name, val, replace); + return SetGlobal_(name, val, replace, constant, enumerate); } template Index: ps/trunk/source/scriptinterface/ScriptInterface.cpp =================================================================== --- ps/trunk/source/scriptinterface/ScriptInterface.cpp +++ ps/trunk/source/scriptinterface/ScriptInterface.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -86,7 +86,6 @@ void ErrorReporter(JSContext* cx, const char* message, JSErrorReport* report) { - std::stringstream msg; bool isWarning = JSREPORT_IS_WARNING(report->flags); msg << (isWarning ? "JavaScript warning: " : "JavaScript error: "); @@ -364,10 +363,11 @@ JS_SetGlobalJitCompilerOption(m_runtime->m_rt, JSJITCOMPILER_ION_ENABLE, 1); JS_SetGlobalJitCompilerOption(m_runtime->m_rt, JSJITCOMPILER_BASELINE_ENABLE, 1); - JS::RuntimeOptionsRef(m_cx).setExtraWarnings(1) - .setWerror(0) - .setVarObjFix(1) - .setStrictMode(1); + JS::RuntimeOptionsRef(m_cx) + .setExtraWarnings(true) + .setWerror(false) + .setVarObjFix(true) + .setStrictMode(true); JS::CompartmentOptions opt; opt.setVersion(JSVERSION_LATEST); @@ -602,7 +602,7 @@ return JS::ObjectValue(*JS::CurrentGlobalOrNull(m->m_cx)); } -bool ScriptInterface::SetGlobal_(const char* name, JS::HandleValue value, bool replace) +bool ScriptInterface::SetGlobal_(const char* name, JS::HandleValue value, bool replace, bool constant, bool enumerate) { JSAutoRequest rq(m->m_cx); JS::RootedObject global(m->m_cx, m->m_glob); @@ -618,9 +618,13 @@ } } - bool ok = JS_DefineProperty(m->m_cx, global, name, value, JSPROP_ENUMERATE | JSPROP_READONLY - | JSPROP_PERMANENT); - return ok; + uint attrs = 0; + if (constant) + attrs |= JSPROP_READONLY | JSPROP_PERMANENT; + if (enumerate) + attrs |= JSPROP_ENUMERATE; + + return JS_DefineProperty(m->m_cx, global, name, value, attrs); } bool ScriptInterface::SetProperty_(JS::HandleValue obj, const char* name, JS::HandleValue value, bool constant, bool enumerate) const Index: ps/trunk/source/simulation2/scripting/MessageTypeConversions.cpp =================================================================== --- ps/trunk/source/simulation2/scripting/MessageTypeConversions.cpp +++ ps/trunk/source/simulation2/scripting/MessageTypeConversions.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -291,7 +291,7 @@ SET_MSG_PROPERTY(j0); SET_MSG_PROPERTY(i1); SET_MSG_PROPERTY(j1); - return OBJECT_TO_JSVAL(obj); + return JS::ObjectValue(*obj); } CMessage* CMessageTerrainChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) @@ -331,7 +331,7 @@ JS::Value CMessageWaterChanged::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); - return OBJECT_TO_JSVAL(obj); + return JS::ObjectValue(*obj); } CMessage* CMessageWaterChanged::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) Index: ps/trunk/source/simulation2/serialization/StdDeserializer.cpp =================================================================== --- ps/trunk/source/simulation2/serialization/StdDeserializer.cpp +++ ps/trunk/source/simulation2/serialization/StdDeserializer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -167,12 +167,7 @@ if (!proto) throw PSERROR_Deserialize_ScriptError("Failed to find serializable prototype for object"); - JS::RootedObject parent(cx, JS_GetParent(proto)); - if (!proto || !parent) - throw PSERROR_Deserialize_ScriptError(); - - // TODO: Remove support for parent since this is dropped upstream SpiderMonkey - obj.set(JS_NewObjectWithGivenProto(cx, nullptr, proto, parent)); + obj.set(JS_NewObjectWithGivenProto(cx, nullptr, proto)); if (!obj) throw PSERROR_Deserialize_ScriptError("JS_NewObject failed");