mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-28 23:13:09 +00:00
Adapt 0 A.D. to SpiderMonkey ESR 102
This follows the migration guide at: https://github.com/mozilla-spidermonkey/spidermonkey-embedding-examples Based on patch by: wraitii Differential Revision: https://code.wildfiregames.com/D5002
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -41,7 +41,7 @@ inline bool GetProperty(const ScriptRequest& rq, JS::HandleValue obj, PropType n
|
||||
JS::RootedObject object(rq.cx, &obj.toObject());
|
||||
if constexpr (std::is_same_v<int, PropType>)
|
||||
{
|
||||
JS::RootedId id(rq.cx, INT_TO_JSID(name));
|
||||
JS::RootedId id(rq.cx, JS::PropertyKey::Int(name));
|
||||
return JS_GetPropertyById(rq.cx, object, id, out);
|
||||
}
|
||||
else if constexpr (std::is_same_v<const char*, PropType>)
|
||||
@@ -108,7 +108,7 @@ inline bool SetProperty(const ScriptRequest& rq, JS::HandleValue obj, PropType n
|
||||
JS::RootedObject object(rq.cx, &obj.toObject());
|
||||
if constexpr (std::is_same_v<int, PropType>)
|
||||
{
|
||||
JS::RootedId id(rq.cx, INT_TO_JSID(name));
|
||||
JS::RootedId id(rq.cx, JS::PropertyKey::Int(name));
|
||||
return JS_DefinePropertyById(rq.cx, object, id, value, attrs);
|
||||
}
|
||||
else if constexpr (std::is_same_v<const char*, PropType>)
|
||||
|
||||
@@ -171,7 +171,7 @@ void ScriptContext::MaybeIncrementalGC(double delay)
|
||||
// The sweeping actually frees memory and it does this in a background thread (if JS_USE_HELPER_THREADS is set).
|
||||
// While the sweeping is happening we already run scripts again and produce new garbage.
|
||||
|
||||
const int GCSliceTimeBudget = 30; // Milliseconds an incremental slice is allowed to run
|
||||
const js::SliceBudget GCSliceTimeBudget = js::SliceBudget(js::TimeBudget(30)); // Milliseconds an incremental slice is allowed to run
|
||||
|
||||
// Have a minimum time in seconds to wait between GC slices and before starting a new GC to distribute the GC
|
||||
// load and to hopefully make it unnoticeable for the player. This value should be high enough to distribute
|
||||
|
||||
@@ -107,7 +107,7 @@ JSClassOps global_classops = {
|
||||
nullptr, nullptr,
|
||||
nullptr, nullptr,
|
||||
nullptr, nullptr, nullptr,
|
||||
nullptr, nullptr, nullptr,
|
||||
nullptr, nullptr,
|
||||
JS_GlobalObjectTraceHook
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -229,12 +229,21 @@ public:
|
||||
static bool Math_random(JSContext* cx, uint argc, JS::Value* vp);
|
||||
|
||||
/**
|
||||
* Retrieve the private data field of a JSObject that is an instance of the given JSClass.
|
||||
* Name the reserved slots we may need to use in custom JSObjects.
|
||||
* When using JSCLASS_HAS_RESERVED_SLOTS in the definition of your JSClass, use the number
|
||||
* of the highest slot you need plus 1.
|
||||
*/
|
||||
enum JSObjectReservedSlots {
|
||||
PRIVATE = 0
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the private data field of a JSObject.
|
||||
*/
|
||||
template <typename T>
|
||||
static T* GetPrivate(const ScriptRequest& rq, JS::HandleObject thisobj, JSClass* jsClass)
|
||||
static T* GetPrivate(const ScriptRequest& rq, JS::HandleObject thisobj)
|
||||
{
|
||||
T* value = static_cast<T*>(JS_GetInstancePrivate(rq.cx, thisobj, jsClass, nullptr));
|
||||
T* value = JS::GetMaybePtrFromReservedSlot<T>(thisobj, JSObjectReservedSlots::PRIVATE);
|
||||
|
||||
if (value == nullptr)
|
||||
ScriptException::Raise(rq, "Private data of the given object is null!");
|
||||
@@ -243,20 +252,20 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the private data field of a JS Object that is an instance of the given JSClass.
|
||||
* Retrieve the private data field of a JS Object.
|
||||
* If an error occurs, GetPrivate will report it with the according stack.
|
||||
*/
|
||||
template <typename T>
|
||||
static T* GetPrivate(const ScriptRequest& rq, JS::CallArgs& callArgs, JSClass* jsClass)
|
||||
static T* GetPrivate(const ScriptRequest& rq, JS::CallArgs& callArgs)
|
||||
{
|
||||
if (!callArgs.thisv().isObject())
|
||||
{
|
||||
ScriptException::Raise(rq, "Cannot retrieve private JS class data because from a non-object value!");
|
||||
ScriptException::Raise(rq, "Cannot retrieve private JS object data because from a non-object value!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JS::RootedObject thisObj(rq.cx, &callArgs.thisv().toObject());
|
||||
T* value = static_cast<T*>(JS_GetInstancePrivate(rq.cx, thisObj, jsClass, &callArgs));
|
||||
T* value = JS::GetMaybePtrFromReservedSlot<T>(thisObj, JSObjectReservedSlots::PRIVATE);
|
||||
|
||||
if (value == nullptr)
|
||||
ScriptException::Raise(rq, "Private data of the given object is null!");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -21,6 +21,10 @@
|
||||
#define JSGC_GENERATIONAL 1
|
||||
#define JSGC_USE_EXACT_ROOTING 1
|
||||
|
||||
#ifdef DEBUG
|
||||
#define MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# define XP_WIN
|
||||
# ifndef WIN32
|
||||
@@ -73,7 +77,7 @@
|
||||
# pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#if MOZJS_MAJOR_VERSION != 91
|
||||
#if MOZJS_MAJOR_VERSION != 102
|
||||
#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 +85,7 @@ system-installed version. Make sure you have got all the right files and \
|
||||
include paths.
|
||||
#endif
|
||||
|
||||
#if MOZJS_MINOR_VERSION != 13
|
||||
#if MOZJS_MINOR_VERSION != 15
|
||||
#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 \
|
||||
|
||||
Reference in New Issue
Block a user