mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-27 20:51:36 +00:00
Exact stack rooting for JSON related ScriptInterface functions.
Refs #2415 Refs #2462 This was SVN commit r15603.
This commit is contained in:
@@ -241,15 +241,17 @@ public:
|
||||
void test_json()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", g_ScriptRuntime);
|
||||
JSContext* cx = script.GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
std::string input = "({'x':1,'z':[2,'3\\u263A\\ud800'],\"y\":true})";
|
||||
CScriptValRooted val;
|
||||
TS_ASSERT(script.Eval(input.c_str(), val));
|
||||
JS::RootedValue val(cx);
|
||||
TS_ASSERT(script.Eval(input.c_str(), &val));
|
||||
|
||||
std::string stringified = script.StringifyJSON(val.get());
|
||||
std::string stringified = script.StringifyJSON(&val);
|
||||
TS_ASSERT_STR_EQUALS(stringified, "{\n \"x\": 1,\n \"z\": [\n 2,\n \"3\xE2\x98\xBA\xEF\xBF\xBD\"\n ],\n \"y\": true\n}");
|
||||
|
||||
val = script.ParseJSON(stringified);
|
||||
script.ParseJSON(stringified, &val);
|
||||
TS_ASSERT_WSTR_EQUALS(script.ToString(val.get()), L"({x:1, z:[2, \"3\\u263A\\uFFFD\"], y:true})");
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user