1
0
forked from mirrors/0ad

Changes tests to use global g_ScriptRuntime instead of creating a new JSRuntime for each test.

The tests crashed on my Debian systems but not on my Ubuntu system.
The crash happened in line 142 of SpiderMonkey's ThreadLocal.h.

I know that I had to use a workarounnd for contexts to avoid destroying
the context that was created first. I also had in mind that in newer
versions a JS_Init function got introduced which presumably solves this
kind of issues.
Based on this experience I assumed runtimes could have a similar problem
and this patch indeed fixes the issues.
Unfortunately the correct usage of JSRuntimes in that regard is not
documented.
There's only a rater misterious comment in JSAPI.h which hasn't been
cleared up so far and is most likely completely outdated
(https://bugzilla.mozilla.org/show_bug.cgi?id=992641).

This was SVN commit r14995.
This commit is contained in:
Yves
2014-04-25 21:19:51 +00:00
parent 49fc88ff81
commit 7acdde5c86
17 changed files with 79 additions and 84 deletions
@@ -28,7 +28,7 @@ class TestScriptInterface : public CxxTest::TestSuite
public:
void test_loadscript_basic()
{
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
ScriptInterface script("Test", "Test", g_ScriptRuntime);
TestLogger logger;
TS_ASSERT(script.LoadScript(L"test.js", "var x = 1+1;"));
TS_ASSERT_WSTR_NOT_CONTAINS(logger.GetOutput(), L"JavaScript error");
@@ -37,7 +37,7 @@ public:
void test_loadscript_error()
{
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
ScriptInterface script("Test", "Test", g_ScriptRuntime);
TestLogger logger;
TS_ASSERT(!script.LoadScript(L"test.js", "1+"));
TS_ASSERT_WSTR_CONTAINS(logger.GetOutput(), L"JavaScript error: test.js line 1\nSyntaxError: syntax error");
@@ -45,7 +45,7 @@ public:
void test_loadscript_strict_warning()
{
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
ScriptInterface script("Test", "Test", g_ScriptRuntime);
TestLogger logger;
TS_ASSERT(script.LoadScript(L"test.js", "1+1;"));
TS_ASSERT_WSTR_CONTAINS(logger.GetOutput(), L"JavaScript warning: test.js line 1\nuseless expression");
@@ -53,7 +53,7 @@ public:
void test_loadscript_strict_error()
{
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
ScriptInterface script("Test", "Test", g_ScriptRuntime);
TestLogger logger;
TS_ASSERT(!script.LoadScript(L"test.js", "with(1){}"));
TS_ASSERT_WSTR_CONTAINS(logger.GetOutput(), L"JavaScript error: test.js line 1\nSyntaxError: strict mode code may not contain \'with\' statements");
@@ -61,9 +61,8 @@ public:
void test_clone_basic()
{
shared_ptr<ScriptRuntime> runtime = ScriptInterface::CreateRuntime();
ScriptInterface script1("Test", "Test", runtime);
ScriptInterface script2("Test", "Test", runtime);
ScriptInterface script1("Test", "Test", g_ScriptRuntime);
ScriptInterface script2("Test", "Test", g_ScriptRuntime);
CScriptVal obj1;
TS_ASSERT(script1.Eval("({'x': 123, 'y': [1, 1.5, '2', 'test', undefined, null, true, false]})", obj1));
@@ -78,10 +77,8 @@ public:
void test_clone_getters()
{
// The tests should be run with JS_SetGCZeal so this can try to find GC bugs
shared_ptr<ScriptRuntime> runtime = ScriptInterface::CreateRuntime();
ScriptInterface script1("Test", "Test", runtime);
ScriptInterface script2("Test", "Test", runtime);
ScriptInterface script1("Test", "Test", g_ScriptRuntime);
ScriptInterface script2("Test", "Test", g_ScriptRuntime);
CScriptVal 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));
@@ -95,9 +92,8 @@ public:
void test_clone_cyclic()
{
shared_ptr<ScriptRuntime> runtime = ScriptInterface::CreateRuntime();
ScriptInterface script1("Test", "Test", runtime);
ScriptInterface script2("Test", "Test", runtime);
ScriptInterface script1("Test", "Test", g_ScriptRuntime);
ScriptInterface script2("Test", "Test", g_ScriptRuntime);
CScriptVal obj1;
TS_ASSERT(script1.Eval("var x = []; x[0] = x; ({'a': x, 'b': x})", obj1));
@@ -121,7 +117,7 @@ public:
void test_random()
{
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
ScriptInterface script("Test", "Test", g_ScriptRuntime);
double d1, d2;
TS_ASSERT(script.Eval("Math.random()", d1));
@@ -141,7 +137,7 @@ public:
void test_json()
{
ScriptInterface script("Test", "Test", ScriptInterface::CreateRuntime());
ScriptInterface script("Test", "Test", g_ScriptRuntime);
std::string input = "({'x':1,'z':[2,'3\\u263A\\ud800'],\"y\":true})";
CScriptValRooted val;