mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-10-13 18:53:43 +00:00
Exact rooting for CallConstructor.
Refs #2415 Refs #2462 This was SVN commit r15601.
This commit is contained in:
@@ -865,20 +865,21 @@ AutoGCRooter* ScriptInterface::ReplaceAutoGCRooter(AutoGCRooter* rooter)
|
||||
return ret;
|
||||
}
|
||||
|
||||
jsval ScriptInterface::CallConstructor(jsval ctor, uint argc, jsval argv)
|
||||
void ScriptInterface::CallConstructor(JS::HandleValue ctor, JS::AutoValueVector& argv, JS::MutableHandleValue out)
|
||||
{
|
||||
JSAutoRequest rq(m->m_cx);
|
||||
if (!ctor.isObject())
|
||||
{
|
||||
LOGERROR(L"CallConstructor: ctor is not an object");
|
||||
return JS::UndefinedValue();
|
||||
out.setNull();
|
||||
return;
|
||||
}
|
||||
|
||||
// Passing argc 0 and argv JSVAL_VOID causes a crash in mozjs24
|
||||
if (argc == 0)
|
||||
return JS::ObjectValue(*JS_New(m->m_cx, &ctor.toObject(), 0, NULL));
|
||||
if (argv.length() == 0)
|
||||
out.setObjectOrNull(JS_New(m->m_cx, &ctor.toObject(), 0, NULL));
|
||||
else
|
||||
return JS::ObjectValue(*JS_New(m->m_cx, &ctor.toObject(), argc, &argv));
|
||||
out.setObjectOrNull(JS_New(m->m_cx, &ctor.toObject(), argv.length(), argv.begin()));
|
||||
}
|
||||
|
||||
void ScriptInterface::DefineCustomObjectType(JSClass *clasp, JSNative constructor, uint minArgs, JSPropertySpec *ps, JSFunctionSpec *fs, JSPropertySpec *static_ps, JSFunctionSpec *static_fs)
|
||||
|
||||
@@ -136,9 +136,11 @@ public:
|
||||
|
||||
/**
|
||||
* Call a constructor function, equivalent to JS "new ctor(arg)".
|
||||
* @return The new object; or JSVAL_VOID on failure, and logs an error message
|
||||
* @param ctor An object that can be used as constructor
|
||||
* @param argv Constructor arguments
|
||||
* @param out The new object; On error an error message gets logged and out is Null (out.isNull() == true).
|
||||
*/
|
||||
jsval CallConstructor(jsval ctor, uint argc, jsval argv);
|
||||
void CallConstructor(JS::HandleValue ctor, JS::AutoValueVector& argv, JS::MutableHandleValue out);
|
||||
|
||||
/**
|
||||
* Call the named property on the given object, with void return type and 0 arguments
|
||||
|
||||
Reference in New Issue
Block a user