1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : * vim: set ts=8 sw=4 et tw=99:
3 : */
4 :
5 : #include "tests.h"
6 :
7 11 : struct ScriptObjectFixture : public JSAPITest {
8 : static const int code_size;
9 : static const char code[];
10 : static jschar uc_code[];
11 :
12 11 : ScriptObjectFixture()
13 11 : {
14 572 : for (int i = 0; i < code_size; i++)
15 561 : uc_code[i] = code[i];
16 11 : }
17 :
18 11 : bool tryScript(JSScript *script)
19 : {
20 11 : CHECK(script);
21 :
22 11 : JS_GC(cx);
23 :
24 : /* After a garbage collection, the script should still work. */
25 : jsval result;
26 11 : CHECK(JS_ExecuteScript(cx, global, script, &result));
27 :
28 11 : return true;
29 : }
30 : };
31 :
32 : const char ScriptObjectFixture::code[] =
33 : "(function(a, b){return a+' '+b;}('hello', 'world'))";
34 : const int ScriptObjectFixture::code_size = sizeof(ScriptObjectFixture::code) - 1;
35 : jschar ScriptObjectFixture::uc_code[ScriptObjectFixture::code_size];
36 :
37 4 : BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript)
38 : {
39 : return tryScript(JS_CompileScript(cx, global, code, code_size,
40 1 : __FILE__, __LINE__));
41 : }
42 1 : END_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript)
43 :
44 4 : BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript_empty)
45 : {
46 : return tryScript(JS_CompileScript(cx, global, "", 0,
47 1 : __FILE__, __LINE__));
48 : }
49 1 : END_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScript_empty)
50 :
51 4 : BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScriptForPrincipals)
52 : {
53 : return tryScript(JS_CompileScriptForPrincipals(cx, global, NULL,
54 : code, code_size,
55 1 : __FILE__, __LINE__));
56 : }
57 1 : END_FIXTURE_TEST(ScriptObjectFixture, bug438633_CompileScriptForPrincipals)
58 :
59 4 : BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript)
60 : {
61 : return tryScript(JS_CompileUCScript(cx, global,
62 : uc_code, code_size,
63 1 : __FILE__, __LINE__));
64 : }
65 1 : END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript)
66 :
67 4 : BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript_empty)
68 : {
69 : return tryScript(JS_CompileUCScript(cx, global,
70 : uc_code, 0,
71 1 : __FILE__, __LINE__));
72 : }
73 1 : END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScript_empty)
74 :
75 4 : BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScriptForPrincipals)
76 : {
77 : return tryScript(JS_CompileUCScriptForPrincipals(cx, global, NULL,
78 : uc_code, code_size,
79 1 : __FILE__, __LINE__));
80 : }
81 1 : END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileUCScriptForPrincipals)
82 :
83 4 : BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile)
84 : {
85 2 : TempFile tempScript;
86 : static const char script_filename[] = "temp-bug438633_JS_CompileFile";
87 1 : FILE *script_stream = tempScript.open(script_filename);
88 1 : CHECK(fputs(code, script_stream) != EOF);
89 1 : tempScript.close();
90 1 : JSScript *script = JS_CompileUTF8File(cx, global, script_filename);
91 1 : tempScript.remove();
92 1 : return tryScript(script);
93 : }
94 1 : END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile)
95 :
96 4 : BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile_empty)
97 : {
98 2 : TempFile tempScript;
99 : static const char script_filename[] = "temp-bug438633_JS_CompileFile_empty";
100 1 : tempScript.open(script_filename);
101 1 : tempScript.close();
102 1 : JSScript *script = JS_CompileUTF8File(cx, global, script_filename);
103 1 : tempScript.remove();
104 1 : return tryScript(script);
105 : }
106 1 : END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFile_empty)
107 :
108 4 : BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandle)
109 : {
110 2 : TempFile tempScript;
111 1 : FILE *script_stream = tempScript.open("temp-bug438633_JS_CompileFileHandle");
112 1 : CHECK(fputs(code, script_stream) != EOF);
113 1 : CHECK(fseek(script_stream, 0, SEEK_SET) != EOF);
114 : return tryScript(JS_CompileUTF8FileHandle(cx, global, "temporary file",
115 1 : script_stream));
116 : }
117 1 : END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandle)
118 :
119 4 : BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandle_empty)
120 : {
121 2 : TempFile tempScript;
122 1 : FILE *script_stream = tempScript.open("temp-bug438633_JS_CompileFileHandle_empty");
123 : return tryScript(JS_CompileUTF8FileHandle(cx, global, "empty temporary file",
124 1 : script_stream));
125 : }
126 1 : END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandle_empty)
127 :
128 4 : BEGIN_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandleForPrincipals)
129 : {
130 2 : TempFile tempScript;
131 1 : FILE *script_stream = tempScript.open("temp-bug438633_JS_CompileFileHandleForPrincipals");
132 1 : CHECK(fputs(code, script_stream) != EOF);
133 1 : CHECK(fseek(script_stream, 0, SEEK_SET) != EOF);
134 : return tryScript(JS_CompileUTF8FileHandleForPrincipals(cx, global,
135 : "temporary file",
136 1 : script_stream, NULL));
137 : }
138 3 : END_FIXTURE_TEST(ScriptObjectFixture, bug438633_JS_CompileFileHandleForPrincipals)
|