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:
Yves
2014-07-13 15:31:48 +00:00
parent f4949c82ff
commit 1b5ab8142e
10 changed files with 47 additions and 38 deletions
@@ -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);
}