1
0
forked from mirrors/0ad

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
+3 -5
View File
@@ -946,7 +946,7 @@ void ScriptInterface::DefineCustomObjectType(JSClass *clasp, JSNative constructo
CustomType type;
type.m_Object = obj;
type.m_Prototype = obj;
type.m_Class = clasp;
type.m_Constructor = constructor;
@@ -960,12 +960,10 @@ JSObject* ScriptInterface::CreateCustomObject(const std::string & typeName)
if (it == m_CustomObjectTypes.end())
throw PSERROR_Scripting_TypeDoesNotExist();
JSFunction* ctor = JS_NewFunction(m->m_cx, (*it).second.m_Constructor, 0, 0,
NULL, "ctor_fun");
return JS_New(m->m_cx, JS_GetFunctionObject(ctor), 0, NULL);
JS::RootedObject prototype(m->m_cx, (*it).second.m_Prototype);
return JS_NewObject(m->m_cx, (*it).second.m_Class, prototype, NULL);
}
bool ScriptInterface::CallFunctionVoid(jsval val, const char* name)
{
JSAutoRequest rq(m->m_cx);