Changeset View
Changeset View
Standalone View
Standalone View
source/scriptinterface/tests/test_ScriptInterface.h
Show First 20 Lines • Show All 248 Lines • ▼ Show 20 Lines | void test_json() | ||||
TS_ASSERT(script.Eval(input.c_str(), &val)); | TS_ASSERT(script.Eval(input.c_str(), &val)); | ||||
std::string stringified = script.StringifyJSON(&val); | 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}"); | 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}"); | ||||
TS_ASSERT(script.ParseJSON(stringified, &val)); | TS_ASSERT(script.ParseJSON(stringified, &val)); | ||||
TS_ASSERT_STR_EQUALS(script.ToString(&val), "({x:1, z:[2, \"3\\u263A\\uFFFD\"], y:true})"); | TS_ASSERT_STR_EQUALS(script.ToString(&val), "({x:1, z:[2, \"3\\u263A\\uFFFD\"], y:true})"); | ||||
} | } | ||||
// This function tests a common way to mod functions, by crating a wrapper that | |||||
// extends the functionality and is then assigned to the name of the function. | |||||
void test_function_override() | |||||
Itms: This is unrelated to hotloading, but it deals with modification of functions that are… | |||||
wraitiiUnsubmitted Not Done Inline ActionsWould be nice to commit separately but agreed that we need this to stay. wraitii: Would be nice to commit separately but agreed that we need this to stay. | |||||
ItmsAuthorUnsubmitted Done Inline ActionsOkay I'll split it. Itms: Okay I'll split it. | |||||
{ | |||||
ScriptInterface script("Test", "Test", g_ScriptRuntime); | |||||
JSContext* cx = script.GetContext(); | |||||
JSAutoRequest rq(cx); | |||||
TS_ASSERT(script.Eval( | |||||
"function f() { return 1; }" | |||||
"f = (function (originalFunction) {" | |||||
"return function () { return originalFunction() + 1; }" | |||||
"})(f);" | |||||
)); | |||||
JS::RootedValue out(cx); | |||||
TS_ASSERT(script.Eval("f()", &out)); | |||||
int outNbr = 0; | |||||
ScriptInterface::FromJSVal(cx, out, outNbr); | |||||
TS_ASSERT_EQUALS(2, outNbr); | |||||
} | |||||
}; | }; |
Wildfire Games · Phabricator
This is unrelated to hotloading, but it deals with modification of functions that are properties of the global object. Modders do this a lot, and it's very useful. So I want to make sure this doesn't break with SM45 or a later version.