Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/scriptinterface/ScriptConversions.h
/* Copyright (C) 2020 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | template<typename T> static bool FromJSVal_vector(const ScriptRequest& rq, JS::HandleValue v, std::vector<T>& out) | ||||
obj = &v.toObject(); | obj = &v.toObject(); | ||||
if ((!JS::IsArrayObject(rq.cx, obj, &isArray) || !isArray) && !JS_IsTypedArrayObject(obj)) | if ((!JS::IsArrayObject(rq.cx, obj, &isArray) || !isArray) && !JS_IsTypedArrayObject(obj)) | ||||
FAIL("Argument must be an array"); | FAIL("Argument must be an array"); | ||||
u32 length; | u32 length; | ||||
if (!JS::GetArrayLength(rq.cx, obj, &length)) | if (!JS::GetArrayLength(rq.cx, obj, &length)) | ||||
FAIL("Failed to get array length"); | FAIL("Failed to get array length"); | ||||
out.clear(); | |||||
out.reserve(length); | out.reserve(length); | ||||
for (u32 i = 0; i < length; ++i) | for (u32 i = 0; i < length; ++i) | ||||
{ | { | ||||
JS::RootedValue el(rq.cx); | JS::RootedValue el(rq.cx); | ||||
if (!JS_GetElement(rq.cx, obj, i, &el)) | if (!JS_GetElement(rq.cx, obj, i, &el)) | ||||
FAIL("Failed to read array element"); | FAIL("Failed to read array element"); | ||||
T el2; | T el2; | ||||
if (!ScriptInterface::FromJSVal<T>(rq, el, el2)) | if (!ScriptInterface::FromJSVal<T>(rq, el, el2)) | ||||
Show All 40 Lines |
Wildfire Games · Phabricator