mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-23 09:47:24 +00:00
Makes custom JS objects compatible with SpiderMonkey ESR31.
In v24 you called JS_InitClass and passed in a definition of JSNative functions. Later you could call JS_NewObject with this class and the object would get a prototype with the specified JSNative functions. In ESR31 you now have to explicitly store the prototype object returned by JS_InitClass and pass it as prototype argument to JS_NewObject to achieve the same. This change modifies our existing ScriptInterface implementation for custom object types a bit and uses it at places where the JSAPI was used directly before. Refs #2462 This was SVN commit r15524.
This commit is contained in:
@@ -51,8 +51,8 @@ template<> void ScriptInterface::ToJSVal<IComponent*>(JSContext* cx, JS::Value&
|
||||
|
||||
// Otherwise we need to construct a wrapper object
|
||||
// (TODO: cache wrapper objects?)
|
||||
JSClass* cls = val->GetJSClass();
|
||||
if (!cls)
|
||||
JS::RootedObject obj(cx);
|
||||
if (!val->NewJSObject(*ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface, &obj))
|
||||
{
|
||||
// Report as an error, since scripts really shouldn't try to use unscriptable interfaces
|
||||
LOGERROR(L"IComponent does not have a scriptable interface");
|
||||
@@ -60,15 +60,7 @@ template<> void ScriptInterface::ToJSVal<IComponent*>(JSContext* cx, JS::Value&
|
||||
return;
|
||||
}
|
||||
|
||||
JS::RootedObject obj(cx, JS_NewObject(cx, cls, NULL, NULL));
|
||||
if (!obj)
|
||||
{
|
||||
LOGERROR(L"Failed to construct IComponent script object");
|
||||
ret = JS::UndefinedValue();
|
||||
return;
|
||||
}
|
||||
JS_SetPrivate(obj, static_cast<void*>(val));
|
||||
|
||||
ret = JS::ObjectValue(*obj);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user