OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 } | 44 } |
45 | 45 |
46 | 46 |
47 void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) { | 47 void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) { |
48 CHECK(false); | 48 CHECK(false); |
49 } | 49 } |
50 | 50 |
51 | 51 |
52 void Loop(const v8::FunctionCallbackInfo<v8::Value>& args) { | 52 void Loop(const v8::FunctionCallbackInfo<v8::Value>& args) { |
53 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); | 53 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); |
54 v8::Handle<v8::String> source = | 54 v8::Handle<v8::String> source = v8::String::NewFromUtf8( |
55 v8::String::New("try { doloop(); fail(); } catch(e) { fail(); }"); | 55 args.GetIsolate(), "try { doloop(); fail(); } catch(e) { fail(); }"); |
56 v8::Handle<v8::Value> result = v8::Script::Compile(source)->Run(); | 56 v8::Handle<v8::Value> result = v8::Script::Compile(source)->Run(); |
57 CHECK(result.IsEmpty()); | 57 CHECK(result.IsEmpty()); |
58 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); | 58 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); |
59 } | 59 } |
60 | 60 |
61 | 61 |
62 void DoLoop(const v8::FunctionCallbackInfo<v8::Value>& args) { | 62 void DoLoop(const v8::FunctionCallbackInfo<v8::Value>& args) { |
63 v8::TryCatch try_catch; | 63 v8::TryCatch try_catch; |
64 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); | 64 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); |
65 v8::Script::Compile(v8::String::New("function f() {" | 65 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), |
66 " var term = true;" | 66 "function f() {" |
67 " try {" | 67 " var term = true;" |
68 " while(true) {" | 68 " try {" |
69 " if (term) terminate();" | 69 " while(true) {" |
70 " term = false;" | 70 " if (term) terminate();" |
71 " }" | 71 " term = false;" |
72 " fail();" | 72 " }" |
73 " } catch(e) {" | 73 " fail();" |
74 " fail();" | 74 " } catch(e) {" |
75 " }" | 75 " fail();" |
76 "}" | 76 " }" |
77 "f()"))->Run(); | 77 "}" |
| 78 "f()"))->Run(); |
78 CHECK(try_catch.HasCaught()); | 79 CHECK(try_catch.HasCaught()); |
79 CHECK(try_catch.Exception()->IsNull()); | 80 CHECK(try_catch.Exception()->IsNull()); |
80 CHECK(try_catch.Message().IsEmpty()); | 81 CHECK(try_catch.Message().IsEmpty()); |
81 CHECK(!try_catch.CanContinue()); | 82 CHECK(!try_catch.CanContinue()); |
82 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); | 83 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); |
83 } | 84 } |
84 | 85 |
85 | 86 |
86 void DoLoopNoCall(const v8::FunctionCallbackInfo<v8::Value>& args) { | 87 void DoLoopNoCall(const v8::FunctionCallbackInfo<v8::Value>& args) { |
87 v8::TryCatch try_catch; | 88 v8::TryCatch try_catch; |
88 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); | 89 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); |
89 v8::Script::Compile(v8::String::New("var term = true;" | 90 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), |
90 "while(true) {" | 91 "var term = true;" |
91 " if (term) terminate();" | 92 "while(true) {" |
92 " term = false;" | 93 " if (term) terminate();" |
93 "}"))->Run(); | 94 " term = false;" |
| 95 "}"))->Run(); |
94 CHECK(try_catch.HasCaught()); | 96 CHECK(try_catch.HasCaught()); |
95 CHECK(try_catch.Exception()->IsNull()); | 97 CHECK(try_catch.Exception()->IsNull()); |
96 CHECK(try_catch.Message().IsEmpty()); | 98 CHECK(try_catch.Message().IsEmpty()); |
97 CHECK(!try_catch.CanContinue()); | 99 CHECK(!try_catch.CanContinue()); |
98 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); | 100 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); |
99 } | 101 } |
100 | 102 |
101 | 103 |
102 v8::Handle<v8::ObjectTemplate> CreateGlobalTemplate( | 104 v8::Handle<v8::ObjectTemplate> CreateGlobalTemplate( |
| 105 v8::Isolate* isolate, |
103 v8::FunctionCallback terminate, | 106 v8::FunctionCallback terminate, |
104 v8::FunctionCallback doloop) { | 107 v8::FunctionCallback doloop) { |
105 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); | 108 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); |
106 global->Set(v8::String::New("terminate"), | 109 global->Set(v8::String::NewFromUtf8(isolate, "terminate"), |
107 v8::FunctionTemplate::New(terminate)); | 110 v8::FunctionTemplate::New(terminate)); |
108 global->Set(v8::String::New("fail"), v8::FunctionTemplate::New(Fail)); | 111 global->Set(v8::String::NewFromUtf8(isolate, "fail"), |
109 global->Set(v8::String::New("loop"), v8::FunctionTemplate::New(Loop)); | 112 v8::FunctionTemplate::New(Fail)); |
110 global->Set(v8::String::New("doloop"), v8::FunctionTemplate::New(doloop)); | 113 global->Set(v8::String::NewFromUtf8(isolate, "loop"), |
| 114 v8::FunctionTemplate::New(Loop)); |
| 115 global->Set(v8::String::NewFromUtf8(isolate, "doloop"), |
| 116 v8::FunctionTemplate::New(doloop)); |
111 return global; | 117 return global; |
112 } | 118 } |
113 | 119 |
114 | 120 |
115 // Test that a single thread of JavaScript execution can terminate | 121 // Test that a single thread of JavaScript execution can terminate |
116 // itself. | 122 // itself. |
117 TEST(TerminateOnlyV8ThreadFromThreadItself) { | 123 TEST(TerminateOnlyV8ThreadFromThreadItself) { |
118 v8::HandleScope scope(CcTest::isolate()); | 124 v8::HandleScope scope(CcTest::isolate()); |
119 v8::Handle<v8::ObjectTemplate> global = | 125 v8::Handle<v8::ObjectTemplate> global = |
120 CreateGlobalTemplate(TerminateCurrentThread, DoLoop); | 126 CreateGlobalTemplate(CcTest::isolate(), TerminateCurrentThread, DoLoop); |
121 v8::Handle<v8::Context> context = | 127 v8::Handle<v8::Context> context = |
122 v8::Context::New(CcTest::isolate(), NULL, global); | 128 v8::Context::New(CcTest::isolate(), NULL, global); |
123 v8::Context::Scope context_scope(context); | 129 v8::Context::Scope context_scope(context); |
124 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 130 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); |
125 // Run a loop that will be infinite if thread termination does not work. | 131 // Run a loop that will be infinite if thread termination does not work. |
126 v8::Handle<v8::String> source = | 132 v8::Handle<v8::String> source = v8::String::NewFromUtf8( |
127 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); | 133 CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }"); |
128 v8::Script::Compile(source)->Run(); | 134 v8::Script::Compile(source)->Run(); |
129 // Test that we can run the code again after thread termination. | 135 // Test that we can run the code again after thread termination. |
130 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 136 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); |
131 v8::Script::Compile(source)->Run(); | 137 v8::Script::Compile(source)->Run(); |
132 } | 138 } |
133 | 139 |
134 | 140 |
135 // Test that a single thread of JavaScript execution can terminate | 141 // Test that a single thread of JavaScript execution can terminate |
136 // itself in a loop that performs no calls. | 142 // itself in a loop that performs no calls. |
137 TEST(TerminateOnlyV8ThreadFromThreadItselfNoLoop) { | 143 TEST(TerminateOnlyV8ThreadFromThreadItselfNoLoop) { |
138 v8::HandleScope scope(CcTest::isolate()); | 144 v8::HandleScope scope(CcTest::isolate()); |
139 v8::Handle<v8::ObjectTemplate> global = | 145 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( |
140 CreateGlobalTemplate(TerminateCurrentThread, DoLoopNoCall); | 146 CcTest::isolate(), TerminateCurrentThread, DoLoopNoCall); |
141 v8::Handle<v8::Context> context = | 147 v8::Handle<v8::Context> context = |
142 v8::Context::New(CcTest::isolate(), NULL, global); | 148 v8::Context::New(CcTest::isolate(), NULL, global); |
143 v8::Context::Scope context_scope(context); | 149 v8::Context::Scope context_scope(context); |
144 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 150 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); |
145 // Run a loop that will be infinite if thread termination does not work. | 151 // Run a loop that will be infinite if thread termination does not work. |
146 v8::Handle<v8::String> source = | 152 v8::Handle<v8::String> source = v8::String::NewFromUtf8( |
147 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); | 153 CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }"); |
148 v8::Script::Compile(source)->Run(); | 154 v8::Script::Compile(source)->Run(); |
149 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 155 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); |
150 // Test that we can run the code again after thread termination. | 156 // Test that we can run the code again after thread termination. |
151 v8::Script::Compile(source)->Run(); | 157 v8::Script::Compile(source)->Run(); |
152 } | 158 } |
153 | 159 |
154 | 160 |
155 class TerminatorThread : public v8::internal::Thread { | 161 class TerminatorThread : public v8::internal::Thread { |
156 public: | 162 public: |
157 explicit TerminatorThread(i::Isolate* isolate) | 163 explicit TerminatorThread(i::Isolate* isolate) |
(...skipping 11 matching lines...) Expand all Loading... |
169 | 175 |
170 | 176 |
171 // Test that a single thread of JavaScript execution can be terminated | 177 // Test that a single thread of JavaScript execution can be terminated |
172 // from the side by another thread. | 178 // from the side by another thread. |
173 TEST(TerminateOnlyV8ThreadFromOtherThread) { | 179 TEST(TerminateOnlyV8ThreadFromOtherThread) { |
174 semaphore = new v8::internal::Semaphore(0); | 180 semaphore = new v8::internal::Semaphore(0); |
175 TerminatorThread thread(CcTest::i_isolate()); | 181 TerminatorThread thread(CcTest::i_isolate()); |
176 thread.Start(); | 182 thread.Start(); |
177 | 183 |
178 v8::HandleScope scope(CcTest::isolate()); | 184 v8::HandleScope scope(CcTest::isolate()); |
179 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(Signal, DoLoop); | 185 v8::Handle<v8::ObjectTemplate> global = |
| 186 CreateGlobalTemplate(CcTest::isolate(), Signal, DoLoop); |
180 v8::Handle<v8::Context> context = | 187 v8::Handle<v8::Context> context = |
181 v8::Context::New(CcTest::isolate(), NULL, global); | 188 v8::Context::New(CcTest::isolate(), NULL, global); |
182 v8::Context::Scope context_scope(context); | 189 v8::Context::Scope context_scope(context); |
183 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 190 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); |
184 // Run a loop that will be infinite if thread termination does not work. | 191 // Run a loop that will be infinite if thread termination does not work. |
185 v8::Handle<v8::String> source = | 192 v8::Handle<v8::String> source = v8::String::NewFromUtf8( |
186 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); | 193 CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }"); |
187 v8::Script::Compile(source)->Run(); | 194 v8::Script::Compile(source)->Run(); |
188 | 195 |
189 thread.Join(); | 196 thread.Join(); |
190 delete semaphore; | 197 delete semaphore; |
191 semaphore = NULL; | 198 semaphore = NULL; |
192 } | 199 } |
193 | 200 |
194 | 201 |
195 int call_count = 0; | 202 int call_count = 0; |
196 | 203 |
197 | 204 |
198 void TerminateOrReturnObject(const v8::FunctionCallbackInfo<v8::Value>& args) { | 205 void TerminateOrReturnObject(const v8::FunctionCallbackInfo<v8::Value>& args) { |
199 if (++call_count == 10) { | 206 if (++call_count == 10) { |
200 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); | 207 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); |
201 v8::V8::TerminateExecution(args.GetIsolate()); | 208 v8::V8::TerminateExecution(args.GetIsolate()); |
202 return; | 209 return; |
203 } | 210 } |
204 v8::Local<v8::Object> result = v8::Object::New(); | 211 v8::Local<v8::Object> result = v8::Object::New(); |
205 result->Set(v8::String::New("x"), v8::Integer::New(42)); | 212 result->Set(v8::String::NewFromUtf8(args.GetIsolate(), "x"), |
| 213 v8::Integer::New(42)); |
206 args.GetReturnValue().Set(result); | 214 args.GetReturnValue().Set(result); |
207 } | 215 } |
208 | 216 |
209 | 217 |
210 void LoopGetProperty(const v8::FunctionCallbackInfo<v8::Value>& args) { | 218 void LoopGetProperty(const v8::FunctionCallbackInfo<v8::Value>& args) { |
211 v8::TryCatch try_catch; | 219 v8::TryCatch try_catch; |
212 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); | 220 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); |
213 v8::Script::Compile(v8::String::New("function f() {" | 221 v8::Script::Compile( |
214 " try {" | 222 v8::String::NewFromUtf8(args.GetIsolate(), |
215 " while(true) {" | 223 "function f() {" |
216 " terminate_or_return_object().x;" | 224 " try {" |
217 " }" | 225 " while(true) {" |
218 " fail();" | 226 " terminate_or_return_object().x;" |
219 " } catch(e) {" | 227 " }" |
220 " fail();" | 228 " fail();" |
221 " }" | 229 " } catch(e) {" |
222 "}" | 230 " fail();" |
223 "f()"))->Run(); | 231 " }" |
| 232 "}" |
| 233 "f()"))->Run(); |
224 CHECK(try_catch.HasCaught()); | 234 CHECK(try_catch.HasCaught()); |
225 CHECK(try_catch.Exception()->IsNull()); | 235 CHECK(try_catch.Exception()->IsNull()); |
226 CHECK(try_catch.Message().IsEmpty()); | 236 CHECK(try_catch.Message().IsEmpty()); |
227 CHECK(!try_catch.CanContinue()); | 237 CHECK(!try_catch.CanContinue()); |
228 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); | 238 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); |
229 } | 239 } |
230 | 240 |
231 | 241 |
232 // Test that we correctly handle termination exceptions if they are | 242 // Test that we correctly handle termination exceptions if they are |
233 // triggered by the creation of error objects in connection with ICs. | 243 // triggered by the creation of error objects in connection with ICs. |
234 TEST(TerminateLoadICException) { | 244 TEST(TerminateLoadICException) { |
235 v8::HandleScope scope(CcTest::isolate()); | 245 v8::HandleScope scope(CcTest::isolate()); |
236 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); | 246 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); |
237 global->Set(v8::String::New("terminate_or_return_object"), | 247 global->Set( |
238 v8::FunctionTemplate::New(TerminateOrReturnObject)); | 248 v8::String::NewFromUtf8(CcTest::isolate(), "terminate_or_return_object"), |
239 global->Set(v8::String::New("fail"), v8::FunctionTemplate::New(Fail)); | 249 v8::FunctionTemplate::New(TerminateOrReturnObject)); |
240 global->Set(v8::String::New("loop"), | 250 global->Set(v8::String::NewFromUtf8(CcTest::isolate(), "fail"), |
| 251 v8::FunctionTemplate::New(Fail)); |
| 252 global->Set(v8::String::NewFromUtf8(CcTest::isolate(), "loop"), |
241 v8::FunctionTemplate::New(LoopGetProperty)); | 253 v8::FunctionTemplate::New(LoopGetProperty)); |
242 | 254 |
243 v8::Handle<v8::Context> context = | 255 v8::Handle<v8::Context> context = |
244 v8::Context::New(CcTest::isolate(), NULL, global); | 256 v8::Context::New(CcTest::isolate(), NULL, global); |
245 v8::Context::Scope context_scope(context); | 257 v8::Context::Scope context_scope(context); |
246 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 258 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); |
247 // Run a loop that will be infinite if thread termination does not work. | 259 // Run a loop that will be infinite if thread termination does not work. |
248 v8::Handle<v8::String> source = | 260 v8::Handle<v8::String> source = v8::String::NewFromUtf8( |
249 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); | 261 CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }"); |
250 call_count = 0; | 262 call_count = 0; |
251 v8::Script::Compile(source)->Run(); | 263 v8::Script::Compile(source)->Run(); |
252 // Test that we can run the code again after thread termination. | 264 // Test that we can run the code again after thread termination. |
253 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 265 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); |
254 call_count = 0; | 266 call_count = 0; |
255 v8::Script::Compile(source)->Run(); | 267 v8::Script::Compile(source)->Run(); |
256 } | 268 } |
257 | 269 |
258 | 270 |
259 void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) { | 271 void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) { |
260 v8::TryCatch try_catch; | 272 v8::TryCatch try_catch; |
261 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); | 273 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); |
262 v8::Script::Compile(v8::String::New("function f() {" | 274 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), |
263 " var term = true;" | 275 "function f() {" |
264 " try {" | 276 " var term = true;" |
265 " while(true) {" | 277 " try {" |
266 " if (term) terminate();" | 278 " while(true) {" |
267 " term = false;" | 279 " if (term) terminate();" |
268 " }" | 280 " term = false;" |
269 " fail();" | 281 " }" |
270 " } catch(e) {" | 282 " fail();" |
271 " fail();" | 283 " } catch(e) {" |
272 " }" | 284 " fail();" |
273 "}" | 285 " }" |
274 "f()"))->Run(); | 286 "}" |
| 287 "f()"))->Run(); |
275 CHECK(try_catch.HasCaught()); | 288 CHECK(try_catch.HasCaught()); |
276 CHECK(try_catch.Exception()->IsNull()); | 289 CHECK(try_catch.Exception()->IsNull()); |
277 CHECK(try_catch.Message().IsEmpty()); | 290 CHECK(try_catch.Message().IsEmpty()); |
278 CHECK(!try_catch.CanContinue()); | 291 CHECK(!try_catch.CanContinue()); |
279 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); | 292 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); |
280 v8::Script::Compile(v8::String::New("function f() { fail(); } f()"))->Run(); | 293 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), |
| 294 "function f() { fail(); } f()")) |
| 295 ->Run(); |
281 } | 296 } |
282 | 297 |
283 | 298 |
284 // Test that reentry into V8 while the termination exception is still pending | 299 // Test that reentry into V8 while the termination exception is still pending |
285 // (has not yet unwound the 0-level JS frame) does not crash. | 300 // (has not yet unwound the 0-level JS frame) does not crash. |
286 TEST(TerminateAndReenterFromThreadItself) { | 301 TEST(TerminateAndReenterFromThreadItself) { |
287 v8::HandleScope scope(CcTest::isolate()); | 302 v8::HandleScope scope(CcTest::isolate()); |
288 v8::Handle<v8::ObjectTemplate> global = | 303 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( |
289 CreateGlobalTemplate(TerminateCurrentThread, ReenterAfterTermination); | 304 CcTest::isolate(), TerminateCurrentThread, ReenterAfterTermination); |
290 v8::Handle<v8::Context> context = | 305 v8::Handle<v8::Context> context = |
291 v8::Context::New(CcTest::isolate(), NULL, global); | 306 v8::Context::New(CcTest::isolate(), NULL, global); |
292 v8::Context::Scope context_scope(context); | 307 v8::Context::Scope context_scope(context); |
293 CHECK(!v8::V8::IsExecutionTerminating()); | 308 CHECK(!v8::V8::IsExecutionTerminating()); |
294 v8::Handle<v8::String> source = | 309 v8::Handle<v8::String> source = v8::String::NewFromUtf8( |
295 v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); | 310 CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }"); |
296 v8::Script::Compile(source)->Run(); | 311 v8::Script::Compile(source)->Run(); |
297 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 312 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); |
298 // Check we can run JS again after termination. | 313 // Check we can run JS again after termination. |
299 CHECK(v8::Script::Compile(v8::String::New("function f() { return true; }" | 314 CHECK(v8::Script::Compile( |
300 "f()"))->Run()->IsTrue()); | 315 v8::String::NewFromUtf8(CcTest::isolate(), |
| 316 "function f() { return true; }" |
| 317 "f()")) |
| 318 ->Run() |
| 319 ->IsTrue()); |
301 } | 320 } |
302 | 321 |
303 | 322 |
304 void DoLoopCancelTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { | 323 void DoLoopCancelTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { |
305 v8::TryCatch try_catch; | 324 v8::TryCatch try_catch; |
306 CHECK(!v8::V8::IsExecutionTerminating()); | 325 CHECK(!v8::V8::IsExecutionTerminating()); |
307 v8::Script::Compile(v8::String::New("var term = true;" | 326 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), |
308 "while(true) {" | 327 "var term = true;" |
309 " if (term) terminate();" | 328 "while(true) {" |
310 " term = false;" | 329 " if (term) terminate();" |
311 "}" | 330 " term = false;" |
312 "fail();"))->Run(); | 331 "}" |
| 332 "fail();"))->Run(); |
313 CHECK(try_catch.HasCaught()); | 333 CHECK(try_catch.HasCaught()); |
314 CHECK(try_catch.Exception()->IsNull()); | 334 CHECK(try_catch.Exception()->IsNull()); |
315 CHECK(try_catch.Message().IsEmpty()); | 335 CHECK(try_catch.Message().IsEmpty()); |
316 CHECK(!try_catch.CanContinue()); | 336 CHECK(!try_catch.CanContinue()); |
317 CHECK(v8::V8::IsExecutionTerminating()); | 337 CHECK(v8::V8::IsExecutionTerminating()); |
318 CHECK(try_catch.HasTerminated()); | 338 CHECK(try_catch.HasTerminated()); |
319 v8::V8::CancelTerminateExecution(CcTest::isolate()); | 339 v8::V8::CancelTerminateExecution(CcTest::isolate()); |
320 CHECK(!v8::V8::IsExecutionTerminating()); | 340 CHECK(!v8::V8::IsExecutionTerminating()); |
321 } | 341 } |
322 | 342 |
323 | 343 |
324 // Test that a single thread of JavaScript execution can terminate | 344 // Test that a single thread of JavaScript execution can terminate |
325 // itself and then resume execution. | 345 // itself and then resume execution. |
326 TEST(TerminateCancelTerminateFromThreadItself) { | 346 TEST(TerminateCancelTerminateFromThreadItself) { |
327 v8::Isolate* isolate = CcTest::isolate(); | 347 v8::Isolate* isolate = CcTest::isolate(); |
328 v8::HandleScope scope(isolate); | 348 v8::HandleScope scope(isolate); |
329 v8::Handle<v8::ObjectTemplate> global = | 349 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( |
330 CreateGlobalTemplate(TerminateCurrentThread, DoLoopCancelTerminate); | 350 isolate, TerminateCurrentThread, DoLoopCancelTerminate); |
331 v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global); | 351 v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global); |
332 v8::Context::Scope context_scope(context); | 352 v8::Context::Scope context_scope(context); |
333 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 353 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); |
334 v8::Handle<v8::String> source = | 354 v8::Handle<v8::String> source = v8::String::NewFromUtf8( |
335 v8::String::New("try { doloop(); } catch(e) { fail(); } 'completed';"); | 355 isolate, "try { doloop(); } catch(e) { fail(); } 'completed';"); |
336 // Check that execution completed with correct return value. | 356 // Check that execution completed with correct return value. |
337 CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed"))); | 357 CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed"))); |
338 } | 358 } |
OLD | NEW |