mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-23 03:47:27 +00:00
Use ScriptInterface::CreateObject for ToJSVal<CColor>, and for ToJSVal<Grid<u8> >, ToJSVal<Grid<u16> > used by the AIManager obtaining the pathfinder grid.
Make that function static, so that it can be used for these functions without slowly having to obtain the ScriptInterface instance using GetScriptInterfaceAndCBData just to get the JSContext again. Remove few redundant conversions for CreateObject arguments. Differential Revision: https://code.wildfiregames.com/D2128 Tested on: gcc 9.1.0, clang 8.0.1, Jenkins Tedious performance testing in: D2128, D2127 This was SVN commit r22894.
This commit is contained in:
@@ -132,16 +132,16 @@ public:
|
||||
|
||||
/**
|
||||
* Sets the given value to a new plain JS::Object, converts the arguments to JS::Values and sets them as properties.
|
||||
* This is static so that callers like ToJSVal can use it with the JSContext directly instead of having to obtain the instance using GetScriptInterfaceAndCBData.
|
||||
* Can throw an exception.
|
||||
*/
|
||||
template<typename... Args>
|
||||
bool CreateObject(JS::MutableHandleValue objectValue, Args const&... args) const
|
||||
static bool CreateObject(JSContext* cx, JS::MutableHandleValue objectValue, Args const&... args)
|
||||
{
|
||||
JSContext* cx = GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
JS::RootedObject obj(cx);
|
||||
|
||||
if (!CreateObject_(&obj, args...))
|
||||
if (!CreateObject_(cx, &obj, args...))
|
||||
return false;
|
||||
|
||||
objectValue.setObject(*obj);
|
||||
@@ -151,7 +151,7 @@ public:
|
||||
/**
|
||||
* Sets the given value to a new JS object or Null Value in case of out-of-memory.
|
||||
*/
|
||||
void CreateArray(JS::MutableHandleValue objectValue, size_t length = 0) const;
|
||||
static void CreateArray(JSContext* cx, JS::MutableHandleValue objectValue, size_t length = 0);
|
||||
|
||||
JS::Value GetGlobalObject() const;
|
||||
|
||||
@@ -402,17 +402,16 @@ private:
|
||||
/**
|
||||
* Careful, the CreateObject_ helpers avoid creation of the JSAutoRequest!
|
||||
*/
|
||||
bool CreateObject_(JS::MutableHandleObject obj) const;
|
||||
static bool CreateObject_(JSContext* cx, JS::MutableHandleObject obj);
|
||||
|
||||
template<typename T, typename... Args>
|
||||
bool CreateObject_(JS::MutableHandleObject obj, const char* propertyName, const T& propertyValue, Args const&... args) const
|
||||
static bool CreateObject_(JSContext* cx, JS::MutableHandleObject obj, const char* propertyName, const T& propertyValue, Args const&... args)
|
||||
{
|
||||
// JSAutoRequest is the responsibility of the caller
|
||||
JSContext* cx = GetContext();
|
||||
JS::RootedValue val(cx);
|
||||
AssignOrToJSVal(cx, &val, propertyValue);
|
||||
|
||||
return CreateObject_(obj, args...) && JS_DefineProperty(cx, obj, propertyName, val, JSPROP_ENUMERATE);
|
||||
return CreateObject_(cx, obj, args...) && JS_DefineProperty(cx, obj, propertyName, val, JSPROP_ENUMERATE);
|
||||
}
|
||||
|
||||
bool CallFunction_(JS::HandleValue val, const char* name, JS::HandleValueArray argv, JS::MutableHandleValue ret) const;
|
||||
|
||||
Reference in New Issue
Block a user