Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/scriptinterface/tests/test_ScriptInterface.h
Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | void test_clone_basic() | ||||
ScriptInterface::Request rq1(script1); | ScriptInterface::Request rq1(script1); | ||||
JS::RootedValue obj1(rq1.cx); | JS::RootedValue obj1(rq1.cx); | ||||
TS_ASSERT(script1.Eval("({'x': 123, 'y': [1, 1.5, '2', 'test', undefined, null, true, false]})", &obj1)); | TS_ASSERT(script1.Eval("({'x': 123, 'y': [1, 1.5, '2', 'test', undefined, null, true, false]})", &obj1)); | ||||
{ | { | ||||
ScriptInterface::Request rq2(script2); | ScriptInterface::Request rq2(script2); | ||||
JS::RootedValue obj2(rq2.cx, script2.CloneValueFromOtherContext(script1, obj1)); | JS::RootedValue obj2(rq2.cx, script2.CloneValueFromOtherCompartment(script1, obj1)); | ||||
std::string source; | std::string source; | ||||
TS_ASSERT(script2.CallFunction(obj2, "toSource", source)); | TS_ASSERT(script2.CallFunction(obj2, "toSource", source)); | ||||
TS_ASSERT_STR_EQUALS(source, "({x:123, y:[1, 1.5, \"2\", \"test\", (void 0), null, true, false]})"); | TS_ASSERT_STR_EQUALS(source, "({x:123, y:[1, 1.5, \"2\", \"test\", (void 0), null, true, false]})"); | ||||
} | } | ||||
} | } | ||||
void test_clone_getters() | void test_clone_getters() | ||||
{ | { | ||||
// The tests should be run with JS_SetGCZeal so this can try to find GC bugs | // The tests should be run with JS_SetGCZeal so this can try to find GC bugs | ||||
ScriptInterface script1("Test", "Test", g_ScriptRuntime); | ScriptInterface script1("Test", "Test", g_ScriptRuntime); | ||||
ScriptInterface script2("Test", "Test", g_ScriptRuntime); | ScriptInterface script2("Test", "Test", g_ScriptRuntime); | ||||
ScriptInterface::Request rq1(script1); | ScriptInterface::Request rq1(script1); | ||||
JS::RootedValue obj1(rq1.cx); | JS::RootedValue obj1(rq1.cx); | ||||
TS_ASSERT(script1.Eval("var s = '?'; var v = ({get x() { return 123 }, 'y': {'w':{get z() { delete v.y; delete v.n; v = null; s += s; return 4 }}}, 'n': 100}); v", &obj1)); | TS_ASSERT(script1.Eval("var s = '?'; var v = ({get x() { return 123 }, 'y': {'w':{get z() { delete v.y; delete v.n; v = null; s += s; return 4 }}}, 'n': 100}); v", &obj1)); | ||||
{ | { | ||||
ScriptInterface::Request rq2(script2); | ScriptInterface::Request rq2(script2); | ||||
JS::RootedValue obj2(rq2.cx, script2.CloneValueFromOtherContext(script1, obj1)); | JS::RootedValue obj2(rq2.cx, script2.CloneValueFromOtherCompartment(script1, obj1)); | ||||
std::string source; | std::string source; | ||||
TS_ASSERT(script2.CallFunction(obj2, "toSource", source)); | TS_ASSERT(script2.CallFunction(obj2, "toSource", source)); | ||||
TS_ASSERT_STR_EQUALS(source, "({x:123, y:{w:{z:4}}})"); | TS_ASSERT_STR_EQUALS(source, "({x:123, y:{w:{z:4}}})"); | ||||
} | } | ||||
} | } | ||||
void test_clone_cyclic() | void test_clone_cyclic() | ||||
{ | { | ||||
ScriptInterface script1("Test", "Test", g_ScriptRuntime); | ScriptInterface script1("Test", "Test", g_ScriptRuntime); | ||||
ScriptInterface script2("Test", "Test", g_ScriptRuntime); | ScriptInterface script2("Test", "Test", g_ScriptRuntime); | ||||
ScriptInterface::Request rq1(script1); | ScriptInterface::Request rq1(script1); | ||||
JS::RootedValue obj1(rq1.cx); | JS::RootedValue obj1(rq1.cx); | ||||
TS_ASSERT(script1.Eval("var x = []; x[0] = x; ({'a': x, 'b': x})", &obj1)); | TS_ASSERT(script1.Eval("var x = []; x[0] = x; ({'a': x, 'b': x})", &obj1)); | ||||
{ | { | ||||
ScriptInterface::Request rq2(script2); | ScriptInterface::Request rq2(script2); | ||||
JS::RootedValue obj2(rq2.cx, script2.CloneValueFromOtherContext(script1, obj1)); | JS::RootedValue obj2(rq2.cx, script2.CloneValueFromOtherCompartment(script1, obj1)); | ||||
// Use JSAPI function to check if the values of the properties "a", "b" are equals a.x[0] | // Use JSAPI function to check if the values of the properties "a", "b" are equals a.x[0] | ||||
JS::RootedValue prop_a(rq2.cx); | JS::RootedValue prop_a(rq2.cx); | ||||
JS::RootedValue prop_b(rq2.cx); | JS::RootedValue prop_b(rq2.cx); | ||||
JS::RootedValue prop_x1(rq2.cx); | JS::RootedValue prop_x1(rq2.cx); | ||||
TS_ASSERT(script2.GetProperty(obj2, "a", &prop_a)); | TS_ASSERT(script2.GetProperty(obj2, "a", &prop_a)); | ||||
TS_ASSERT(script2.GetProperty(obj2, "b", &prop_b)); | TS_ASSERT(script2.GetProperty(obj2, "b", &prop_b)); | ||||
TS_ASSERT(prop_a.isObject()); | TS_ASSERT(prop_a.isObject()); | ||||
▲ Show 20 Lines • Show All 148 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator