mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Remove Script::CreateArray
It's better to construct a js-array from a `JS::RootedValueVector`. Because it is more strongly typed and the index doesn't has to be specified when appending an element. Some usages are replaced with `JS::RootedValueArray`. Fixes: #8702
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -227,21 +227,20 @@ JS::Value ReadFileLines(const ScriptRequest& rq, const std::wstring& filename)
|
||||
// split into array of strings (one per line)
|
||||
std::stringstream ss(contents);
|
||||
|
||||
JS::RootedValue line_array(rq.cx);
|
||||
Script::CreateArray(rq, &line_array);
|
||||
JS::RootedValueVector lineArray{rq.cx};
|
||||
|
||||
std::string line;
|
||||
int cur_line = 0;
|
||||
|
||||
while (std::getline(ss, line))
|
||||
{
|
||||
// Decode each line as UTF-8
|
||||
JS::RootedValue val(rq.cx);
|
||||
Script::ToJSVal(rq, &val, CStr(line).FromUTF8());
|
||||
Script::SetPropertyInt(rq, line_array, cur_line++, val);
|
||||
if (!lineArray.append(val))
|
||||
throw std::runtime_error{"Append failed"};
|
||||
}
|
||||
|
||||
return line_array;
|
||||
return JS::ObjectValue(*JS::NewArrayObject(rq.cx, lineArray));
|
||||
}
|
||||
|
||||
// Return file contents parsed as a JS Object
|
||||
|
||||
Reference in New Issue
Block a user