mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-01 01:09:24 +00:00
Changes ToJSVal to take JS::MutableHandleValue instead of JS::Value&.
JS::MutableHandleValue is similar to JS::HandleValue, but the whole JS::Value it points to can be replaced. This change is needed for support of exact stack rooting and moving GC. Contains a few other trivial API adjustments and style improvements too. Refs #2462 Refs #2415 This was SVN commit r15534.
This commit is contained in:
@@ -23,11 +23,11 @@
|
||||
#include "lib/external_libraries/libsdl.h"
|
||||
#include "ps/Hotkey.h"
|
||||
|
||||
#define SET(obj, name, value) STMT(JS::RootedValue v_(cx); ToJSVal(cx, v_.get(), (value)); JS_SetProperty(cx, (obj), (name), v_.address()))
|
||||
#define SET(obj, name, value) STMT(JS::RootedValue v_(cx); ToJSVal(cx, &v_, (value)); JS_SetProperty(cx, (obj), (name), v_.address()))
|
||||
// ignore JS_SetProperty return value, because errors should be impossible
|
||||
// and we can't do anything useful in the case of errors anyway
|
||||
|
||||
template<> void ScriptInterface::ToJSVal<SDL_Event_>(JSContext* cx, JS::Value& ret, SDL_Event_ const& val)
|
||||
template<> void ScriptInterface::ToJSVal<SDL_Event_>(JSContext* cx, JS::MutableHandleValue ret, SDL_Event_ const& val)
|
||||
{
|
||||
JSAutoRequest rq(cx);
|
||||
const char* typeName;
|
||||
@@ -52,10 +52,10 @@ template<> void ScriptInterface::ToJSVal<SDL_Event_>(JSContext* cx, JS::Value& r
|
||||
default: typeName = "(unknown)"; break;
|
||||
}
|
||||
|
||||
JSObject* obj = JS_NewObject(cx, NULL, NULL, NULL);
|
||||
if (! obj)
|
||||
JS::RootedObject obj(cx, JS_NewObject(cx, NULL, NULL, NULL));
|
||||
if (!obj)
|
||||
{
|
||||
ret = JSVAL_VOID;
|
||||
ret.setUndefined();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ template<> void ScriptInterface::ToJSVal<SDL_Event_>(JSContext* cx, JS::Value& r
|
||||
JSObject* keysym = JS_NewObject(cx, NULL, NULL, NULL);
|
||||
if (! keysym)
|
||||
{
|
||||
ret = JSVAL_VOID;
|
||||
ret.setUndefined();
|
||||
return;
|
||||
}
|
||||
JS::RootedValue keysymVal(cx, JS::ObjectValue(*keysym));
|
||||
@@ -131,13 +131,13 @@ template<> void ScriptInterface::ToJSVal<SDL_Event_>(JSContext* cx, JS::Value& r
|
||||
}
|
||||
}
|
||||
|
||||
ret = JS::ObjectValue(*obj);
|
||||
ret.setObject(*obj);
|
||||
}
|
||||
|
||||
template<> void ScriptInterface::ToJSVal<IGUIObject*>(JSContext* UNUSED(cx), JS::Value& ret, IGUIObject* const& val)
|
||||
template<> void ScriptInterface::ToJSVal<IGUIObject*>(JSContext* UNUSED(cx), JS::MutableHandleValue ret, IGUIObject* const& val)
|
||||
{
|
||||
if (val == NULL)
|
||||
ret = JSVAL_NULL;
|
||||
ret.setNull();
|
||||
else
|
||||
ret = JS::ObjectValue(*val->GetJSObject());
|
||||
ret.setObject(*val->GetJSObject());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user