Index: binaries/data/mods/public/globalscripts/vector.js =================================================================== --- binaries/data/mods/public/globalscripts/vector.js +++ binaries/data/mods/public/globalscripts/vector.js @@ -430,7 +430,12 @@ return new Vector3D(v.x / f, v.y / f, v.z / f); }; +// This is a workaround that is prone to break. The easiest +// way to remove it would be to create the prototype in C++. +// If the prototype has to be moddable, explain it at the top +// of the file and find a way to remove the workaround. +// https://trac.wildfiregames.com/ticket/5376 // make the prototypes easily accessible to C++ -const Vector2Dprototype = Vector2D.prototype; -const Vector3Dprototype = Vector3D.prototype; +this["Vector2Dprototype"] = Vector2D.prototype; +this["Vector3Dprototype"] = Vector3D.prototype; Index: build/premake/extern_libs5.lua =================================================================== --- build/premake/extern_libs5.lua +++ build/premake/extern_libs5.lua @@ -572,9 +572,9 @@ }, spidermonkey = { compile_settings = function() - if _OPTIONS["with-system-mozjs38"] then + if _OPTIONS["with-system-mozjs45"] then if not _OPTIONS["android"] then - pkgconfig.add_includes("mozjs-38") + pkgconfig.add_includes("mozjs-45") end else if os.istarget("windows") then @@ -592,31 +592,25 @@ end end, link_settings = function() - if _OPTIONS["with-system-mozjs38"] then + if _OPTIONS["with-system-mozjs45"] then if _OPTIONS["android"] then - links { "mozjs-38" } + links { "mozjs-45" } else - pkgconfig.add_links("nspr") - pkgconfig.add_links("mozjs-38") + pkgconfig.add_links("mozjs-45") end else - if os.istarget("macosx") then - add_default_lib_paths("nspr") - links { "nspr4", "plc4", "plds4" } - end - filter { "Debug", "action:vs2013" } - links { "mozjs38-ps-debug-vc120" } + links { "mozjs45-ps-debug-vc120" } filter { "Release", "action:vs2013" } - links { "mozjs38-ps-release-vc120" } + links { "mozjs45-ps-release-vc120" } filter { "Debug", "action:vs2015" } - links { "mozjs38-ps-debug-vc140" } + links { "mozjs45-ps-debug-vc140" } filter { "Release", "action:vs2015" } - links { "mozjs38-ps-release-vc140" } + links { "mozjs45-ps-release-vc140" } filter { "Debug", "action:not vs*" } - links { "mozjs38-ps-debug" } + links { "mozjs45-ps-debug" } filter { "Release", "action:not vs*" } - links { "mozjs38-ps-release" } + links { "mozjs45-ps-release" } filter { } add_source_lib_paths("spidermonkey") end Index: libraries/osx/build-osx-libs.sh =================================================================== --- libraries/osx/build-osx-libs.sh +++ libraries/osx/build-osx-libs.sh @@ -38,8 +38,6 @@ NETTLE_VERSION="nettle-3.4" GNUTLS_VERSION="gnutls-3.5.19" GLOOX_VERSION="gloox-1.0.20" -# NSPR is necessary for threadsafe Spidermonkey -NSPR_VERSION="4.15" # OS X only includes part of ICU, and only the dylib # NOTE: remember to also update LIB_URL below when changing version ICU_VERSION="icu4c-59_1" @@ -48,7 +46,7 @@ SODIUM_VERSION="libsodium-1.0.16" # -------------------------------------------------------------- # Bundled with the game: -# * SpiderMonkey 38 +# * SpiderMonkey 45 # * NVTT # * FCollada # -------------------------------------------------------------- @@ -593,38 +591,6 @@ popd > /dev/null # -------------------------------------------------------------- -echo -e "Building NSPR..." - -LIB_VERSION="${NSPR_VERSION}" -LIB_ARCHIVE="nspr-$LIB_VERSION.tar.gz" -LIB_DIRECTORY="nspr-$LIB_VERSION" -LIB_URL="https://ftp.mozilla.org/pub/mozilla.org/nspr/releases/v$LIB_VERSION/src/" - -mkdir -p nspr -pushd nspr > /dev/null - -NSPR_DIR="$(pwd)" - -if [[ "$force_rebuild" = "true" ]] || [[ ! -e .already-built ]] || [[ .already-built -ot $LIB_DIRECTORY ]] -then - rm -f .already-built - download_lib $LIB_URL $LIB_ARCHIVE - - rm -rf $LIB_DIRECTORY bin include lib share - tar -xf $LIB_ARCHIVE - pushd $LIB_DIRECTORY/nspr - - (CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" ./configure --prefix="$NSPR_DIR" --enable-64bit && make ${JOBS} && make install) || die "NSPR build failed" - popd - # TODO: how can we not build the dylibs? - rm -f lib/*.dylib - touch .already-built -else - already_built -fi -popd > /dev/null - -# -------------------------------------------------------------- echo -e "Building ICU..." LIB_VERSION="${ICU_VERSION}" @@ -755,9 +721,9 @@ # be customized, so we build and install them from bundled sources # -------------------------------------------------------------------- echo -e "Building Spidermonkey..." -LIB_VERSION="mozjs-38.2.1" -LIB_ARCHIVE="$LIB_VERSION.rc0.tar.bz2" -LIB_DIRECTORY="mozjs-38.0.0" +LIB_VERSION="mozjs-45.0.2" +LIB_ARCHIVE="$LIB_VERSION.tar.bz2" +LIB_DIRECTORY="mozjs-45.0.2" pushd ../source/spidermonkey/ > /dev/null @@ -778,14 +744,10 @@ popd pushd $LIB_DIRECTORY/js/src - # We want separate debug/release versions of the library, so change their install name in the Makefile - perl -i.bak -pe 's/(^STATIC_LIBRARY_NAME\s+=).*/$1'\''mozjs38-ps-debug'\''/' moz.build - CONF_OPTS="--target=$ARCH-apple-darwin --prefix=${INSTALL_DIR} --with-system-nspr --with-nspr-prefix=${NSPR_DIR} --with-system-zlib=${ZLIB_DIR} --disable-tests --disable-shared-js" + CONF_OPTS="--target=$ARCH-apple-darwin --prefix=${INSTALL_DIR} --enable-posix-nspr-emulation --with-system-zlib=${ZLIB_DIR} --disable-tests --disable-shared-js --disable-jemalloc --without-intl-api" # Change the default location where the tracelogger should store its output, which is /tmp/ on OSX. TLCXXFLAGS='-DTRACE_LOG_DIR="\"../../source/tools/tracelogger/\""' - # Uncomment this line for 32-bit 10.5 cross compile: - #CONF_OPTS="$CONF_OPTS --target=i386-apple-darwin9.0.0" if [[ $MIN_OSX_VERSION && ${MIN_OSX_VERSION-_} ]]; then CONF_OPTS="$CONF_OPTS --enable-macos-target=$MIN_OSX_VERSION" fi @@ -793,24 +755,26 @@ CONF_OPTS="$CONF_OPTS --with-macosx-sdk=$SYSROOT" fi + # We want separate debug/release versions of the library, so change their install name in the Makefile + perl -i.bak -pe 's/(^STATIC_LIBRARY_NAME\s+=).*/$1'\''mozjs45-ps-debug'\''/' moz.build mkdir -p build-debug pushd build-debug (CC="clang" CXX="clang++" CXXFLAGS="${TLCXXFLAGS}" AR=ar CROSS_COMPILE=1 ../configure $CONF_OPTS --enable-debug --disable-optimize --enable-js-diagnostics --enable-gczeal && make ${JOBS}) || die "Spidermonkey build failed" # js-config.h is different for debug and release builds, so we need different include directories for both mkdir -p $INCLUDE_DIR_DEBUG cp -R -L dist/include/* $INCLUDE_DIR_DEBUG/ - cp dist/lib/*.a $INSTALL_DIR/lib + cp dist/sdk/lib/*.a $INSTALL_DIR/lib popd mv moz.build.bak moz.build - perl -i.bak -pe 's/(^STATIC_LIBRARY_NAME\s+=).*/$1'\''mozjs38-ps-release'\''/' moz.build + perl -i.bak -pe 's/(^STATIC_LIBRARY_NAME\s+=).*/$1'\''mozjs45-ps-release'\''/' moz.build mkdir -p build-release pushd build-release (CC="clang" CXX="clang++" CXXFLAGS="${TLCXXFLAGS}" AR=ar CROSS_COMPILE=1 ../configure $CONF_OPTS --enable-optimize && make ${JOBS}) || die "Spidermonkey build failed" # js-config.h is different for debug and release builds, so we need different include directories for both mkdir -p $INCLUDE_DIR_RELEASE cp -R -L dist/include/* $INCLUDE_DIR_RELEASE/ - cp dist/lib/*.a $INSTALL_DIR/lib + cp dist/sdk/lib/*.a $INSTALL_DIR/lib popd mv moz.build.bak moz.build Index: libraries/source/spidermonkey/ExportJSPropertyDescriptor.diff =================================================================== --- /dev/null +++ libraries/source/spidermonkey/ExportJSPropertyDescriptor.diff @@ -0,0 +1,13 @@ +diff --git a/js/src/jsapi.h b/js/src/jsapi.h +index 2940624..2370457 100644 +--- a/js/src/jsapi.h ++++ b/js/src/jsapi.h +@@ -2399,7 +2399,7 @@ JS_FreezeObject(JSContext* cx, JS::Handle obj); + + /*** Property descriptors ************************************************************************/ + +-struct JSPropertyDescriptor : public JS::Traceable { ++struct JS_PUBLIC_API(JSPropertyDescriptor) : public JS::Traceable { + JSObject* obj; + unsigned attrs; + JSGetterOp getter; Index: libraries/source/spidermonkey/FixLinking.diff =================================================================== --- /dev/null +++ libraries/source/spidermonkey/FixLinking.diff @@ -0,0 +1,49 @@ +From dcf520da15d940c900d7e8ffd5a9b05427c54dc8 Mon Sep 17 00:00:00 2001 +From: Philip Chimento +Date: Wed, 5 Jul 2017 22:47:44 -0700 +Subject: [PATCH 4/9] headers: Fix symbols visibility + +Some symbols that need to be public are not marked as such. +--- + js/public/Utility.h | 2 +- + js/src/jsalloc.h | 4 +++- + 2 files changed, 4 insertions(+), 2 deletions(-) + +diff --git a/js/public/Utility.h b/js/public/Utility.h +index 75214c32..f50fd8dd 100644 +--- a/js/public/Utility.h ++++ b/js/public/Utility.h +@@ -77,7 +77,7 @@ enum ThreadType { + # if defined(DEBUG) || defined(JS_OOM_BREAKPOINT) + extern bool InitThreadType(void); + extern void SetThreadType(ThreadType); +-extern uint32_t GetThreadType(void); ++extern JS_FRIEND_API(uint32_t) GetThreadType(void); + # else + inline bool InitThreadType(void) { return true; } + inline void SetThreadType(ThreadType t) {}; +diff --git a/js/src/jsalloc.h b/js/src/jsalloc.h +index b9ae5190..234ea9dc 100644 +--- a/js/src/jsalloc.h ++++ b/js/src/jsalloc.h +@@ -17,6 +17,8 @@ + #include "js/TypeDecls.h" + #include "js/Utility.h" + ++extern JS_PUBLIC_API(void) JS_ReportOutOfMemory(JSContext* cx); ++ + namespace js { + + enum class AllocFunction { +@@ -130,7 +132,7 @@ class TempAllocPolicy + + bool checkSimulatedOOM() const { + if (js::oom::ShouldFailWithOOM()) { +- js::ReportOutOfMemory(reinterpret_cast(cx_)); ++ JS_ReportOutOfMemory(reinterpret_cast(cx_)); + return false; + } + +-- +2.11.0 (Apple Git-81) + Index: libraries/source/spidermonkey/FixMozglueStatic.diff =================================================================== --- /dev/null +++ libraries/source/spidermonkey/FixMozglueStatic.diff @@ -0,0 +1,20 @@ +diff --git a/mozglue/build/moz.build b/mozglue/build/moz.build +index 58e2db6..1cfb504 100644 +--- a/mozglue/build/moz.build ++++ b/mozglue/build/moz.build +@@ -4,12 +4,9 @@ + # License, v. 2.0. If a copy of the MPL was not distributed with this + # file, You can obtain one at http://mozilla.org/MPL/2.0/. + +-# Build mozglue as a shared lib on Windows, OSX and Android. +-# If this is ever changed, update MOZ_SHARED_MOZGLUE in browser/installer/Makefile.in +-if CONFIG['OS_TARGET'] in ('WINNT', 'Darwin', 'Android'): +- SharedLibrary('mozglue') +-else: +- Library('mozglue') ++# Build mozglue as a static lib into js for 0 A.D. ++Library('mozglue') ++FINAL_LIBRARY = 'js' + + if not CONFIG['MOZ_CRT']: + SDK_LIBRARY = True Index: libraries/source/spidermonkey/FixTracelogger.diff =================================================================== --- libraries/source/spidermonkey/FixTracelogger.diff +++ libraries/source/spidermonkey/FixTracelogger.diff @@ -1,565 +1,223 @@ -diff --git a/js/src/jit-test/tests/tracelogger/bug1231170.js b/js/src/jit-test/tests/tracelogger/bug1231170.js -new file mode 100644 -index 0000000..023e93e ---- /dev/null -+++ b/js/src/jit-test/tests/tracelogger/bug1231170.js -@@ -0,0 +1,3 @@ -+var du = new Debugger(); -+if (typeof du.drainTraceLogger === "function") -+ du.drainTraceLogger(); -diff --git a/js/src/jit-test/tests/tracelogger/bug1266649.js b/js/src/jit-test/tests/tracelogger/bug1266649.js -new file mode 100644 -index 0000000..81ae7ad ---- /dev/null -+++ b/js/src/jit-test/tests/tracelogger/bug1266649.js -@@ -0,0 +1,10 @@ -+ -+var du = new Debugger(); -+if (typeof du.setupTraceLogger === "function" && -+ typeof oomTest === 'function') -+{ -+ du.setupTraceLogger({ -+ Scripts: true -+ }) -+ oomTest(() => function(){}); -+} -diff --git a/js/src/jit/Ion.cpp b/js/src/jit/Ion.cpp -index 93e2fda..09049d6 100644 ---- a/js/src/jit/Ion.cpp -+++ b/js/src/jit/Ion.cpp -@@ -1055,6 +1055,8 @@ IonScript::Destroy(FreeOp* fop, IonScript* script) - - script->destroyCaches(); - script->unlinkFromRuntime(fop); -+ // Frees the potential event we have set. -+ script->traceLoggerScriptEvent_ = TraceLoggerEvent(); - fop->free_(script); - } - -diff --git a/js/src/vm/Debugger.cpp b/js/src/vm/Debugger.cpp -index 26262fd..af7f313 100644 ---- a/js/src/vm/Debugger.cpp -+++ b/js/src/vm/Debugger.cpp -@@ -369,10 +369,10 @@ Debugger::Debugger(JSContext* cx, NativeObject* dbg) - objects(cx), - environments(cx), - #ifdef NIGHTLY_BUILD -- traceLoggerLastDrainedId(0), -+ traceLoggerLastDrainedSize(0), - traceLoggerLastDrainedIteration(0), - #endif -- traceLoggerScriptedCallsLastDrainedId(0), -+ traceLoggerScriptedCallsLastDrainedSize(0), - traceLoggerScriptedCallsLastDrainedIteration(0) - { - assertSameCompartment(cx, dbg); -@@ -3907,9 +3907,9 @@ Debugger::drainTraceLogger(JSContext* cx, unsigned argc, Value* vp) - size_t num; - TraceLoggerThread* logger = TraceLoggerForMainThread(cx->runtime()); - bool lostEvents = logger->lostEvents(dbg->traceLoggerLastDrainedIteration, -- dbg->traceLoggerLastDrainedId); -+ dbg->traceLoggerLastDrainedSize); - EventEntry* events = logger->getEventsStartingAt(&dbg->traceLoggerLastDrainedIteration, -- &dbg->traceLoggerLastDrainedId, -+ &dbg->traceLoggerLastDrainedSize, - &num); - - RootedObject array(cx, NewDenseEmptyArray(cx)); -@@ -4002,10 +4002,10 @@ Debugger::drainTraceLoggerScriptCalls(JSContext* cx, unsigned argc, Value* vp) - size_t num; - TraceLoggerThread* logger = TraceLoggerForMainThread(cx->runtime()); - bool lostEvents = logger->lostEvents(dbg->traceLoggerScriptedCallsLastDrainedIteration, -- dbg->traceLoggerScriptedCallsLastDrainedId); -+ dbg->traceLoggerScriptedCallsLastDrainedSize); - EventEntry* events = logger->getEventsStartingAt( - &dbg->traceLoggerScriptedCallsLastDrainedIteration, -- &dbg->traceLoggerScriptedCallsLastDrainedId, -+ &dbg->traceLoggerScriptedCallsLastDrainedSize, - &num); - - RootedObject array(cx, NewDenseEmptyArray(cx)); -diff --git a/js/src/vm/Debugger.h b/js/src/vm/Debugger.h -index 8cac36a..c92d685 100644 ---- a/js/src/vm/Debugger.h -+++ b/js/src/vm/Debugger.h -@@ -314,10 +314,10 @@ class Debugger : private mozilla::LinkedListElement - * lost events. - */ - #ifdef NIGHTLY_BUILD -- uint32_t traceLoggerLastDrainedId; -+ uint32_t traceLoggerLastDrainedSize; - uint32_t traceLoggerLastDrainedIteration; - #endif -- uint32_t traceLoggerScriptedCallsLastDrainedId; -+ uint32_t traceLoggerScriptedCallsLastDrainedSize; - uint32_t traceLoggerScriptedCallsLastDrainedIteration; - - class FrameRange; -diff --git a/js/src/vm/TraceLogging.cpp b/js/src/vm/TraceLogging.cpp -index 6715b36..9766a6f 100644 ---- a/js/src/vm/TraceLogging.cpp -+++ b/js/src/vm/TraceLogging.cpp -@@ -131,7 +131,7 @@ TraceLoggerThread::init() - { - if (!pointerMap.init()) - return false; -- if (!extraTextId.init()) -+ if (!textIdPayloads.init()) - return false; - if (!events.init()) - return false; -@@ -185,10 +185,10 @@ TraceLoggerThread::~TraceLoggerThread() - graph = nullptr; - } - -- for (TextIdHashMap::Range r = extraTextId.all(); !r.empty(); r.popFront()) -- js_delete(r.front().value()); -- extraTextId.finish(); -- pointerMap.finish(); -+ if (textIdPayloads.initialized()) { -+ for (TextIdHashMap::Range r = textIdPayloads.all(); !r.empty(); r.popFront()) -+ js_delete(r.front().value()); -+ } - } - - bool -@@ -287,7 +287,7 @@ TraceLoggerThread::eventText(uint32_t id) - if (id < TraceLogger_Last) - return TLTextIdString(static_cast(id)); - -- TextIdHashMap::Ptr p = extraTextId.lookup(id); -+ TextIdHashMap::Ptr p = textIdPayloads.lookup(id); - MOZ_ASSERT(p); - - return p->value()->string(); -@@ -341,13 +341,15 @@ TraceLoggerThread::extractScriptDetails(uint32_t textId, const char** filename, - TraceLoggerEventPayload* - TraceLoggerThread::getOrCreateEventPayload(TraceLoggerTextId textId) - { -- TextIdHashMap::AddPtr p = extraTextId.lookupForAdd(textId); -- if (p) -+ TextIdHashMap::AddPtr p = textIdPayloads.lookupForAdd(textId); -+ if (p) { -+ MOZ_ASSERT(p->value()->textId() == textId); // Sanity check. - return p->value(); -+ } - - TraceLoggerEventPayload* payload = js_new(textId, (char*)nullptr); - -- if (!extraTextId.add(p, textId, payload)) -+ if (!textIdPayloads.add(p, textId, payload)) - return nullptr; - - return payload; -@@ -357,8 +359,10 @@ TraceLoggerEventPayload* - TraceLoggerThread::getOrCreateEventPayload(const char* text) - { - PointerHashMap::AddPtr p = pointerMap.lookupForAdd((const void*)text); -- if (p) -+ if (p) { -+ MOZ_ASSERT(p->value()->textId() < nextTextId); // Sanity check. - return p->value(); -+ } - - size_t len = strlen(text); - char* str = js_pod_malloc(len + 1); -@@ -369,7 +373,7 @@ TraceLoggerThread::getOrCreateEventPayload(const char* text) - MOZ_ASSERT(ret == len); - MOZ_ASSERT(strlen(str) == len); - -- uint32_t textId = extraTextId.count() + TraceLogger_Last; -+ uint32_t textId = nextTextId; - - TraceLoggerEventPayload* payload = js_new(textId, str); - if (!payload) { -@@ -377,17 +381,19 @@ TraceLoggerThread::getOrCreateEventPayload(const char* text) - return nullptr; - } - -- if (!extraTextId.putNew(textId, payload)) { -+ if (!textIdPayloads.putNew(textId, payload)) { - js_delete(payload); - return nullptr; - } - -- if (!pointerMap.add(p, text, payload)) -- return nullptr; -- - if (graph.get()) - graph->addTextId(textId, str); - -+ nextTextId++; -+ -+ if (!pointerMap.add(p, text, payload)) -+ return nullptr; -+ - return payload; - } - -@@ -407,9 +413,14 @@ TraceLoggerThread::getOrCreateEventPayload(TraceLoggerTextId type, const char* f - if (!traceLoggerState->isTextIdEnabled(type)) - return getOrCreateEventPayload(type); - -- PointerHashMap::AddPtr p = pointerMap.lookupForAdd(ptr); -- if (p) -- return p->value(); -+ PointerHashMap::AddPtr p; -+ if (ptr) { -+ p = pointerMap.lookupForAdd(ptr); -+ if (p) { -+ MOZ_ASSERT(p->value()->textId() < nextTextId); // Sanity check. -+ return p->value(); -+ } -+ } - - // Compute the length of the string to create. - size_t lenFilename = strlen(filename); -@@ -428,24 +439,28 @@ TraceLoggerThread::getOrCreateEventPayload(TraceLoggerTextId type, const char* f - MOZ_ASSERT(ret == len); - MOZ_ASSERT(strlen(str) == len); - -- uint32_t textId = extraTextId.count() + TraceLogger_Last; -+ uint32_t textId = nextTextId; - TraceLoggerEventPayload* payload = js_new(textId, str); - if (!payload) { - js_free(str); - return nullptr; - } - -- if (!extraTextId.putNew(textId, payload)) { -+ if (!textIdPayloads.putNew(textId, payload)) { - js_delete(payload); - return nullptr; - } - -- if (!pointerMap.add(p, ptr, payload)) -- return nullptr; -- - if (graph.get()) - graph->addTextId(textId, str); - -+ nextTextId++; -+ -+ if (ptr) { -+ if (!pointerMap.add(p, ptr, payload)) -+ return nullptr; -+ } -+ - return payload; - } - -@@ -453,14 +468,14 @@ TraceLoggerEventPayload* - TraceLoggerThread::getOrCreateEventPayload(TraceLoggerTextId type, JSScript* script) - { - return getOrCreateEventPayload(type, script->filename(), script->lineno(), script->column(), -- script); -+ nullptr); - } - - TraceLoggerEventPayload* - TraceLoggerThread::getOrCreateEventPayload(TraceLoggerTextId type, - const JS::ReadOnlyCompileOptions& script) - { -- return getOrCreateEventPayload(type, script.filename(), script.lineno, script.column, &script); -+ return getOrCreateEventPayload(type, script.filename(), script.lineno, script.column, nullptr); - } - - void -@@ -485,7 +500,7 @@ TraceLoggerThread::startEvent(uint32_t id) - if (!traceLoggerState->isTextIdEnabled(id)) - return; - -- logTimestamp(id); -+ log(id); - } - - void -@@ -510,7 +525,7 @@ TraceLoggerThread::stopEvent(uint32_t id) - if (!traceLoggerState->isTextIdEnabled(id)) - return; - -- logTimestamp(TraceLogger_Stop); -+ log(TraceLogger_Stop); - } - - void -@@ -522,23 +537,57 @@ TraceLoggerThread::logTimestamp(TraceLoggerTextId id) - void - TraceLoggerThread::logTimestamp(uint32_t id) - { -+ MOZ_ASSERT(id > TraceLogger_LastTreeItem && id < TraceLogger_Last); -+ log(id); -+} -+ -+void -+TraceLoggerThread::log(uint32_t id) -+{ - if (enabled == 0) - return; - - MOZ_ASSERT(traceLoggerState); -- if (!events.ensureSpaceBeforeAdd()) { -+ -+ // We request for 3 items to add, since if we don't have enough room -+ // we record the time it took to make more place. To log this information -+ // we need 2 extra free entries. -+ if (!events.hasSpaceForAdd(3)) { - uint64_t start = rdtsc() - traceLoggerState->startupTime; - -- if (graph.get()) -- graph->log(events); -+ if (!events.ensureSpaceBeforeAdd(3)) { -+ if (graph.get()) -+ graph->log(events); -+ -+ iteration_++; -+ events.clear(); -+ -+ // Remove the item in the pointerMap for which the payloads -+ // have no uses anymore -+ for (PointerHashMap::Enum e(pointerMap); !e.empty(); e.popFront()) { -+ if (e.front().value()->uses() != 0) -+ continue; -+ -+ TextIdHashMap::Ptr p = textIdPayloads.lookup(e.front().value()->textId()); -+ MOZ_ASSERT(p); -+ textIdPayloads.remove(p); -+ -+ e.removeFront(); -+ } - -- iteration_++; -- events.clear(); -+ // Free all payloads that have no uses anymore. -+ for (TextIdHashMap::Enum e(textIdPayloads); !e.empty(); e.popFront()) { -+ if (e.front().value()->uses() == 0) { -+ js_delete(e.front().value()); -+ e.removeFront(); -+ } -+ } -+ } - - // Log the time it took to flush the events as being from the - // Tracelogger. - if (graph.get()) { -- MOZ_ASSERT(events.capacity() > 2); -+ MOZ_ASSERT(events.hasSpaceForAdd(2)); - EventEntry& entryStart = events.pushUninitialized(); - entryStart.time = start; - entryStart.textId = TraceLogger_Internal; -@@ -548,13 +597,6 @@ TraceLoggerThread::logTimestamp(uint32_t id) - entryStop.textId = TraceLogger_Stop; - } - -- // Free all TextEvents that have no uses anymore. -- for (TextIdHashMap::Enum e(extraTextId); !e.empty(); e.popFront()) { -- if (e.front().value()->uses() == 0) { -- js_delete(e.front().value()); -- e.removeFront(); -- } -- } - } - - uint64_t time = rdtsc() - traceLoggerState->startupTime; -@@ -956,3 +998,16 @@ TraceLoggerEvent::~TraceLoggerEvent() - if (payload_) - payload_->release(); - } -+ -+TraceLoggerEvent& -+TraceLoggerEvent::operator=(const TraceLoggerEvent& other) -+{ -+ if (hasPayload()) -+ payload()->release(); -+ if (other.hasPayload()) -+ other.payload()->use(); -+ -+ payload_ = other.payload_; -+ -+ return *this; -+} -diff --git a/js/src/vm/TraceLogging.h b/js/src/vm/TraceLogging.h -index a124dcb..91a1eb0 100644 ---- a/js/src/vm/TraceLogging.h -+++ b/js/src/vm/TraceLogging.h -@@ -110,6 +110,9 @@ class TraceLoggerEvent { - bool hasPayload() const { - return !!payload_; - } -+ -+ TraceLoggerEvent& operator=(const TraceLoggerEvent& other); -+ TraceLoggerEvent(const TraceLoggerEvent& event) = delete; - }; - - /** -@@ -130,6 +133,10 @@ class TraceLoggerEventPayload { - uses_(0) - { } - -+ ~TraceLoggerEventPayload() { -+ MOZ_ASSERT(uses_ == 0); -+ } -+ - uint32_t textId() { - return textId_; - } -@@ -166,7 +173,8 @@ class TraceLoggerThread - mozilla::UniquePtr graph; - - PointerHashMap pointerMap; -- TextIdHashMap extraTextId; -+ TextIdHashMap textIdPayloads; -+ uint32_t nextTextId; - - ContinuousSpace events; - -@@ -181,6 +189,7 @@ class TraceLoggerThread - : enabled(0), - failed(false), - graph(), -+ nextTextId(TraceLogger_Last), - iteration_(0), - top(nullptr) - { } -@@ -195,22 +204,22 @@ class TraceLoggerThread - bool enable(JSContext* cx); - bool disable(); - -- // Given the previous iteration and lastEntryId, return an array of events -+ // Given the previous iteration and size, return an array of events - // (there could be lost events). At the same time update the iteration and -- // lastEntry and gives back how many events there are. -- EventEntry* getEventsStartingAt(uint32_t* lastIteration, uint32_t* lastEntryId, size_t* num) { -+ // size and gives back how many events there are. -+ EventEntry* getEventsStartingAt(uint32_t* lastIteration, uint32_t* lastSize, size_t* num) { - EventEntry* start; - if (iteration_ == *lastIteration) { -- MOZ_ASSERT(events.lastEntryId() >= *lastEntryId); -- *num = events.lastEntryId() - *lastEntryId; -- start = events.data() + *lastEntryId + 1; -+ MOZ_ASSERT(*lastSize <= events.size()); -+ *num = events.size() - *lastSize; -+ start = events.data() + *lastSize; - } else { -- *num = events.lastEntryId() + 1; -+ *num = events.size(); - start = events.data(); - } - - *lastIteration = iteration_; -- *lastEntryId = events.lastEntryId(); -+ *lastSize = events.size(); - return start; - } - -@@ -220,16 +229,16 @@ class TraceLoggerThread - const char** lineno, size_t* lineno_len, const char** colno, - size_t* colno_len); - -- bool lostEvents(uint32_t lastIteration, uint32_t lastEntryId) { -+ bool lostEvents(uint32_t lastIteration, uint32_t lastSize) { - // If still logging in the same iteration, there are no lost events. - if (lastIteration == iteration_) { -- MOZ_ASSERT(lastEntryId <= events.lastEntryId()); -+ MOZ_ASSERT(lastSize <= events.size()); - return false; - } - -- // When proceeded to the next iteration and lastEntryId points to -- // the maximum capacity there are no logs that are lost. -- if (lastIteration + 1 == iteration_ && lastEntryId == events.capacity()) -+ // If we are in a consecutive iteration we are only sure we didn't lose any events, -+ // when the lastSize equals the maximum size 'events' can get. -+ if (lastIteration == iteration_ - 1 && lastSize == events.maxSize()) - return false; - - return true; -@@ -268,6 +277,7 @@ class TraceLoggerThread - void stopEvent(uint32_t id); - private: - void stopEvent(); -+ void log(uint32_t id); - - public: - static unsigned offsetOfEnabled() { -diff --git a/js/src/vm/TraceLoggingGraph.cpp b/js/src/vm/TraceLoggingGraph.cpp -index d1b7f2e..a4eb273 100644 ---- a/js/src/vm/TraceLoggingGraph.cpp -+++ b/js/src/vm/TraceLoggingGraph.cpp -@@ -276,7 +276,7 @@ TraceLoggerGraph::flush() - if (bytesWritten < tree.size()) - return false; - -- treeOffset += tree.lastEntryId(); -+ treeOffset += tree.size(); - tree.clear(); - } - -@@ -359,7 +359,7 @@ TraceLoggerGraph::startEventInternal(uint32_t id, uint64_t timestamp) - - if (parent.lastChildId() == 0) { - MOZ_ASSERT(!entry.hasChildren()); -- MOZ_ASSERT(parent.treeId() == tree.lastEntryId() + treeOffset); -+ MOZ_ASSERT(parent.treeId() == treeOffset + tree.size() - 1); - - if (!updateHasChildren(parent.treeId())) - return false; -diff --git a/js/src/vm/TraceLoggingTypes.h b/js/src/vm/TraceLoggingTypes.h -index f1c9d0c..10b76d6 100644 ---- a/js/src/vm/TraceLoggingTypes.h -+++ b/js/src/vm/TraceLoggingTypes.h -@@ -21,7 +21,6 @@ - _(Internal) \ - _(Interpreter) \ - _(InlinedScripts) \ -- _(Invalidation) \ - _(IonCompilation) \ - _(IonCompilationPaused) \ - _(IonLinking) \ -@@ -60,6 +59,7 @@ - - #define TRACELOGGER_LOG_ITEMS(_) \ - _(Bailout) \ -+ _(Invalidation) \ - _(Disable) \ - _(Enable) \ - _(Stop) -@@ -130,6 +130,9 @@ class ContinuousSpace { - uint32_t size_; - uint32_t capacity_; - -+ // The maximum amount of ram memory a continuous space structure can take (in bytes). -+ static const uint32_t LIMIT = 200 * 1024 * 1024; -+ - public: - ContinuousSpace () - : data_(nullptr) -@@ -151,6 +154,10 @@ class ContinuousSpace { - data_ = nullptr; - } - -+ static uint32_t maxSize() { -+ return LIMIT / sizeof(T); -+ } -+ - T* data() { - return data_; - } -@@ -187,11 +194,14 @@ class ContinuousSpace { - if (hasSpaceForAdd(count)) - return true; - -+ // Limit the size of a continuous buffer. -+ if (size_ + count > maxSize()) -+ return false; -+ - uint32_t nCapacity = capacity_ * 2; -- if (size_ + count > nCapacity) -- nCapacity = size_ + count; -- T* entries = (T*) js_realloc(data_, nCapacity * sizeof(T)); -+ nCapacity = (nCapacity < maxSize()) ? nCapacity : maxSize(); - -+ T* entries = (T*) js_realloc(data_, nCapacity * sizeof(T)); - if (!entries) - return false; - +diff --git a/js/src/jit-test/tests/tracelogger/bug1266649.js b/js/src/jit-test/tests/tracelogger/bug1266649.js +new file mode 100644 +index 0000000..2878e0c +--- /dev/null ++++ b/js/src/jit-test/tests/tracelogger/bug1266649.js +@@ -0,0 +1,8 @@ ++ ++var du = new Debugger(); ++if (typeof du.setupTraceLogger === "function") { ++ du.setupTraceLogger({ ++ Scripts: true ++ }) ++ oomTest(() => function(){}); ++} +diff --git a/js/src/vm/TraceLogging.cpp b/js/src/vm/TraceLogging.cpp +index ce7acc6..8f8aca4 100644 +--- a/js/src/vm/TraceLogging.cpp ++++ b/js/src/vm/TraceLogging.cpp +@@ -393,14 +393,14 @@ TraceLoggerThread::getOrCreateEventPayload(const char* text) + return nullptr; + } + +- if (!pointerMap.add(p, text, payload)) +- return nullptr; +- + if (graph.get()) + graph->addTextId(textId, str); + + nextTextId++; + ++ if (!pointerMap.add(p, text, payload)) ++ return nullptr; ++ + return payload; + } + +@@ -420,10 +420,13 @@ TraceLoggerThread::getOrCreateEventPayload(TraceLoggerTextId type, const char* f + if (!traceLoggerState->isTextIdEnabled(type)) + return getOrCreateEventPayload(type); + +- PointerHashMap::AddPtr p = pointerMap.lookupForAdd(ptr); +- if (p) { +- MOZ_ASSERT(p->value()->textId() < nextTextId); // Sanity check. +- return p->value(); ++ PointerHashMap::AddPtr p; ++ if (ptr) { ++ p = pointerMap.lookupForAdd(ptr); ++ if (p) { ++ MOZ_ASSERT(p->value()->textId() < nextTextId); // Sanity check. ++ return p->value(); ++ } + } + + // Compute the length of the string to create. +@@ -455,14 +458,16 @@ TraceLoggerThread::getOrCreateEventPayload(TraceLoggerTextId type, const char* f + return nullptr; + } + +- if (!pointerMap.add(p, ptr, payload)) +- return nullptr; +- + if (graph.get()) + graph->addTextId(textId, str); + + nextTextId++; + ++ if (ptr) { ++ if (!pointerMap.add(p, ptr, payload)) ++ return nullptr; ++ } ++ + return payload; + } + +@@ -477,7 +482,7 @@ TraceLoggerEventPayload* + TraceLoggerThread::getOrCreateEventPayload(TraceLoggerTextId type, + const JS::ReadOnlyCompileOptions& script) + { +- return getOrCreateEventPayload(type, script.filename(), script.lineno, script.column, &script); ++ return getOrCreateEventPayload(type, script.filename(), script.lineno, script.column, nullptr); + } + + void +@@ -550,19 +555,42 @@ TraceLoggerThread::log(uint32_t id) + return; + + MOZ_ASSERT(traceLoggerState); +- if (!events.ensureSpaceBeforeAdd()) { ++ if (!events.hasSpaceForAdd(3)) { + uint64_t start = rdtsc() - traceLoggerState->startupTime; + +- if (graph.get()) +- graph->log(events); ++ if (!events.ensureSpaceBeforeAdd(3)) { ++ if (graph.get()) ++ graph->log(events); + +- iteration_++; +- events.clear(); ++ iteration_++; ++ events.clear(); ++ ++ // Remove the item in the pointerMap for which the payloads ++ // have no uses anymore ++ for (PointerHashMap::Enum e(pointerMap); !e.empty(); e.popFront()) { ++ if (e.front().value()->uses() != 0) ++ continue; ++ ++ TextIdHashMap::Ptr p = textIdPayloads.lookup(e.front().value()->textId()); ++ MOZ_ASSERT(p); ++ textIdPayloads.remove(p); ++ ++ e.removeFront(); ++ } ++ ++ // Free all payloads that have no uses anymore. ++ for (TextIdHashMap::Enum e(textIdPayloads); !e.empty(); e.popFront()) { ++ if (e.front().value()->uses() == 0) { ++ js_delete(e.front().value()); ++ e.removeFront(); ++ } ++ } ++ } + + // Log the time it took to flush the events as being from the + // Tracelogger. + if (graph.get()) { +- MOZ_ASSERT(events.capacity() > 2); ++ MOZ_ASSERT(events.capacity() - events.size() > 2); + EventEntry& entryStart = events.pushUninitialized(); + entryStart.time = start; + entryStart.textId = TraceLogger_Internal; +@@ -572,26 +600,6 @@ TraceLoggerThread::log(uint32_t id) + entryStop.textId = TraceLogger_Stop; + } + +- // Remove the item in the pointerMap for which the payloads +- // have no uses anymore +- for (PointerHashMap::Enum e(pointerMap); !e.empty(); e.popFront()) { +- if (e.front().value()->uses() != 0) +- continue; +- +- TextIdHashMap::Ptr p = textIdPayloads.lookup(e.front().value()->textId()); +- MOZ_ASSERT(p); +- textIdPayloads.remove(p); +- +- e.removeFront(); +- } +- +- // Free all payloads that have no uses anymore. +- for (TextIdHashMap::Enum e(textIdPayloads); !e.empty(); e.popFront()) { +- if (e.front().value()->uses() == 0) { +- js_delete(e.front().value()); +- e.removeFront(); +- } +- } + } + + uint64_t time = rdtsc() - traceLoggerState->startupTime; +diff --git a/js/src/vm/TraceLogging.h b/js/src/vm/TraceLogging.h +index 270478c..313950e 100644 +--- a/js/src/vm/TraceLogging.h ++++ b/js/src/vm/TraceLogging.h +@@ -242,7 +242,7 @@ class TraceLoggerThread + + // If we are in a consecutive iteration we are only sure we didn't lose any events, + // when the lastSize equals the maximum size 'events' can get. +- if (lastIteration == iteration_ - 1 && lastSize == CONTINUOUSSPACE_LIMIT) ++ if (lastIteration == iteration_ - 1 && lastSize == events.max_items()) + return false; + + return true; +diff --git a/js/src/vm/TraceLoggingTypes.h b/js/src/vm/TraceLoggingTypes.h +index bb8ccc7..1d98bf6 100644 +--- a/js/src/vm/TraceLoggingTypes.h ++++ b/js/src/vm/TraceLoggingTypes.h +@@ -130,15 +130,15 @@ TLTextIdIsTreeEvent(uint32_t id) + id >= TraceLogger_Last; + } + +-// The maximum amount of ram memory a continuous space structure can take (in bytes). +-static const uint32_t CONTINUOUSSPACE_LIMIT = 200 * 1024 * 1024; +- + template + class ContinuousSpace { + T* data_; + uint32_t size_; + uint32_t capacity_; + ++ // The maximum amount of ram memory a continuous space structure can take (in bytes). ++ static const uint32_t LIMIT = 200 * 1024 * 1024; ++ + public: + ContinuousSpace () + : data_(nullptr) +@@ -160,6 +160,10 @@ class ContinuousSpace { + data_ = nullptr; + } + ++ uint32_t max_items() { ++ return LIMIT / sizeof(T); ++ } ++ + T* data() { + return data_; + } +@@ -197,11 +201,14 @@ class ContinuousSpace { + return true; + + uint32_t nCapacity = capacity_ * 2; +- if (size_ + count > nCapacity || nCapacity * sizeof(T) > CONTINUOUSSPACE_LIMIT) { ++ if (size_ + count > nCapacity) + nCapacity = size_ + count; + ++ if (nCapacity > max_items()) { ++ nCapacity = max_items(); ++ + // Limit the size of a continuous buffer. +- if (nCapacity * sizeof(T) > CONTINUOUSSPACE_LIMIT) ++ if (size_ + count > nCapacity) + return false; + } + Index: libraries/source/spidermonkey/FixVersionDetection.diff =================================================================== --- libraries/source/spidermonkey/FixVersionDetection.diff +++ /dev/null @@ -1,137 +0,0 @@ - -# HG changeset patch -# User Sean Stangl -# Date 1426889983 25200 -# Node ID 4f8bbef857155fbee1d064e014b22dd72512b389 -# Parent 6f42f8ee82468d18acd65e0c2b5bf6c040696224 -Bug 1145882 - Part 1/2 - Only use $PYTHON after defined by MOZ_PYTHON. r=glandium - -diff --git a/js/src/configure.in b/js/src/configure.in ---- a/js/src/configure.in -+++ b/js/src/configure.in -@@ -228,61 +228,16 @@ if test -n "$gonkdir" ; then - fi - - AC_DEFINE(ANDROID) - AC_DEFINE(GONK) - else - MOZ_ANDROID_NDK - fi - --dnl ============================================================== --dnl Get mozilla version from central milestone file --dnl ============================================================== --MOZILLA_VERSION=`$PYTHON $srcdir/python/mozbuild/mozbuild/milestone.py --topsrcdir $srcdir` --MOZILLA_UAVERSION=`$PYTHON $srcdir/python/mozbuild/mozbuild/milestone.py --topsrcdir $srcdir --uaversion` --MOZILLA_SYMBOLVERSION=`$PYTHON $srcdir/python/mozbuild/mozbuild/milestone.py --topsrcdir $srcdir --symbolversion` -- --AC_DEFINE_UNQUOTED(MOZILLA_VERSION,"$MOZILLA_VERSION") --AC_DEFINE_UNQUOTED(MOZILLA_VERSION_U,$MOZILLA_VERSION) --AC_DEFINE_UNQUOTED(MOZILLA_UAVERSION,"$MOZILLA_UAVERSION") --AC_SUBST(MOZILLA_SYMBOLVERSION) -- --# Separate version into components for use in shared object naming etc --changequote(,) --MOZJS_MAJOR_VERSION=`echo $MOZILLA_VERSION | sed "s|\(^[0-9]*\)\.[0-9]*.*|\1|"` --MOZJS_MINOR_VERSION=`echo $MOZILLA_VERSION | sed "s|^[0-9]*\.\([0-9]*\).*|\1|"` --MOZJS_PATCH_VERSION=`echo $MOZILLA_VERSION | sed "s|^[0-9]*\.[0-9]*[^0-9]*||"` --IS_ALPHA=`echo $MOZILLA_VERSION | grep '[ab]'` -- --dnl XXX in a temporary bid to avoid developer anger at renaming files --dnl XXX before "js" symlinks exist, don't change names. --dnl --dnl if test -n "$JS_STANDALONE"; then --dnl JS_SHELL_NAME=js$MOZJS_MAJOR_VERSION --dnl JS_CONFIG_NAME=js$MOZJS_MAJOR_VERSION-config --dnl else --JS_SHELL_NAME=js --JS_CONFIG_NAME=js-config --dnl fi -- --changequote([,]) --if test -n "$IS_ALPHA"; then -- changequote(,) -- MOZJS_ALPHA=`echo $MOZILLA_VERSION | sed "s|^[0-9]*\.[0-9\.]*\([^0-9]\).*|\1|"` -- changequote([,]) --fi --AC_DEFINE_UNQUOTED(MOZJS_MAJOR_VERSION,$MOZJS_MAJOR_VERSION) --AC_DEFINE_UNQUOTED(MOZJS_MINOR_VERSION,$MOZJS_MINOR_VERSION) --AC_SUBST(JS_SHELL_NAME) --AC_SUBST(JS_CONFIG_NAME) --AC_SUBST(MOZJS_MAJOR_VERSION) --AC_SUBST(MOZJS_MINOR_VERSION) --AC_SUBST(MOZJS_PATCH_VERSION) --AC_SUBST(MOZJS_ALPHA) -- - dnl ======================================================== - dnl Checks for compilers. - dnl ======================================================== - - dnl AR_FLAGS set here so HOST_AR_FLAGS can be set correctly (see bug 538269) - AR_FLAGS='crs $@' - - if test "$COMPILE_ENVIRONMENT"; then -@@ -733,16 +688,62 @@ fi - if test "$COMPILE_ENVIRONMENT"; then - - AC_PATH_XTRA - - XCFLAGS="$X_CFLAGS" - - fi # COMPILE_ENVIRONMENT - -+dnl ============================================================== -+dnl Get mozilla version from central milestone file -+dnl ============================================================== -+MOZILLA_VERSION=`$PYTHON $srcdir/python/mozbuild/mozbuild/milestone.py --topsrcdir $srcdir` -+MOZILLA_UAVERSION=`$PYTHON $srcdir/python/mozbuild/mozbuild/milestone.py --topsrcdir $srcdir --uaversion` -+MOZILLA_SYMBOLVERSION=`$PYTHON $srcdir/python/mozbuild/mozbuild/milestone.py --topsrcdir $srcdir --symbolversion` -+ -+AC_DEFINE_UNQUOTED(MOZILLA_VERSION,"$MOZILLA_VERSION") -+AC_DEFINE_UNQUOTED(MOZILLA_VERSION_U,$MOZILLA_VERSION) -+AC_DEFINE_UNQUOTED(MOZILLA_UAVERSION,"$MOZILLA_UAVERSION") -+AC_SUBST(MOZILLA_SYMBOLVERSION) -+ -+# Separate version into components for use in shared object naming etc -+changequote(,) -+MOZJS_MAJOR_VERSION=`echo $MOZILLA_VERSION | sed "s|\(^[0-9]*\)\.[0-9]*.*|\1|"` -+MOZJS_MINOR_VERSION=`echo $MOZILLA_VERSION | sed "s|^[0-9]*\.\([0-9]*\).*|\1|"` -+MOZJS_PATCH_VERSION=`echo $MOZILLA_VERSION | sed "s|^[0-9]*\.[0-9]*[^0-9]*||"` -+IS_ALPHA=`echo $MOZILLA_VERSION | grep '[ab]'` -+ -+dnl XXX in a temporary bid to avoid developer anger at renaming files -+dnl XXX before "js" symlinks exist, don't change names. -+dnl -+dnl if test -n "$JS_STANDALONE"; then -+dnl JS_SHELL_NAME=js$MOZJS_MAJOR_VERSION -+dnl JS_CONFIG_NAME=js$MOZJS_MAJOR_VERSION-config -+dnl else -+JS_SHELL_NAME=js -+JS_CONFIG_NAME=js-config -+dnl fi -+ -+changequote([,]) -+if test -n "$IS_ALPHA"; then -+ changequote(,) -+ MOZJS_ALPHA=`echo $MOZILLA_VERSION | sed "s|^[0-9]*\.[0-9\.]*\([^0-9]\).*|\1|"` -+ changequote([,]) -+fi -+AC_DEFINE_UNQUOTED(MOZJS_MAJOR_VERSION,$MOZJS_MAJOR_VERSION) -+AC_DEFINE_UNQUOTED(MOZJS_MINOR_VERSION,$MOZJS_MINOR_VERSION) -+AC_SUBST(JS_SHELL_NAME) -+AC_SUBST(JS_CONFIG_NAME) -+AC_SUBST(MOZJS_MAJOR_VERSION) -+AC_SUBST(MOZJS_MINOR_VERSION) -+AC_SUBST(MOZJS_PATCH_VERSION) -+AC_SUBST(MOZJS_ALPHA) -+ -+ - dnl ======================================================== - dnl set the defaults first - dnl ======================================================== - AS_BIN=$AS - AR_LIST='$(AR) t' - AR_EXTRACT='$(AR) x' - AR_DELETE='$(AR) d' - AS='$(CC)' - Index: libraries/source/spidermonkey/FixVersionDetectionConfigure.diff =================================================================== --- libraries/source/spidermonkey/FixVersionDetectionConfigure.diff +++ /dev/null @@ -1,178 +0,0 @@ -Created from the patched (FixVersionDetection.diff) configure.in, ignoring -unrelated hunks (thus invalidating some hard-coded line numbers). This way -we do not add a dependency on autoconf-2.13. - -diff --git a/js/src/configure b/js/src/configure ---- a/js/src/configure -+++ b/js/src/configure -@@ -1662,70 +1662,6 @@ esac - - fi - --MOZILLA_VERSION=`$PYTHON $srcdir/python/mozbuild/mozbuild/milestone.py --topsrcdir $srcdir` --MOZILLA_UAVERSION=`$PYTHON $srcdir/python/mozbuild/mozbuild/milestone.py --topsrcdir $srcdir --uaversion` --MOZILLA_SYMBOLVERSION=`$PYTHON $srcdir/python/mozbuild/mozbuild/milestone.py --topsrcdir $srcdir --symbolversion` -- --cat >> confdefs.pytmp <> confdefs.h <> confdefs.pytmp <> confdefs.h <> confdefs.pytmp <> confdefs.h <> confdefs.pytmp <> confdefs.h <> confdefs.pytmp <> confdefs.h <> confdefs.pytmp <> confdefs.h <> confdefs.pytmp <> confdefs.h <> confdefs.pytmp <> confdefs.h <> confdefs.pytmp <> confdefs.h <> confdefs.pytmp <> confdefs.h <> $CONFIG_STATUS <> $CONFIG_STATUS < +# Date 1501017350 25200 +# Node ID 5d95b2833b30582ab3df4e28373d749ddbf7c04e +# Parent c24e6fc9f689aeb32de0bf7916b1d0098d4a2bb9 +Bug 1379539 - Remove unnecessary NSPR dependency. r=glandium, a=jcristau + +diff --git a/build/autoconf/nspr-build.m4 b/build/autoconf/nspr-build.m4 +index 970e1e7..66d96b1 100644 +--- a/build/autoconf/nspr-build.m4 ++++ b/build/autoconf/nspr-build.m4 +@@ -167,11 +167,8 @@ fi + + AC_SUBST_LIST(NSPR_CFLAGS) + +-NSPR_PKGCONF_CHECK="nspr" ++PKGCONF_REQUIRES_PRIVATE="Requires.private: nspr" + if test -n "$MOZ_NATIVE_NSPR"; then +- # piggy back on $MOZ_NATIVE_NSPR to set a variable for the nspr check for js.pc +- NSPR_PKGCONF_CHECK="nspr >= $NSPR_MINVER" +- + _SAVE_CFLAGS=$CFLAGS + CFLAGS="$CFLAGS $NSPR_CFLAGS" + AC_TRY_COMPILE([#include "prlog.h"], +@@ -181,8 +178,12 @@ if test -n "$MOZ_NATIVE_NSPR"; then + , + AC_MSG_ERROR([system NSPR does not support PR_STATIC_ASSERT])) + CFLAGS=$_SAVE_CFLAGS ++ # piggy back on $MOZ_NATIVE_NSPR to set a variable for the nspr check for js.pc ++ PKGCONF_REQUIRES_PRIVATE="Requires.private: nspr >= $NSPR_MINVER" ++elif test -n "$JS_POSIX_NSPR"; then ++ PKGCONF_REQUIRES_PRIVATE= + fi +-AC_SUBST(NSPR_PKGCONF_CHECK) ++AC_SUBST([PKGCONF_REQUIRES_PRIVATE]) + + fi # _IS_OUTER_CONFIGURE + +diff --git a/js/src/js.pc.in b/js/src/js.pc.in +index 1efea33..2eae393 100644 +--- a/js/src/js.pc.in ++++ b/js/src/js.pc.in +@@ -6,6 +6,6 @@ includedir=@includedir@ + Name: SpiderMonkey @MOZILLA_VERSION@ + Description: The Mozilla library for JavaScript + Version: @MOZILLA_VERSION@ +-Requires.private: @NSPR_PKGCONF_CHECK@ ++@PKGCONF_REQUIRES_PRIVATE@ + Libs: -L${libdir} -l@JS_LIBRARY_NAME@ + Cflags: -include ${includedir}/@JS_LIBRARY_NAME@/js/RequiredDefines.h -I${includedir}/@JS_LIBRARY_NAME@ Index: libraries/source/spidermonkey/build.sh =================================================================== --- libraries/source/spidermonkey/build.sh +++ libraries/source/spidermonkey/build.sh @@ -27,10 +27,11 @@ MAKE_OPTS="${JOBS}" -CONF_OPTS="--enable-shared-js --disable-tests --without-intl-api" +# jemalloc is outdated on SM45, do not use it +CONF_OPTS="--disable-tests --disable-jemalloc --enable-shared-js --without-intl-api" # Bug 1269319 -# When compiled with GCC 6 (or later), SpiderMonkey 38 (and versions up to 49) is +# When compiled with GCC 6 (or later), SpiderMonkey 45 (and versions up to 49) is # subject to segfaults. Disabling a few optimizations fixes that. # See also #4053 if [ "${OS}" != "Windows_NT" ] @@ -45,19 +46,18 @@ # The default location is . on Windows and /tmp/ on *nix. TLCXXFLAGS='-DTRACE_LOG_DIR="\"../../source/tools/tracelogger/\""' -# We bundle prebuilt binaries for Windows and the .libs for nspr aren't included. +# NSPR is needed on Windows for POSIX emulation. # If you want to build on Windows, check README.txt and edit the absolute paths # to match your environment. if [ "${OS}" = "Windows_NT" ] then - NSPR_INCLUDES="-IC:/Projects/nspr/nspr-4.12/nspr/dist/include/nspr" + NSPR_INCLUDES="-IC:/Users/Nicolas/Documents/0ad/nspr-4.12/nspr/dist/include/nspr" NSPR_LIBS=" \ - C:/Projects/nspr/nspr-4.12/nspr/dist/lib/nspr4 \ - C:/Projects/nspr/nspr-4.12/nspr/dist/lib/plds4 \ - C:/Projects/nspr/nspr-4.12/nspr/dist/lib/plc4" + C:/Users/Nicolas/Documents/0ad/nspr-4.12/nspr/dist/lib/nspr4 \ + C:/Users/Nicolas/Documents/0ad/nspr-4.12/nspr/dist/lib/plds4 \ + C:/Users/Nicolas/Documents/0ad/nspr-4.12/nspr/dist/lib/plc4" else - NSPR_INCLUDES="`pkg-config nspr --cflags`" - NSPR_LIBS="`pkg-config nspr --libs`" + CONF_OPTS="${CONF_OPTS} --enable-posix-nspr-emulation" fi # If Valgrind looks like it's installed, then set up SM to support it @@ -76,11 +76,11 @@ echo "SpiderMonkey build options: ${CONF_OPTS}" echo ${CONF_OPTS} -FOLDER=mozjs-38.0.0 +FOLDER=mozjs-45.0.2 # Delete the existing directory to avoid conflicts and extract the tarball rm -rf $FOLDER -tar xjf mozjs-38.2.1.rc0.tar.bz2 +tar xjf mozjs-45.0.2.tar.bz2 # Clean up header files that may be left over by earlier versions of SpiderMonkey rm -rf include-unix-* @@ -100,17 +100,27 @@ # the LIBRARY_NAME for each build. # (We use perl instead of sed so that it works with MozillaBuild on Windows, # which has an ancient sed.) -perl -i.bak -pe 's/(SHARED_LIBRARY_NAME\s+=).*/$1 '\''mozjs38-ps-debug'\''/' moz.build +perl -i.bak -pe 's/(SHARED_LIBRARY_NAME\s+=).*/$1 '\''mozjs45-ps-debug'\''/' moz.build mkdir -p build-debug cd build-debug -CXXFLAGS="${CXXFLAGS} ${TLCXXFLAGS}" ../configure ${CONF_OPTS} --with-nspr-libs="$NSPR_LIBS" --with-nspr-cflags="$NSPR_INCLUDES" --enable-debug --disable-optimize --enable-js-diagnostics --enable-gczeal +if [ "${OS}" = "Windows_NT" ] +then + CXXFLAGS="${CXXFLAGS} ${TLCXXFLAGS}" ../configure ${CONF_OPTS} --with-nspr-cflags="${NSPR_INCLUDES}" --with-nspr-libs="${NSPR_LIBS}" --enable-debug --disable-optimize --enable-js-diagnostics --enable-gczeal +else + CXXFLAGS="${CXXFLAGS} ${TLCXXFLAGS}" ../configure ${CONF_OPTS} --enable-debug --disable-optimize --enable-js-diagnostics --enable-gczeal +fi ${MAKE} ${MAKE_OPTS} cd .. -perl -i.bak -pe 's/(SHARED_LIBRARY_NAME\s+=).*/$1 '\''mozjs38-ps-release'\''/' moz.build +perl -i.bak -pe 's/(SHARED_LIBRARY_NAME\s+=).*/$1 '\''mozjs45-ps-release'\''/' moz.build mkdir -p build-release cd build-release -CXXFLAGS="${CXXFLAGS} ${TLCXXFLAGS}" ../configure ${CONF_OPTS} --with-nspr-libs="$NSPR_LIBS" --with-nspr-cflags="$NSPR_INCLUDES" --enable-optimize # --enable-gczeal --enable-debug-symbols +if [ "${OS}" = "Windows_NT" ] +then + CXXFLAGS="${CXXFLAGS} ${TLCXXFLAGS}" ../configure ${CONF_OPTS} --with-nspr-cflags="${NSPR_INCLUDES}" --with-nspr-libs="${NSPR_LIBS}" --enable-optimize # --enable-gczeal --enable-debug-symbols +else + CXXFLAGS="${CXXFLAGS} ${TLCXXFLAGS}" ../configure ${CONF_OPTS} --enable-optimize # --enable-gczeal --enable-debug-symbols +fi ${MAKE} ${MAKE_OPTS} cd .. @@ -147,12 +157,12 @@ # Bug #776126 # SpiderMonkey uses a tweaked zlib when building, and it wrongly copies its own files to include dirs # afterwards, so we have to remove them to not have them conflicting with the regular zlib - cd ${FOLDER}/js/src/build-release/dist/include + pushd ${FOLDER}/js/src/build-release/dist/include rm mozzconf.h zconf.h zlib.h - cd ../../../../../.. - cd ${FOLDER}/js/src/build-debug/dist/include + popd + pushd ${FOLDER}/js/src/build-debug/dist/include rm mozzconf.h zconf.h zlib.h - cd ../../../../../.. + popd fi # Copy files into the necessary locations for building and running the game @@ -164,16 +174,16 @@ cp -R -L ${FOLDER}/js/src/build-debug/dist/include/* ${INCLUDE_DIR_DEBUG}/ mkdir -p lib/ -cp -L ${FOLDER}/js/src/build-debug/dist/lib/${LIB_PREFIX}mozjs38-ps-debug${LIB_SRC_SUFFIX} lib/${LIB_PREFIX}mozjs38-ps-debug${LIB_DST_SUFFIX} -cp -L ${FOLDER}/js/src/build-release/dist/lib/${LIB_PREFIX}mozjs38-ps-release${LIB_SRC_SUFFIX} lib/${LIB_PREFIX}mozjs38-ps-release${LIB_DST_SUFFIX} -cp -L ${FOLDER}/js/src/build-debug/dist/bin/${LIB_PREFIX}mozjs38-ps-debug${DLL_SRC_SUFFIX} ../../../binaries/system/${LIB_PREFIX}mozjs38-ps-debug${DLL_DST_SUFFIX} -cp -L ${FOLDER}/js/src/build-release/dist/bin/${LIB_PREFIX}mozjs38-ps-release${DLL_SRC_SUFFIX} ../../../binaries/system/${LIB_PREFIX}mozjs38-ps-release${DLL_DST_SUFFIX} +cp -L ${FOLDER}/js/src/build-debug/dist/sdk/lib/${LIB_PREFIX}mozjs45-ps-debug${LIB_SRC_SUFFIX} lib/${LIB_PREFIX}mozjs45-ps-debug${LIB_DST_SUFFIX} +cp -L ${FOLDER}/js/src/build-release/dist/sdk/lib/${LIB_PREFIX}mozjs45-ps-release${LIB_SRC_SUFFIX} lib/${LIB_PREFIX}mozjs45-ps-release${LIB_DST_SUFFIX} +cp -L ${FOLDER}/js/src/build-debug/dist/bin/${LIB_PREFIX}mozjs45-ps-debug${DLL_SRC_SUFFIX} ../../../binaries/system/${LIB_PREFIX}mozjs45-ps-debug${DLL_DST_SUFFIX} +cp -L ${FOLDER}/js/src/build-release/dist/bin/${LIB_PREFIX}mozjs45-ps-release${DLL_SRC_SUFFIX} ../../../binaries/system/${LIB_PREFIX}mozjs45-ps-release${DLL_DST_SUFFIX} # On Windows, also copy debugging symbols files if [ "${OS}" = "Windows_NT" ] then - cp -L ${FOLDER}/js/src/build-debug/js/src/${LIB_PREFIX}mozjs38-ps-debug.pdb ../../../binaries/system/${LIB_PREFIX}mozjs38-ps-debug.pdb - cp -L ${FOLDER}/js/src/build-release/js/src/${LIB_PREFIX}mozjs38-ps-release.pdb ../../../binaries/system/${LIB_PREFIX}mozjs38-ps-release.pdb + cp -L ${FOLDER}/js/src/build-debug/js/src/${LIB_PREFIX}mozjs45-ps-debug.pdb ../../../binaries/system/${LIB_PREFIX}mozjs45-ps-debug.pdb + cp -L ${FOLDER}/js/src/build-release/js/src/${LIB_PREFIX}mozjs45-ps-release.pdb ../../../binaries/system/${LIB_PREFIX}mozjs45-ps-release.pdb fi # Flag that it's already been built successfully so we can skip it next time Index: libraries/source/spidermonkey/mozjs-45.0.2.REPLACEME.txt =================================================================== --- /dev/null +++ libraries/source/spidermonkey/mozjs-45.0.2.REPLACEME.txt @@ -0,0 +1,2 @@ +Replace me with +https://ftp.mozilla.org/pub/spidermonkey/releases/45.0.2/ Index: libraries/source/spidermonkey/patch.sh =================================================================== --- libraries/source/spidermonkey/patch.sh +++ libraries/source/spidermonkey/patch.sh @@ -2,45 +2,23 @@ # Apply patches if needed # This script gets called from build-osx-libs.sh and build.sh. -# Fix the version specification code which used PYTHON before it was set. -# The second patch is required to not add autoconf as a dependency. -patch -p1 < ../FixVersionDetection.diff -patch -p1 < ../FixVersionDetectionConfigure.diff +# Remove the unnecessary NSPR dependency. +# Will be included in SM52. +# https://bugzilla.mozilla.org/show_bug.cgi?id=1379539 +patch -p1 < ../RemoveNSPRDependency.diff # Fix the path to the moz.build file in the zlib module patch -p1 < ../FixZLibMozBuild.diff -# === Fix the SM38 tracelogger === +# === Fix the SM45 tracelogger === # This patch is a squashed version of several patches that were adapted # to fix failing hunks. # # Applied in the following order, they are: -# * https://bugzilla.mozilla.org/show_bug.cgi?id=1223767 -# Assertion failure: i < size_, at js/src/vm/TraceLoggingTypes.h:210 -# Also fix stop-information to make reduce.py work correctly. -# * https://bugzilla.mozilla.org/show_bug.cgi?id=1227914 -# Limit the memory tracelogger can take. -# This causes tracelogger to flush data to the disk regularly and prevents out of -# memory issues if a lot of data gets logged. -# * https://bugzilla.mozilla.org/show_bug.cgi?id=1155618 -# Fix tracelogger destructor that touches possibly uninitialised hash table. -# * https://bugzilla.mozilla.org/show_bug.cgi?id=1223636 -# Don't treat extraTextId as containing only extra ids. -# This fixes an assertion failure: id == nextTextId at js/src/vm/TraceLoggingGraph.cpp -# * https://bugzilla.mozilla.org/show_bug.cgi?id=1227028 -# Fix when to keep the payload of a TraceLogger event. -# This fixes an assertion failure: textId < uint32_t(1 << 31) at js/src/vm/TraceLoggingGraph.h # * https://bugzilla.mozilla.org/show_bug.cgi?id=1266649 # Handle failing to add to pointermap gracefully. # * https://bugzilla.mozilla.org/show_bug.cgi?id=1280648 # Don't cache based on pointers to movable GC things. -# * https://bugzilla.mozilla.org/show_bug.cgi?id=1224123 -# Fix the use of LastEntryId in tracelogger.h. -# * https://bugzilla.mozilla.org/show_bug.cgi?id=1231170 -# Use size in debugger instead of the current id to track last logged item. -# * https://bugzilla.mozilla.org/show_bug.cgi?id=1221844 -# Move TraceLogger_Invalidation to LOG_ITEM. -# Add some debug checks to logTimestamp. # * https://bugzilla.mozilla.org/show_bug.cgi?id=1255766 # Also mark resizing of memory. # * https://bugzilla.mozilla.org/show_bug.cgi?id=1259403 @@ -51,5 +29,21 @@ # Patch embedded python psutil to work with FreeBSD 12 after revision 315662 # Based on: https://svnweb.freebsd.org/ports/head/sysutils/py-psutil121/files/patch-_psutil_bsd.c?revision=436575&view=markup -# Related: https://bugzilla.mozilla.org/show_bug.cgi?id=1238983 +# psutil will be upgraded in SM60: https://bugzilla.mozilla.org/show_bug.cgi?id=1436857 patch -p0 < ../FixpsutilFreeBSD.diff + +# Always link mozglue into the shared library when building standalone. +# Will be included in SM60. Custom version of the patch for SM45, which doesn't have the same build system. +# https://bugzilla.mozilla.org/show_bug.cgi?id=1176787 +patch -p1 < ../FixMozGlueStatic.diff + +# JSPropertyDescriptor is not public in SM45. +# Will be fixed in SM52. +# https://bugzilla.mozilla.org/show_bug.cgi?id=1316079 +patch -p1 < ../ExportJSPropertyDescriptor.diff + +# When trying to link pyrogenesis, js::oom::GetThreadType() and js::ReportOutOfMemory() +# are marked as unresolved symbols. +# Will be included in SM52. +# https://bugzilla.mozilla.org/show_bug.cgi?id=1379538 +patch -p1 < ../FixLinking.diff Index: source/gui/IGUIObject.h =================================================================== --- source/gui/IGUIObject.h +++ source/gui/IGUIObject.h @@ -85,7 +85,7 @@ // Allow getProperty to access things like GetParent() friend bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp); - friend bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, bool UNUSED(strict), JS::MutableHandleValue vp); + friend bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, JS::ObjectOpResult& result); friend bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint argc, JS::Value* vp); public: Index: source/gui/IGUIObject.cpp =================================================================== --- source/gui/IGUIObject.cpp +++ source/gui/IGUIObject.cpp @@ -412,7 +412,6 @@ JS::CompileOptions options(cx); options.setFileAndLine(CodeName.c_str(), 0); - options.setCompileAndGo(true); JS::RootedFunction func(cx); JS::AutoObjectVector emptyScopeChain(cx); Index: source/gui/scripting/JSInterface_IGUIObject.h =================================================================== --- source/gui/scripting/JSInterface_IGUIObject.h +++ source/gui/scripting/JSInterface_IGUIObject.h @@ -26,7 +26,7 @@ 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); + bool setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, JS::ObjectOpResult& result); 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); Index: source/gui/scripting/JSInterface_IGUIObject.cpp =================================================================== --- source/gui/scripting/JSInterface_IGUIObject.cpp +++ source/gui/scripting/JSInterface_IGUIObject.cpp @@ -317,28 +317,28 @@ } } -bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, bool UNUSED(strict), JS::MutableHandleValue vp) +bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, JS::ObjectOpResult& result) { IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, obj, &JSI_IGUIObject::JSI_class, NULL); if (!e) - return false; + return result.fail(JSMSG_NOT_NONNULL_OBJECT); JSAutoRequest rq(cx); JS::RootedValue idval(cx); if (!JS_IdToValue(cx, id, &idval)) - return false; + return result.fail(JSMSG_NOT_NONNULL_OBJECT); std::string propName; if (!ScriptInterface::FromJSVal(cx, idval, propName)) - return false; + return result.fail(JSMSG_UNDEFINED_PROP); if (propName == "name") { std::string value; if (!ScriptInterface::FromJSVal(cx, vp, value)) - return false; + return result.fail(JSMSG_UNDEFINED_PROP); e->SetName(value); - return true; + return result.succeed(); } JS::RootedObject vpObj(cx); @@ -351,13 +351,13 @@ if (vp.isPrimitive() || vp.isNull() || !JS_ObjectIsFunction(cx, &vp.toObject())) { JS_ReportError(cx, "on- event-handlers must be functions"); - return false; + return result.fail(JSMSG_NOT_FUNCTION); } CStr eventName(CStr(propName.substr(2)).LowerCase()); e->SetScriptHandler(eventName, vpObj); - return true; + return result.succeed(); } // Retrieve the setting's type (and make sure it actually exists) @@ -365,7 +365,7 @@ if (e->GetSettingType(propName, Type) != PSRETURN_OK) { JS_ReportError(cx, "Invalid setting '%s'", propName.c_str()); - return true; + return result.fail(JSMSG_TYPE_ERR_BAD_ARGS); } switch (Type) @@ -374,7 +374,7 @@ { std::string value; if (!ScriptInterface::FromJSVal(cx, vp, value)) - return false; + return result.fail(JSMSG_UNDEFINED_PROP); GUI::SetSetting(e, propName, value); break; @@ -384,7 +384,7 @@ { std::wstring value; if (!ScriptInterface::FromJSVal(cx, vp, value)) - return false; + return result.fail(JSMSG_UNDEFINED_PROP); GUI::SetSetting(e, propName, value); break; @@ -394,7 +394,7 @@ { std::string value; if (!ScriptInterface::FromJSVal(cx, vp, value)) - return false; + return result.fail(JSMSG_UNDEFINED_PROP); GUI::SetSetting(e, propName, CGUISpriteInstance(value)); break; @@ -404,7 +404,7 @@ { std::wstring value; if (!ScriptInterface::FromJSVal(cx, vp, value)) - return false; + return result.fail(JSMSG_UNDEFINED_PROP); CGUIString str; str.SetValue(value); @@ -416,7 +416,7 @@ { std::string value; if (!ScriptInterface::FromJSVal(cx, vp, value)) - return false; + return result.fail(JSMSG_UNDEFINED_PROP); EAlign a; if (value == "left") a = EAlign_Left; @@ -425,7 +425,7 @@ else { JS_ReportError(cx, "Invalid alignment (should be 'left', 'right' or 'center')"); - return false; + return result.fail(JSMSG_TYPE_ERR_BAD_ARGS); } GUI::SetSetting(e, propName, a); break; @@ -435,7 +435,7 @@ { std::string value; if (!ScriptInterface::FromJSVal(cx, vp, value)) - return false; + return result.fail(JSMSG_UNDEFINED_PROP); EVAlign a; if (value == "top") a = EVAlign_Top; @@ -444,7 +444,7 @@ else { JS_ReportError(cx, "Invalid alignment (should be 'top', 'bottom' or 'center')"); - return false; + return result.fail(JSMSG_TYPE_ERR_BAD_ARGS); } GUI::SetSetting(e, propName, a); break; @@ -458,7 +458,7 @@ else { JS_ReportError(cx, "Cannot convert value to int"); - return false; + return result.fail(JSMSG_TYPE_ERR_BAD_ARGS); } break; } @@ -471,7 +471,7 @@ else { JS_ReportError(cx, "Cannot convert value to u32"); - return false; + return result.fail(JSMSG_TYPE_ERR_BAD_ARGS); } break; } @@ -484,7 +484,7 @@ else { JS_ReportError(cx, "Cannot convert value to float"); - return false; + return result.fail(JSMSG_TYPE_ERR_BAD_ARGS); } break; } @@ -502,12 +502,12 @@ { std::wstring value; if (!ScriptInterface::FromJSVal(cx, vp, value)) - return false; + return result.fail(JSMSG_UNDEFINED_PROP); if (e->SetSetting(propName, value) != PSRETURN_OK) { JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str()); - return false; + return result.fail(JSMSG_TYPE_ERR_BAD_ARGS); } } else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUISize::JSI_class, NULL)) @@ -532,7 +532,7 @@ else { JS_ReportError(cx, "Size only accepts strings or GUISize objects"); - return false; + return result.fail(JSMSG_TYPE_ERR_BAD_ARGS); } break; } @@ -543,12 +543,12 @@ { std::wstring value; if (!ScriptInterface::FromJSVal(cx, vp, value)) - return false; + return result.fail(JSMSG_UNDEFINED_PROP); if (e->SetSetting(propName, value) != PSRETURN_OK) { JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str()); - return false; + return result.fail(JSMSG_TYPE_ERR_BAD_ARGS); } } else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUIColor::JSI_class, NULL)) @@ -571,7 +571,7 @@ else { JS_ReportError(cx, "Color only accepts strings or GUIColor objects"); - return false; + return result.fail(JSMSG_TYPE_ERR_BAD_ARGS); } break; } @@ -584,7 +584,7 @@ else { JS_ReportError(cx, "Failed to get list '%s'", propName.c_str()); - return false; + return result.fail(JSMSG_TYPE_ERR_BAD_ARGS); } break; } @@ -597,7 +597,7 @@ else { JS_ReportError(cx, "Invalid value for chart series '%s'", propName.c_str()); - return false; + return result.fail(JSMSG_TYPE_ERR_BAD_ARGS); } break; } @@ -607,7 +607,7 @@ break; } - return !JS_IsExceptionPending(cx); + return result.succeed() && !JS_IsExceptionPending(cx); } @@ -635,7 +635,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, NULL, NULL); } bool JSI_IGUIObject::toString(JSContext* cx, uint UNUSED(argc), JS::Value* vp) Index: source/ps/ModIo.cpp =================================================================== --- source/ps/ModIo.cpp +++ source/ps/ModIo.cpp @@ -591,7 +591,8 @@ JS::RootedObject data(cx, dataVal.toObjectOrNull()); u32 length; - if (!JS_IsArrayObject(cx, data) || !JS_GetArrayLength(cx, data, &length) || !length) + bool isArray; + if (!JS_IsArrayObject(cx, data, &isArray) || !JS_GetArrayLength(cx, data, &length) || !length) FAIL("data property not an array with at least one element."); // {"id": 42, ...} @@ -662,7 +663,8 @@ JS::RootedObject data(cx, dataVal.toObjectOrNull()); u32 length; - if (!JS_IsArrayObject(cx, data) || !JS_GetArrayLength(cx, data, &length) || !length) + bool isArray; + if (!JS_IsArrayObject(cx, data, &isArray) || !JS_GetArrayLength(cx, data, &length) || !length) FAIL("data property not an array with at least one element."); modData.clear(); Index: source/ps/VisualReplay.cpp =================================================================== --- source/ps/VisualReplay.cpp +++ source/ps/VisualReplay.cpp @@ -80,7 +80,8 @@ if (scriptInterface.ParseJSON(cacheStr, &cachedReplays)) { cachedReplaysObject.set(&cachedReplays.toObject()); - if (JS_IsArrayObject(cx, cachedReplaysObject)) + bool isArray; + if (JS_IsArrayObject(cx, cachedReplaysObject, &isArray)) return true; } Index: source/scriptinterface/ScriptConversions.h =================================================================== --- source/scriptinterface/ScriptConversions.h +++ source/scriptinterface/ScriptConversions.h @@ -52,8 +52,9 @@ if (!v.isObject()) FAIL("Argument must be an array"); + bool isArray; obj = &v.toObject(); - if (!(JS_IsArrayObject(cx, obj) || JS_IsTypedArrayObject(obj))) + if (!(JS_IsArrayObject(cx, obj, &isArray) || JS_IsTypedArrayObject(obj))) FAIL("Argument must be an array"); u32 length; Index: source/scriptinterface/ScriptEngine.h =================================================================== --- source/scriptinterface/ScriptEngine.h +++ source/scriptinterface/ScriptEngine.h @@ -21,6 +21,8 @@ #include "ScriptTypes.h" #include "ps/Singleton.h" +#include "js/Initialization.h" + /** * A class using the RAII (Resource Acquisition Is Initialization) idiom to manage initialization * and shutdown of the SpiderMonkey script engine. It also keeps a count of active script runtimes Index: source/scriptinterface/ScriptInterface.cpp =================================================================== --- source/scriptinterface/ScriptInterface.cpp +++ source/scriptinterface/ScriptInterface.cpp @@ -102,17 +102,20 @@ JS::RootedValue excn(cx); if (JS_GetPendingException(cx, &excn) && excn.isObject()) { - JS::RootedObject excnObj(cx, &excn.toObject()); // TODO: this violates the docs ("The error reporter callback must not reenter the JSAPI.") + // In case there is an exception raised in the code below, we'll have an infinite loop. - // Hide the exception from EvaluateScript + // Hide the exception from Evaluate JSExceptionState* excnState = JS_SaveExceptionState(cx); JS_ClearPendingException(cx); JS::RootedValue rval(cx); - const char dumpStack[] = "this.stack.trimRight().replace(/^/mg, ' ')"; // indent each line + const char dumpStack[] = "function __stackTrace(a) { return a.stack.trimRight().replace(/^/mg, ' '); }"; // indent each line JS::CompileOptions opts(cx); - if (JS::Evaluate(cx, excnObj, opts.setFileAndLine("(eval)", 1), dumpStack, ARRAY_SIZE(dumpStack)-1, &rval)) + JS::Evaluate(cx, opts.setFileAndLine("(ErrorReporter)", 1), dumpStack, ARRAY_SIZE(dumpStack)-1, &rval); + + JS::RootedObject glob(cx, JS::CurrentGlobalOrNull(cx)); + if (JS_CallFunctionName(cx, glob, "__stackTrace", JS::HandleValueArray(excn), &rval)) { std::string stackTrace; if (ScriptInterface::FromJSVal(cx, rval, stackTrace)) @@ -366,7 +369,6 @@ JS::RuntimeOptionsRef(m_cx).setExtraWarnings(1) .setWerror(0) - .setVarObjFix(1) .setStrictMode(1); JS::CompartmentOptions opt; @@ -551,7 +553,7 @@ } JS::RootedObject global(m->m_cx, m->m_glob); - JS::RootedObject obj(m->m_cx, JS_InitClass(m->m_cx, global, JS::NullPtr(), + JS::RootedObject obj(m->m_cx, JS_InitClass(m->m_cx, global, nullptr, clasp, constructor, minArgs, // Constructor, min args ps, fs, // Properties, methods @@ -759,8 +761,9 @@ return true; // reached the end of the prototype chain JS::RootedObject obj(m->m_cx, &objVal.toObject()); - JS::AutoIdArray props(m->m_cx, JS_Enumerate(m->m_cx, obj)); - if (!props) + JS::Rooted props(m->m_cx, m->m_cx); + bool hasProps = JS_Enumerate(m->m_cx, obj, &props); + if (!hasProps) return false; for (size_t i = 0; i < props.length(); ++i) @@ -848,7 +851,6 @@ JS::CompileOptions options(m->m_cx); options.setFileAndLine(filenameStr.c_str(), lineNo); - options.setCompileAndGo(true); JS::RootedFunction func(m->m_cx); JS::AutoObjectVector emptyScopeChain(m->m_cx); @@ -857,7 +859,7 @@ return false; JS::RootedValue rval(m->m_cx); - return JS_CallFunction(m->m_cx, JS::NullPtr(), func, JS::HandleValueArray::empty(), &rval); + return JS_CallFunction(m->m_cx, nullptr, func, JS::HandleValueArray::empty(), &rval); } shared_ptr ScriptInterface::CreateRuntime(shared_ptr parentRuntime, int runtimeSize, int heapGrowthBytesGCTrigger) @@ -868,7 +870,6 @@ bool ScriptInterface::LoadGlobalScript(const VfsPath& filename, const std::wstring& code) const { JSAutoRequest rq(m->m_cx); - JS::RootedObject global(m->m_cx, m->m_glob); utf16string codeUtf16(code.begin(), code.end()); uint lineNo = 1; // CompileOptions does not copy the contents of the filename string pointer. @@ -878,14 +879,13 @@ JS::RootedValue rval(m->m_cx); JS::CompileOptions opts(m->m_cx); opts.setFileAndLine(filenameStr.c_str(), lineNo); - return JS::Evaluate(m->m_cx, global, opts, + return JS::Evaluate(m->m_cx, opts, reinterpret_cast(codeUtf16.c_str()), (uint)(codeUtf16.length()), &rval); } bool ScriptInterface::LoadGlobalScriptFile(const VfsPath& path) const { JSAutoRequest rq(m->m_cx); - JS::RootedObject global(m->m_cx, m->m_glob); if (!VfsFileExists(path)) { LOGERROR("File '%s' does not exist", path.string8()); @@ -913,7 +913,7 @@ JS::RootedValue rval(m->m_cx); JS::CompileOptions opts(m->m_cx); opts.setFileAndLine(filenameStr.c_str(), lineNo); - return JS::Evaluate(m->m_cx, global, opts, + return JS::Evaluate(m->m_cx, opts, reinterpret_cast(codeUtf16.c_str()), (uint)(codeUtf16.length()), &rval); } @@ -927,23 +927,21 @@ bool ScriptInterface::Eval_(const char* code, JS::MutableHandleValue rval) const { JSAutoRequest rq(m->m_cx); - JS::RootedObject global(m->m_cx, m->m_glob); utf16string codeUtf16(code, code+strlen(code)); JS::CompileOptions opts(m->m_cx); opts.setFileAndLine("(eval)", 1); - return JS::Evaluate(m->m_cx, global, opts, reinterpret_cast(codeUtf16.c_str()), (uint)codeUtf16.length(), rval); + return JS::Evaluate(m->m_cx, opts, reinterpret_cast(codeUtf16.c_str()), (uint)codeUtf16.length(), rval); } bool ScriptInterface::Eval_(const wchar_t* code, JS::MutableHandleValue rval) const { JSAutoRequest rq(m->m_cx); - JS::RootedObject global(m->m_cx, m->m_glob); utf16string codeUtf16(code, code+wcslen(code)); JS::CompileOptions opts(m->m_cx); opts.setFileAndLine("(eval)", 1); - return JS::Evaluate(m->m_cx, global, opts, reinterpret_cast(codeUtf16.c_str()), (uint)codeUtf16.length(), rval); + return JS::Evaluate(m->m_cx, opts, reinterpret_cast(codeUtf16.c_str()), (uint)codeUtf16.length(), rval); } bool ScriptInterface::ParseJSON(const std::string& string_utf8, JS::MutableHandleValue out) const @@ -1024,7 +1022,7 @@ JSAutoRequest rq(m->m_cx); Stringifier str; JS::RootedValue indentVal(m->m_cx, indent ? JS::Int32Value(2) : JS::UndefinedValue()); - if (!JS_Stringify(m->m_cx, obj, JS::NullPtr(), indentVal, &Stringifier::callback, &str)) + if (!JS_Stringify(m->m_cx, obj, nullptr, indentVal, &Stringifier::callback, &str)) { JS_ClearPendingException(m->m_cx); LOGERROR("StringifyJSON failed"); @@ -1052,7 +1050,7 @@ // Temporary disable the error reporter, so we don't print complaints about cyclic values JSErrorReporter er = JS_SetErrorReporter(m->m_runtime->m_rt, NULL); - bool ok = JS_Stringify(m->m_cx, obj, JS::NullPtr(), indentVal, &Stringifier::callback, &str); + bool ok = JS_Stringify(m->m_cx, obj, nullptr, indentVal, &Stringifier::callback, &str); // Restore error reporter JS_SetErrorReporter(m->m_runtime->m_rt, er); Index: source/scriptinterface/ScriptTypes.h =================================================================== --- source/scriptinterface/ScriptTypes.h +++ source/scriptinterface/ScriptTypes.h @@ -71,7 +71,7 @@ # pragma GCC diagnostic pop #endif -#if MOZJS_MAJOR_VERSION != 38 +#if MOZJS_MAJOR_VERSION != 45 #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 \ @@ -79,7 +79,7 @@ include paths. #endif -#if MOZJS_MINOR_VERSION != 3 +#if MOZJS_MINOR_VERSION != 0 #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/components/CCmpAIManager.cpp =================================================================== --- source/simulation2/components/CCmpAIManager.cpp +++ source/simulation2/components/CCmpAIManager.cpp @@ -554,8 +554,9 @@ ENSURE(JS_GetArrayLength(cx, dataObj, &length)); u32 nbytes = (u32)(length * sizeof(NavcellData)); + bool sharedMemory; JS::AutoCheckCannotGC nogc; - memcpy((void*)JS_GetUint16ArrayData(dataObj, nogc), m_PassabilityMap.m_Data, nbytes); + memcpy((void*)JS_GetUint16ArrayData(dataObj, &sharedMemory, nogc), m_PassabilityMap.m_Data, nbytes); } } @@ -583,8 +584,9 @@ ENSURE(JS_GetArrayLength(cx, dataObj, &length)); u32 nbytes = (u32)(length * sizeof(u8)); + bool sharedMemory; JS::AutoCheckCannotGC nogc; - memcpy((void*)JS_GetUint8ArrayData(dataObj, nogc), m_TerritoryMap.m_Data, nbytes); + memcpy((void*)JS_GetUint8ArrayData(dataObj, &sharedMemory, nogc), m_TerritoryMap.m_Data, nbytes); } } Index: source/simulation2/scripting/EngineScriptConversions.cpp =================================================================== --- source/simulation2/scripting/EngineScriptConversions.cpp +++ source/simulation2/scripting/EngineScriptConversions.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -256,7 +256,8 @@ // Copy the array data and then remove the no-GC check to allow further changes to the JS data { JS::AutoCheckCannotGC nogc; - memcpy((void*)JS_GetUint8ArrayData(objArr, nogc), val.m_Data, nbytes); + bool sharedMemory; + memcpy((void*)JS_GetUint8ArrayData(objArr, &sharedMemory, nogc), val.m_Data, nbytes); } JS::RootedValue data(cx, JS::ObjectValue(*objArr)); @@ -282,7 +283,8 @@ // Copy the array data and then remove the no-GC check to allow further changes to the JS data { JS::AutoCheckCannotGC nogc; - memcpy((void*)JS_GetUint16ArrayData(objArr, nogc), val.m_Data, nbytes); + bool sharedMemory; + memcpy((void*)JS_GetUint16ArrayData(objArr, &sharedMemory, nogc), val.m_Data, nbytes); } JS::RootedValue data(cx, JS::ObjectValue(*objArr)); @@ -306,7 +308,8 @@ JSAutoRequest rq(cx); JS::RootedObject obj(cx, &v.toObject()); - if (!JS_IsArrayObject(cx, obj)) + bool isArray; + if (!JS_IsArrayObject(cx, obj, &isArray)) FAIL("Argument must be an array"); u32 numberOfNodes = 0; Index: source/simulation2/serialization/BinarySerializer.cpp =================================================================== --- source/simulation2/serialization/BinarySerializer.cpp +++ source/simulation2/serialization/BinarySerializer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2018 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,8 @@ } // Arrays are special cases of Object - if (JS_IsArrayObject(cx, obj)) + bool isArray; + if (JS_IsArrayObject(cx, obj, &isArray)) { m_Serializer.NumberU8_Unbounded("type", SCRIPT_TYPE_ARRAY); // TODO: probably should have a more efficient storage format @@ -119,9 +120,10 @@ m_Serializer.NumberU32_Unbounded("byte offset", JS_GetTypedArrayByteOffset(obj)); m_Serializer.NumberU32_Unbounded("length", JS_GetTypedArrayLength(obj)); + bool sharedMemory; // Now handle its array buffer // this may be a backref, since ArrayBuffers can be shared by multiple views - JS::RootedValue bufferVal(cx, JS::ObjectValue(*JS_GetArrayBufferViewBuffer(cx, obj))); + JS::RootedValue bufferVal(cx, JS::ObjectValue(*JS_GetArrayBufferViewBuffer(cx, obj, &sharedMemory))); HandleScriptVal(bufferVal); break; } @@ -136,7 +138,8 @@ u32 length = JS_GetArrayBufferByteLength(obj); m_Serializer.NumberU32_Unbounded("buffer length", length); JS::AutoCheckCannotGC nogc; - m_Serializer.RawBytes("buffer data", (const u8*)JS_GetArrayBufferData(obj, nogc), length); + bool sharedMemory; + m_Serializer.RawBytes("buffer data", (const u8*)JS_GetArrayBufferData(obj, &sharedMemory, nogc), length); break; } else @@ -145,11 +148,8 @@ const JSClass* jsclass = JS_GetClass(obj); if (!jsclass) throw PSERROR_Serialize_ScriptError("JS_GetClass failed"); -// TODO: Remove this workaround for upstream API breakage when updating SpiderMonkey -// See https://bugzilla.mozilla.org/show_bug.cgi?id=1236373 -#define JSCLASS_CACHED_PROTO_WIDTH js::JSCLASS_CACHED_PROTO_WIDTH + JSProtoKey protokey = JSCLASS_CACHED_PROTO_KEY(jsclass); -#undef JSCLASS_CACHED_PROTO_WIDTH if (protokey == JSProto_Object) { @@ -302,8 +302,9 @@ } // Find all properties (ordered by insertion time) - JS::AutoIdArray ida (cx, JS_Enumerate(cx, obj)); - if (!ida) + JS::Rooted ida(cx, cx); + bool hasProps = JS_Enumerate(cx, obj, &ida); + if (!hasProps) throw PSERROR_Serialize_ScriptError("JS_Enumerate failed"); m_Serializer.NumberU32_Unbounded("num props", (u32)ida.length()); Index: source/simulation2/serialization/StdDeserializer.cpp =================================================================== --- source/simulation2/serialization/StdDeserializer.cpp +++ source/simulation2/serialization/StdDeserializer.cpp @@ -218,7 +218,7 @@ { std::vector propname; ReadStringLatin1("prop name", propname); - JS::RootedValue propval(cx, ReadScriptVal("prop value", JS::NullPtr())); + JS::RootedValue propval(cx, ReadScriptVal("prop value", nullptr)); utf16string prp(propname.begin(), propname.end());; // TODO: Should ask upstream about getting a variant of JS_SetProperty with a length param. @@ -229,7 +229,7 @@ { utf16string propname; ReadStringUTF16("prop name", propname); - JS::RootedValue propval(cx, ReadScriptVal("prop value", JS::NullPtr())); + JS::RootedValue propval(cx, ReadScriptVal("prop value", nullptr)); if (!JS_SetUCProperty(cx, obj, (const char16_t*)propname.data(), propname.length(), propval)) throw PSERROR_Deserialize_ScriptError(); @@ -338,7 +338,7 @@ AddScriptBackref(arrayObj); // Get buffer object - JS::RootedValue bufferVal(cx, ReadScriptVal("buffer", JS::NullPtr())); + JS::RootedValue bufferVal(cx, ReadScriptVal("buffer", nullptr)); if (!bufferVal.isObject()) throw PSERROR_Deserialize_ScriptError(); @@ -410,8 +410,8 @@ for (u32 i=0; i(text.data()), text.length())); + JS::RootedString str(cx, JS_AtomizeAndPinUCStringN(cx, reinterpret_cast(text.data()), text.length())); if (str) { ret.setString(str); @@ -415,7 +415,7 @@ if (!m_Value.empty()) { utf16string text(m_Value.begin(), m_Value.end()); - JS::RootedString str(cx, JS_InternUCStringN(cx, reinterpret_cast(text.data()), text.length())); + JS::RootedString str(cx, JS_AtomizeAndPinUCStringN(cx, reinterpret_cast(text.data()), text.length())); if (!str) { ret.setUndefined();