mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-11-08 16:11:21 +00:00
Provide ScriptInterface CreateObject and CreateArray functions to replace Eval calls following 7c2e9027c2, 1c0536bf08 and later.
Differential Revision: https://code.wildfiregames.com/D2080 Previous version reviewed By: Krinkle Comments By: historic_bruno, wraitii This was SVN commit r22528.
This commit is contained in:
1 parent
6643613b54
commit
b4626359f5
23 files changed
+316
-192
No files matched your search
@@ -579,6 +579,28 @@ bool ScriptInterface::CallFunction_(JS::HandleValue val, const char* name, JS::H
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ScriptInterface::CreateObject(JS::MutableHandleValue objectValue) const
|
||||
{
|
||||
JSContext* cx = GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
objectValue.setObjectOrNull(JS_NewPlainObject(cx));
|
||||
if (!objectValue.isObject())
|
||||
throw PSERROR_Scripting_CreateObjectFailed();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScriptInterface::CreateArray(JS::MutableHandleValue objectValue, size_t length) const
|
||||
{
|
||||
JSContext* cx = GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
objectValue.setObjectOrNull(JS_NewArrayObject(cx, length));
|
||||
if (!objectValue.isObject())
|
||||
throw PSERROR_Scripting_CreateObjectFailed();
|
||||
}
|
||||
|
||||
JS::Value ScriptInterface::GetGlobalObject() const
|
||||
{
|
||||
JSAutoRequest rq(m->m_cx);
|
||||
|
||||
Reference in new issue
Block a user