Replace ScriptInterface::Call* with new ScriptFunction functions

Finishes work started in f3aedf88a6.
This removes the boost-CPP function wrappers entirely, in favour of pure
templated code in FunctionWrapper.h
The Call* functions were already heavily templated, so there is nothing
really new here. I just use tag dispatch to reduce the number of
overloads slightly.

The new functions do not need the script interface, only the script
request.

Differential Revision: https://code.wildfiregames.com/D3912
This was SVN commit r25354.
This commit is contained in:
wraitii
2021-05-01 14:04:53 +00:00
parent d9748173c7
commit d46a417748
20 changed files with 164 additions and 446 deletions
+1 -21
View File
@@ -472,26 +472,6 @@ JSObject* ScriptInterface::CreateCustomObject(const std::string& typeName) const
return JS_NewObjectWithGivenProto(rq.cx, it->second.m_Class, prototype);
}
bool ScriptInterface::CallFunction_(JS::HandleValue val, const char* name, JS::HandleValueArray argv, JS::MutableHandleValue ret) const
{
ScriptRequest rq(this);
JS::RootedObject obj(rq.cx);
if (!JS_ValueToObject(rq.cx, val, &obj) || !obj)
return false;
// Check that the named function actually exists, to avoid ugly JS error reports
// when calling an undefined value
bool found;
if (!JS_HasProperty(rq.cx, obj, name, &found) || !found)
return false;
if (JS_CallFunctionName(rq.cx, obj, name, argv, ret))
return true;
ScriptException::CatchPending(rq);
return false;
}
bool ScriptInterface::CreateObject_(const ScriptRequest& rq, JS::MutableHandleObject object)
{
object.set(JS_NewPlainObject(rq.cx));
@@ -977,7 +957,7 @@ std::string ScriptInterface::ToString(JS::MutableHandleValue obj, bool pretty) c
// so fall back to obj.toSource()
std::wstring source = L"(error)";
CallFunction(obj, "toSource", source);
ScriptFunction::Call(rq, obj, "toSource", source);
return utf8_from_wstring(source);
}