Index: build/premake/extern_libs5.lua =================================================================== --- build/premake/extern_libs5.lua +++ build/premake/extern_libs5.lua @@ -625,14 +625,14 @@ end else filter { "Debug", "action:vs*" } - links { "mozjs78-ps-debug" } - links { "mozjs78-ps-rust-debug" } + links { "mozjs91-ps-debug" } + links { "mozjs91-ps-rust-debug" } filter { "Debug", "action:not vs*" } - links { "mozjs78-ps-debug" } - links { "mozjs78-ps-rust" } + links { "mozjs91-ps-debug" } + links { "mozjs91-ps-rust" } filter { "Release" } - links { "mozjs78-ps-release" } - links { "mozjs78-ps-rust" } + links { "mozjs91-ps-release" } + links { "mozjs91-ps-rust" } filter { } add_source_lib_paths("spidermonkey") end Index: libraries/source/spidermonkey/FixMozglue.diff =================================================================== --- libraries/source/spidermonkey/FixMozglue.diff +++ libraries/source/spidermonkey/FixMozglue.diff @@ -1,47 +1,16 @@ -diff --git a/js/src/build/moz.build b/js/src/build/moz.build -index b311e9549fed..55f26497ec8d 100644 ---- a/js/src/build/moz.build -+++ b/js/src/build/moz.build -@@ -10,9 +10,7 @@ CONFIGURE_SUBST_FILES += [ - ] - - LIBRARY_DEFINES['EXPORT_JS_API'] = True -- --if not CONFIG['JS_STANDALONE']: -- LIBRARY_DEFINES['MOZ_HAS_MOZGLUE'] = True -+LIBRARY_DEFINES['MOZ_HAS_MOZGLUE'] = True - - # JavaScript must be built shared, even for static builds, as it is used by - # other modules which are always built shared. Failure to do so results in -diff --git a/mozglue/build/moz.build b/mozglue/build/moz.build -index ab0cff86fafc..d8bcead49deb 100644 ---- a/mozglue/build/moz.build -+++ b/mozglue/build/moz.build -@@ -9,6 +9,7 @@ - # If this is ever changed, update MOZ_SHARED_MOZGLUE in browser/installer/Makefile.in - if CONFIG['JS_STANDALONE'] and not CONFIG['MOZ_MEMORY']: - Library('mozglue') -+ FINAL_LIBRARY = 'js' - elif CONFIG['OS_TARGET'] in ('WINNT', 'Darwin', 'Android'): - SharedLibrary('mozglue') - else: -diff --git a/config/makefiles/target_binaries.mk b/config/makefiles/target_binaries.mk -index 31b2c4367e94..a7f9037dfd54 100644 -diff --git a/js/src/moz.build b/js/src/moz.build -index 9c2ab1e1ac18..7444259bca6a 100755 --- a/js/src/moz.build +++ b/js/src/moz.build -@@ -50,7 +50,12 @@ with Files('builtin/intl/*'): - if CONFIG['ENABLE_WASM_CRANELIFT']: - CONFIGURE_SUBST_FILES += ['rust/extra-bindgen-flags'] +@@ -50,9 +50,12 @@ + if CONFIG["ENABLE_WASM_CRANELIFT"]: + CONFIGURE_SUBST_FILES += ["rust/extra-bindgen-flags"] --if not CONFIG['JS_DISABLE_SHELL']: -+if CONFIG['JS_STANDALONE'] and CONFIG['JS_DISABLE_SHELL']: -+ DIRS += [ -+ 'rust', -+ ] ++DIRS += [ ++ "rust" ++] + -+elif not CONFIG['JS_DISABLE_SHELL']: + if not CONFIG["JS_DISABLE_SHELL"]: DIRS += [ - 'rust', - 'shell', +- "rust", + "shell", + ] + Index: libraries/source/spidermonkey/build.sh =================================================================== --- libraries/source/spidermonkey/build.sh +++ libraries/source/spidermonkey/build.sh @@ -3,10 +3,10 @@ set -e # This should match the version in config/milestone.txt -FOLDER="mozjs-78.6.0" +FOLDER="mozjs-91.5.0" # If same-version changes are needed, increment this. -LIB_VERSION="78.6.0+3" -LIB_NAME="mozjs78-ps" +LIB_VERSION="91.5.0+0" +LIB_NAME="mozjs91-ps" # Since this script is called by update-workspaces.sh, we want to quickly # avoid doing any work if SpiderMonkey is already built and up-to-date. @@ -33,6 +33,7 @@ # Standalone SpiderMonkey can not use jemalloc (see https://bugzilla.mozilla.org/show_bug.cgi?id=1465038) # Jitspew doesn't compile on VS17 in the zydis disassembler - since we don't use it, deactivate it. +# Trace-logging doesn't compile for now. CONF_OPTS="--disable-tests --disable-jemalloc --disable-js-shell @@ -40,6 +41,14 @@ --enable-shared-js --disable-jitspew" +if [ -n "$PROFILE" ]; then + CONF_OPTS="$CONF_OPTS --enable-profiling + --enable-perf + --enable-instruments + --enable-trace-logging + --with-jitreport-granularity=3" +fi + if [ "${OS}" = "Windows_NT" ] then CONF_OPTS="${CONF_OPTS} --with-visual-studio-version=2017 --target=i686" @@ -102,13 +111,13 @@ then # Delete the existing directory to avoid conflicts and extract the tarball rm -rf "$FOLDER" - if [ ! -e "${FOLDER}.tar.bz2" ]; + if [ ! -e "${FOLDER}.tar.xz" ]; then # The tarball is committed to svn, but it's useful to let jenkins download it (when testing upgrade scripts). - download="$(command -v wget || echo "curl -L -o "${FOLDER}.tar.bz2"")" - $download "https://github.com/wraitii/spidermonkey-tarballs/releases/download/v78.6.0/${FOLDER}.tar.bz2" + download="$(command -v wget || echo "curl -L -o "${FOLDER}.tar.xz"")" + $download "https://github.com/wraitii/spidermonkey-tarballs/releases/download/v78.6.0/${FOLDER}.tar.xz" fi - tar xjf "${FOLDER}.tar.bz2" + tar xjf "${FOLDER}.tar.xz" # Clean up header files that may be left over by earlier versions of SpiderMonkey rm -rf include-unix-debug @@ -117,8 +126,6 @@ # Apply patches cd "$FOLDER" . ../patch.sh - # Copy a more recent autoconf config.guess to handle ARM macs properly. - cp -f ../config.guess build/autoconf/ # Prevent complaining that configure is outdated. touch ./js/src/configure else @@ -129,10 +136,8 @@ if [ "$(uname -s)" != "FreeBSD" ]; then mkdir -p build-debug cd build-debug - # SM configure checks for autoconf, but we don't actually need it. - # To avoid a dependency, pass something arbitrary (it does need to be an actual program). # llvm-objdump is searched for with the complete name, not simply 'objdump', account for that. - CXXFLAGS="${CXXFLAGS}" ../js/src/configure AUTOCONF="ls" \ + CXXFLAGS="${CXXFLAGS}" ../js/src/configure \ LLVM_OBJDUMP="${LLVM_OBJDUMP}" \ ${CONF_OPTS} \ --enable-debug \ @@ -144,7 +149,7 @@ mkdir -p build-release cd build-release -CXXFLAGS="${CXXFLAGS}" ../js/src/configure AUTOCONF="ls" \ +CXXFLAGS="${CXXFLAGS}" ../js/src/configure \ LLVM_OBJDUMP="${LLVM_OBJDUMP}" \ ${CONF_OPTS} \ --enable-optimize Index: libraries/source/spidermonkey/patch.sh =================================================================== --- libraries/source/spidermonkey/patch.sh +++ libraries/source/spidermonkey/patch.sh @@ -6,41 +6,41 @@ # Unfortunately, 3.7 is mostly unavailable on ARM macs. # Therefore, replace the custom script with a more up-to-date version from pip # if python is detected to be newer than 3.7. -if [ "$(uname -s)" = "Darwin" ]; -then - PYTHON_MINOR_VERSION="$(python3 -c 'import sys; print(sys.version_info.minor)')" - if [ "$PYTHON_MINOR_VERSION" -gt 7 ]; - then - # SM actually uses features from the full-fledged virtualenv package - # and not just venv, so install it to be safe. - # Install it locally to not pollute anything. - pip3 install --upgrade -t virtualenv virtualenv - export PYTHONPATH="$(pwd)/virtualenv:$PYTHONPATH" - patch -p1 < ../FixVirtualEnv.diff - fi -fi +#if [ "$(uname -s)" = "Darwin" ]; +#then +# PYTHON_MINOR_VERSION="$(python3 -c 'import sys; print(sys.version_info.minor)')" +# if [ "$PYTHON_MINOR_VERSION" -gt 7 ]; +# then +# # SM actually uses features from the full-fledged virtualenv package +# # and not just venv, so install it to be safe. +# # Install it locally to not pollute anything. +# pip3 install --upgrade -t virtualenv virtualenv +# export PYTHONPATH="$(pwd)/virtualenv:$PYTHONPATH" +# patch -p1 < ../FixVirtualEnv.diff +# fi +#fi # Mozglue symbols need to be linked against static builds. # https://bugzilla.mozilla.org/show_bug.cgi?id=1588340 patch -p1 < ../FixMozglue.diff # Update library names to have separate debug/release libraries. -patch -p1 < ../RenameLibs.diff +# patch -p1 < ../RenameLibs.diff # Fix ~SharedArrayRawBufferRefs symbol not found. # See https://bugzilla.mozilla.org/show_bug.cgi?id=1644600 # Many thanks to bellaz89 for finding this and reporting it -patch -p1 < ../FixSharedArray.diff +# patch -p1 < ../FixSharedArray.diff # Fix public export on MSVC (C2487) # https://bugzilla.mozilla.org/show_bug.cgi?id=1614243 # (mentionned in the comments, no patch/commit found) -patch -p1 < ../FixPublicExport.diff +# patch -p1 < ../FixPublicExport.diff # Fix Rooted not working on VS17 # https://bugzilla.mozilla.org/show_bug.cgi?id=1679736 # (Landed in 85) -patch -p1 < ../FixMSVCRootedVoid.diff +# patch -p1 < ../FixMSVCRootedVoid.diff # Two SDK-related issues. # -ftrivial-auto-var-init is clang 8, @@ -50,24 +50,24 @@ # which is set to 10.15.4 in SM78. # Upstream has changed this to 10.11 at the moment, # so this patches it to an arbitrarily high Mac OS 11 -patch -p1 < ../FixMacBuild.diff +# patch -p1 < ../FixMacBuild.diff # Fix FP access breaking compilation on RPI3+ # https://bugzilla.mozilla.org/show_bug.cgi?id=1526653 # https://bugzilla.mozilla.org/show_bug.cgi?id=1536491 -patch -p1 < ../FixRpiUnalignedFpAccess.diff +# patch -p1 < ../FixRpiUnalignedFpAccess.diff # Bug 1684261 upstreamed from 78.8: https://hg.mozilla.org/releases/mozilla-esr78/rev/0e8f444683cb # Note that this isn't quite the upstream patch to match our version. -patch -p1 < ../FixRust150.diff +# patch -p1 < ../FixRust150.diff # Patch those separately, as they might interfere with normal behaviour. -if [ "$(uname -s)" = "FreeBSD" ]; -then - # https://svnweb.freebsd.org/ports/head/lang/spidermonkey78/files/patch-js_moz.configure?view=log - patch -p1 < ../FixFreeBSDReadlineDetection.diff - # https://svnweb.freebsd.org/ports/head/lang/spidermonkey78/files/patch-third__party_rust_cc_.cargo-checksum.json?view=log - patch -p1 < ../FixFreeBSDCargoChecksum.diff - # https://svnweb.freebsd.org/ports/head/lang/spidermonkey78/files/patch-third__party_rust_cc_src_lib.rs?view=log - patch -p1 < ../FixFreeBSDRustThirdPartyOSDetection.diff -fi +#if [ "$(uname -s)" = "FreeBSD" ]; +#then +# # https://svnweb.freebsd.org/ports/head/lang/spidermonkey78/files/patch-js_moz.configure?view=log +# patch -p1 < ../FixFreeBSDReadlineDetection.diff +# # https://svnweb.freebsd.org/ports/head/lang/spidermonkey78/files/patch-third__party_rust_cc_.cargo-checksum.json?view=log +# patch -p1 < ../FixFreeBSDCargoChecksum.diff +# # https://svnweb.freebsd.org/ports/head/lang/spidermonkey78/files/patch-third__party_rust_cc_src_lib.rs?view=log +# patch -p1 < ../FixFreeBSDRustThirdPartyOSDetection.diff +#fi Index: source/gui/Scripting/JSInterface_GUIProxy.h =================================================================== --- source/gui/Scripting/JSInterface_GUIProxy.h +++ source/gui/Scripting/JSInterface_GUIProxy.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -170,13 +170,13 @@ // The JS code will see undefined when querying a property descriptor. virtual bool getOwnPropertyDescriptor(JSContext* UNUSED(cx), JS::HandleObject UNUSED(proxy), JS::HandleId UNUSED(id), - JS::MutableHandle UNUSED(desc)) const override + JS::MutableHandle> desc) const override { return true; } // Throw an exception is JS code attempts defining a property. virtual bool defineProperty(JSContext* UNUSED(cx), JS::HandleObject UNUSED(proxy), JS::HandleId UNUSED(id), - JS::Handle UNUSED(desc), JS::ObjectOpResult& UNUSED(result)) const override + JS::Handle UNUSED(desc), JS::ObjectOpResult& UNUSED(result)) const override { return false; } Index: source/gui/Scripting/JSInterface_GUIProxy_impl.h =================================================================== --- source/gui/Scripting/JSInterface_GUIProxy_impl.h +++ source/gui/Scripting/JSInterface_GUIProxy_impl.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -88,7 +88,7 @@ { if (!obj) return nullptr; - if (JS_GetClass(obj) != &JSInterface_GUIProxy::ClassDefinition()) + if (JS::GetClass(obj) != &JSInterface_GUIProxy::ClassDefinition()) return nullptr; return UnsafeFromPrivateSlot(obj); } Index: source/scriptinterface/ScriptContext.cpp =================================================================== --- source/scriptinterface/ScriptContext.cpp +++ source/scriptinterface/ScriptContext.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -107,7 +107,8 @@ JS::SetGCSliceCallback(m_cx, GCSliceCallbackHook); JS_SetGCParameter(m_cx, JSGC_MAX_BYTES, m_ContextSize); - JS_SetGCParameter(m_cx, JSGC_MODE, JSGC_MODE_INCREMENTAL); + JS_SetGCParameter(m_cx, JSGC_INCREMENTAL_GC_ENABLED, true); + JS_SetGCParameter(m_cx, JSGC_PER_ZONE_GC_ENABLED, false); JS_SetOffthreadIonCompilationEnabled(m_cx, true); @@ -143,7 +144,7 @@ // Schedule the zone for GC, which will destroy the realm. if (JS::IsIncrementalGCInProgress(m_cx)) JS::FinishIncrementalGC(m_cx, JS::GCReason::API); - JS::PrepareZoneForGC(js::GetRealmZone(realm)); + JS::PrepareZoneForGC(m_cx, js::GetRealmZone(realm)); m_Realms.remove(realm); } @@ -241,7 +242,7 @@ #endif PrepareZonesForIncrementalGC(); if (!JS::IsIncrementalGCInProgress(m_cx)) - JS::StartIncrementalGC(m_cx, GC_NORMAL, JS::GCReason::API, GCSliceTimeBudget); + JS::StartIncrementalGC(m_cx, JS::GCOptions::Normal, JS::GCReason::API, GCSliceTimeBudget); else JS::IncrementalGCSlice(m_cx, JS::GCReason::API, GCSliceTimeBudget); } @@ -252,14 +253,16 @@ void ScriptContext::ShrinkingGC() { - JS_SetGCParameter(m_cx, JSGC_MODE, JSGC_MODE_ZONE); + JS_SetGCParameter(m_cx, JSGC_INCREMENTAL_GC_ENABLED, false); + JS_SetGCParameter(m_cx, JSGC_PER_ZONE_GC_ENABLED, true); JS::PrepareForFullGC(m_cx); - JS::NonIncrementalGC(m_cx, GC_SHRINK, JS::GCReason::API); - JS_SetGCParameter(m_cx, JSGC_MODE, JSGC_MODE_INCREMENTAL); + JS::NonIncrementalGC(m_cx, JS::GCOptions::Shrink, JS::GCReason::API); + JS_SetGCParameter(m_cx, JSGC_INCREMENTAL_GC_ENABLED, true); + JS_SetGCParameter(m_cx, JSGC_PER_ZONE_GC_ENABLED, false); } void ScriptContext::PrepareZonesForIncrementalGC() const { for (JS::Realm* const& realm : m_Realms) - JS::PrepareZoneForGC(js::GetRealmZone(realm)); + JS::PrepareZoneForGC(m_cx, js::GetRealmZone(realm)); } Index: source/scriptinterface/ScriptConversions.cpp =================================================================== --- source/scriptinterface/ScriptConversions.cpp +++ source/scriptinterface/ScriptConversions.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -105,7 +105,7 @@ if (!str) FAIL("Argument must be convertible to a string"); - if (JS_StringHasLatin1Chars(str)) + if (JS::StringHasLatin1Chars(str)) { size_t length; JS::AutoCheckCannotGC nogc; Index: source/scriptinterface/ScriptExtraHeaders.h =================================================================== --- source/scriptinterface/ScriptExtraHeaders.h +++ source/scriptinterface/ScriptExtraHeaders.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -60,6 +60,10 @@ #include "js/Proxy.h" #include "js/Warnings.h" +#include "js/experimental/TypedData.h" + +#include "js/friend/ErrorMessages.h" + #undef signbit #if MSC_VERSION Index: source/scriptinterface/ScriptInterface.cpp =================================================================== --- source/scriptinterface/ScriptInterface.cpp +++ source/scriptinterface/ScriptInterface.cpp @@ -508,11 +508,11 @@ return false; if (found) { - JS::Rooted desc(rq.cx); - if (!JS_GetOwnPropertyDescriptor(rq.cx, global, name, &desc)) + JS::Rooted> desc(rq.cx); + if (!JS_GetOwnPropertyDescriptor(rq.cx, global, name, &desc) || !desc.isSome()) return false; - if (!desc.writable()) + if (!desc->writable()) { if (!replace) { @@ -522,7 +522,7 @@ // This is not supposed to happen, unless the user has called SetProperty with constant = true on the global object // instead of using SetGlobal. - if (!desc.configurable()) + if (!desc->configurable()) { ScriptException::Raise(rq, "The global \"%s\" is permanent and cannot be hotloaded", name); return false; Index: source/scriptinterface/ScriptTypes.h =================================================================== --- source/scriptinterface/ScriptTypes.h +++ source/scriptinterface/ScriptTypes.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2020 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -73,7 +73,7 @@ # pragma GCC diagnostic pop #endif -#if MOZJS_MAJOR_VERSION != 78 +#if MOZJS_MAJOR_VERSION != 91 #error Your compiler is trying to use an incorrect major version of the \ SpiderMonkey library. The only version that works is the one in the \ libraries/spidermonkey/ directory, and it will not work with a typical \ @@ -81,7 +81,7 @@ include paths. #endif -#if MOZJS_MINOR_VERSION != 6 +#if MOZJS_MINOR_VERSION != 5 #error Your compiler is trying to use an untested minor version of the \ SpiderMonkey library. If you are a package maintainer, please make sure \ to check very carefully that this version does not change the behaviour \ Index: source/simulation2/scripting/EngineScriptConversions.cpp =================================================================== --- source/simulation2/scripting/EngineScriptConversions.cpp +++ source/simulation2/scripting/EngineScriptConversions.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -62,7 +62,7 @@ return; } - JS_SetPrivate(obj, static_cast(val)); + JS::SetPrivate(obj, static_cast(val)); ret.setObject(*obj); } Index: source/simulation2/serialization/BinarySerializer.cpp =================================================================== --- source/simulation2/serialization/BinarySerializer.cpp +++ source/simulation2/serialization/BinarySerializer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -219,9 +219,9 @@ else { // Find type of object - const JSClass* jsclass = JS_GetClass(obj); + const JSClass* jsclass = JS::GetClass(obj); if (!jsclass) - throw PSERROR_Serialize_ScriptError("JS_GetClass failed"); + throw PSERROR_Serialize_ScriptError("JS::GetClass failed"); JSProtoKey protokey = JSCLASS_CACHED_PROTO_KEY(jsclass); @@ -321,10 +321,11 @@ JS::RootedValue propval(rq.cx); // Forbid getters, which might delete values and mess things up. - JS::Rooted desc(rq.cx); - if (!JS_GetPropertyDescriptorById(rq.cx, obj, id, &desc)) + JS::Rooted> desc(rq.cx); + JS::RootedObject holder(rq.cx); + if (!JS_GetPropertyDescriptorById(rq.cx, obj, id, &desc, &holder)) throw PSERROR_Serialize_ScriptError("JS_GetPropertyDescriptorById failed"); - if (desc.hasGetterObject()) + if (desc.isSome() && desc->hasGetter()) throw PSERROR_Serialize_ScriptError("Cannot serialize property getters"); // Get the property name as a string @@ -354,7 +355,7 @@ JS::RootedString string(rq.cx, JS_GetFunctionId(func)); if (string) { - if (JS_StringHasLatin1Chars(string)) + if (JS::StringHasLatin1Chars(string)) { size_t length; JS::AutoCheckCannotGC nogc; @@ -440,7 +441,7 @@ size_t length; JS::AutoCheckCannotGC nogc; // Serialize strings directly as UTF-16 or Latin1, to avoid expensive encoding conversions - bool isLatin1 = JS_StringHasLatin1Chars(string); + bool isLatin1 = JS::StringHasLatin1Chars(string); m_Serializer.Bool("isLatin1", isLatin1); if (isLatin1) {