deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / test / cctest / test-thread-termination.cc
1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 //     * Redistributions of source code must retain the above copyright
7 //       notice, this list of conditions and the following disclaimer.
8 //     * Redistributions in binary form must reproduce the above
9 //       copyright notice, this list of conditions and the following
10 //       disclaimer in the documentation and/or other materials provided
11 //       with the distribution.
12 //     * Neither the name of Google Inc. nor the names of its
13 //       contributors may be used to endorse or promote products derived
14 //       from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #include "src/v8.h"
29 #include "test/cctest/cctest.h"
30
31 #include "src/base/platform/platform.h"
32
33
34 v8::base::Semaphore* semaphore = NULL;
35
36
37 void Signal(const v8::FunctionCallbackInfo<v8::Value>& args) {
38   semaphore->Signal();
39 }
40
41
42 void TerminateCurrentThread(const v8::FunctionCallbackInfo<v8::Value>& args) {
43   CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
44   v8::V8::TerminateExecution(args.GetIsolate());
45 }
46
47
48 void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) {
49   CHECK(false);
50 }
51
52
53 void Loop(const v8::FunctionCallbackInfo<v8::Value>& args) {
54   CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
55   v8::Handle<v8::String> source = v8::String::NewFromUtf8(
56       args.GetIsolate(), "try { doloop(); fail(); } catch(e) { fail(); }");
57   v8::Handle<v8::Value> result = v8::Script::Compile(source)->Run();
58   CHECK(result.IsEmpty());
59   CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
60 }
61
62
63 void DoLoop(const v8::FunctionCallbackInfo<v8::Value>& args) {
64   v8::TryCatch try_catch;
65   CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
66   v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(),
67                                               "function f() {"
68                                               "  var term = true;"
69                                               "  try {"
70                                               "    while(true) {"
71                                               "      if (term) terminate();"
72                                               "      term = false;"
73                                               "    }"
74                                               "    fail();"
75                                               "  } catch(e) {"
76                                               "    fail();"
77                                               "  }"
78                                               "}"
79                                               "f()"))->Run();
80   CHECK(try_catch.HasCaught());
81   CHECK(try_catch.Exception()->IsNull());
82   CHECK(try_catch.Message().IsEmpty());
83   CHECK(!try_catch.CanContinue());
84   CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
85 }
86
87
88 void DoLoopNoCall(const v8::FunctionCallbackInfo<v8::Value>& args) {
89   v8::TryCatch try_catch;
90   CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
91   v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(),
92                                               "var term = true;"
93                                               "while(true) {"
94                                               "  if (term) terminate();"
95                                               "  term = false;"
96                                               "}"))->Run();
97   CHECK(try_catch.HasCaught());
98   CHECK(try_catch.Exception()->IsNull());
99   CHECK(try_catch.Message().IsEmpty());
100   CHECK(!try_catch.CanContinue());
101   CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
102 }
103
104
105 v8::Handle<v8::ObjectTemplate> CreateGlobalTemplate(
106     v8::Isolate* isolate,
107     v8::FunctionCallback terminate,
108     v8::FunctionCallback doloop) {
109   v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
110   global->Set(v8::String::NewFromUtf8(isolate, "terminate"),
111               v8::FunctionTemplate::New(isolate, terminate));
112   global->Set(v8::String::NewFromUtf8(isolate, "fail"),
113               v8::FunctionTemplate::New(isolate, Fail));
114   global->Set(v8::String::NewFromUtf8(isolate, "loop"),
115               v8::FunctionTemplate::New(isolate, Loop));
116   global->Set(v8::String::NewFromUtf8(isolate, "doloop"),
117               v8::FunctionTemplate::New(isolate, doloop));
118   return global;
119 }
120
121
122 // Test that a single thread of JavaScript execution can terminate
123 // itself.
124 TEST(TerminateOnlyV8ThreadFromThreadItself) {
125   v8::HandleScope scope(CcTest::isolate());
126   v8::Handle<v8::ObjectTemplate> global =
127       CreateGlobalTemplate(CcTest::isolate(), TerminateCurrentThread, DoLoop);
128   v8::Handle<v8::Context> context =
129       v8::Context::New(CcTest::isolate(), NULL, global);
130   v8::Context::Scope context_scope(context);
131   CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
132   // Run a loop that will be infinite if thread termination does not work.
133   v8::Handle<v8::String> source = v8::String::NewFromUtf8(
134       CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }");
135   v8::Script::Compile(source)->Run();
136   // Test that we can run the code again after thread termination.
137   CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
138   v8::Script::Compile(source)->Run();
139 }
140
141
142 // Test that a single thread of JavaScript execution can terminate
143 // itself in a loop that performs no calls.
144 TEST(TerminateOnlyV8ThreadFromThreadItselfNoLoop) {
145   v8::HandleScope scope(CcTest::isolate());
146   v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(
147       CcTest::isolate(), TerminateCurrentThread, DoLoopNoCall);
148   v8::Handle<v8::Context> context =
149       v8::Context::New(CcTest::isolate(), NULL, global);
150   v8::Context::Scope context_scope(context);
151   CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
152   // Run a loop that will be infinite if thread termination does not work.
153   v8::Handle<v8::String> source = v8::String::NewFromUtf8(
154       CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }");
155   v8::Script::Compile(source)->Run();
156   CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
157   // Test that we can run the code again after thread termination.
158   v8::Script::Compile(source)->Run();
159 }
160
161
162 class TerminatorThread : public v8::base::Thread {
163  public:
164   explicit TerminatorThread(i::Isolate* isolate)
165       : Thread(Options("TerminatorThread")),
166         isolate_(reinterpret_cast<v8::Isolate*>(isolate)) {}
167   void Run() {
168     semaphore->Wait();
169     CHECK(!v8::V8::IsExecutionTerminating(isolate_));
170     v8::V8::TerminateExecution(isolate_);
171   }
172
173  private:
174   v8::Isolate* isolate_;
175 };
176
177
178 // Test that a single thread of JavaScript execution can be terminated
179 // from the side by another thread.
180 TEST(TerminateOnlyV8ThreadFromOtherThread) {
181   semaphore = new v8::base::Semaphore(0);
182   TerminatorThread thread(CcTest::i_isolate());
183   thread.Start();
184
185   v8::HandleScope scope(CcTest::isolate());
186   v8::Handle<v8::ObjectTemplate> global =
187       CreateGlobalTemplate(CcTest::isolate(), Signal, DoLoop);
188   v8::Handle<v8::Context> context =
189       v8::Context::New(CcTest::isolate(), NULL, global);
190   v8::Context::Scope context_scope(context);
191   CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
192   // Run a loop that will be infinite if thread termination does not work.
193   v8::Handle<v8::String> source = v8::String::NewFromUtf8(
194       CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }");
195   i::FLAG_turbo_osr = false;  // TODO(titzer): interrupts in TF loops.
196   v8::Script::Compile(source)->Run();
197
198   thread.Join();
199   delete semaphore;
200   semaphore = NULL;
201 }
202
203
204 int call_count = 0;
205
206
207 void TerminateOrReturnObject(const v8::FunctionCallbackInfo<v8::Value>& args) {
208   if (++call_count == 10) {
209     CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
210     v8::V8::TerminateExecution(args.GetIsolate());
211     return;
212   }
213   v8::Local<v8::Object> result = v8::Object::New(args.GetIsolate());
214   result->Set(v8::String::NewFromUtf8(args.GetIsolate(), "x"),
215               v8::Integer::New(args.GetIsolate(), 42));
216   args.GetReturnValue().Set(result);
217 }
218
219
220 void LoopGetProperty(const v8::FunctionCallbackInfo<v8::Value>& args) {
221   v8::TryCatch try_catch;
222   CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
223   v8::Script::Compile(
224       v8::String::NewFromUtf8(args.GetIsolate(),
225                               "function f() {"
226                               "  try {"
227                               "    while(true) {"
228                               "      terminate_or_return_object().x;"
229                               "    }"
230                               "    fail();"
231                               "  } catch(e) {"
232                               "    (function() {})();"  // trigger stack check.
233                               "    fail();"
234                               "  }"
235                               "}"
236                               "f()"))->Run();
237   CHECK(try_catch.HasCaught());
238   CHECK(try_catch.Exception()->IsNull());
239   CHECK(try_catch.Message().IsEmpty());
240   CHECK(!try_catch.CanContinue());
241   CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
242 }
243
244
245 // Test that we correctly handle termination exceptions if they are
246 // triggered by the creation of error objects in connection with ICs.
247 TEST(TerminateLoadICException) {
248   v8::Isolate* isolate = CcTest::isolate();
249   v8::HandleScope scope(isolate);
250   v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
251   global->Set(
252       v8::String::NewFromUtf8(isolate, "terminate_or_return_object"),
253       v8::FunctionTemplate::New(isolate, TerminateOrReturnObject));
254   global->Set(v8::String::NewFromUtf8(isolate, "fail"),
255               v8::FunctionTemplate::New(isolate, Fail));
256   global->Set(v8::String::NewFromUtf8(isolate, "loop"),
257               v8::FunctionTemplate::New(isolate, LoopGetProperty));
258
259   v8::Handle<v8::Context> context =
260       v8::Context::New(isolate, NULL, global);
261   v8::Context::Scope context_scope(context);
262   CHECK(!v8::V8::IsExecutionTerminating(isolate));
263   // Run a loop that will be infinite if thread termination does not work.
264   v8::Handle<v8::String> source = v8::String::NewFromUtf8(
265       isolate, "try { loop(); fail(); } catch(e) { fail(); }");
266   call_count = 0;
267   v8::Script::Compile(source)->Run();
268   // Test that we can run the code again after thread termination.
269   CHECK(!v8::V8::IsExecutionTerminating(isolate));
270   call_count = 0;
271   v8::Script::Compile(source)->Run();
272 }
273
274
275 v8::Persistent<v8::String> reenter_script_1;
276 v8::Persistent<v8::String> reenter_script_2;
277
278 void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) {
279   v8::TryCatch try_catch;
280   v8::Isolate* isolate = args.GetIsolate();
281   CHECK(!v8::V8::IsExecutionTerminating(isolate));
282   v8::Local<v8::String> script =
283       v8::Local<v8::String>::New(isolate, reenter_script_1);
284   v8::Script::Compile(script)->Run();
285   CHECK(try_catch.HasCaught());
286   CHECK(try_catch.Exception()->IsNull());
287   CHECK(try_catch.Message().IsEmpty());
288   CHECK(!try_catch.CanContinue());
289   CHECK(v8::V8::IsExecutionTerminating(isolate));
290   script = v8::Local<v8::String>::New(isolate, reenter_script_2);
291   v8::Script::Compile(script)->Run();
292 }
293
294
295 // Test that reentry into V8 while the termination exception is still pending
296 // (has not yet unwound the 0-level JS frame) does not crash.
297 TEST(TerminateAndReenterFromThreadItself) {
298   v8::Isolate* isolate = CcTest::isolate();
299   v8::HandleScope scope(isolate);
300   v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(
301       isolate, TerminateCurrentThread, ReenterAfterTermination);
302   v8::Handle<v8::Context> context =
303       v8::Context::New(isolate, NULL, global);
304   v8::Context::Scope context_scope(context);
305   CHECK(!v8::V8::IsExecutionTerminating());
306   // Create script strings upfront as it won't work when terminating.
307   reenter_script_1.Reset(isolate, v8_str(
308                                       "function f() {"
309                                       "  var term = true;"
310                                       "  try {"
311                                       "    while(true) {"
312                                       "      if (term) terminate();"
313                                       "      term = false;"
314                                       "    }"
315                                       "    fail();"
316                                       "  } catch(e) {"
317                                       "    fail();"
318                                       "  }"
319                                       "}"
320                                       "f()"));
321   reenter_script_2.Reset(isolate, v8_str("function f() { fail(); } f()"));
322   CompileRun("try { loop(); fail(); } catch(e) { fail(); }");
323   CHECK(!v8::V8::IsExecutionTerminating(isolate));
324   // Check we can run JS again after termination.
325   CHECK(CompileRun("function f() { return true; } f()")->IsTrue());
326   reenter_script_1.Reset();
327   reenter_script_2.Reset();
328 }
329
330
331 void DoLoopCancelTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) {
332   v8::TryCatch try_catch;
333   CHECK(!v8::V8::IsExecutionTerminating());
334   v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(),
335                                               "var term = true;"
336                                               "while(true) {"
337                                               "  if (term) terminate();"
338                                               "  term = false;"
339                                               "}"
340                                               "fail();"))->Run();
341   CHECK(try_catch.HasCaught());
342   CHECK(try_catch.Exception()->IsNull());
343   CHECK(try_catch.Message().IsEmpty());
344   CHECK(!try_catch.CanContinue());
345   CHECK(v8::V8::IsExecutionTerminating());
346   CHECK(try_catch.HasTerminated());
347   v8::V8::CancelTerminateExecution(CcTest::isolate());
348   CHECK(!v8::V8::IsExecutionTerminating());
349 }
350
351
352 // Test that a single thread of JavaScript execution can terminate
353 // itself and then resume execution.
354 TEST(TerminateCancelTerminateFromThreadItself) {
355   v8::Isolate* isolate = CcTest::isolate();
356   v8::HandleScope scope(isolate);
357   v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(
358       isolate, TerminateCurrentThread, DoLoopCancelTerminate);
359   v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global);
360   v8::Context::Scope context_scope(context);
361   CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
362   v8::Handle<v8::String> source = v8::String::NewFromUtf8(
363       isolate, "try { doloop(); } catch(e) { fail(); } 'completed';");
364   // Check that execution completed with correct return value.
365   CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed")));
366 }
367
368
369 void MicrotaskShouldNotRun(const v8::FunctionCallbackInfo<v8::Value>& info) {
370   CHECK(false);
371 }
372
373
374 void MicrotaskLoopForever(const v8::FunctionCallbackInfo<v8::Value>& info) {
375   v8::Isolate* isolate = info.GetIsolate();
376   v8::HandleScope scope(isolate);
377   // Enqueue another should-not-run task to ensure we clean out the queue
378   // when we terminate.
379   isolate->EnqueueMicrotask(v8::Function::New(isolate, MicrotaskShouldNotRun));
380   i::FLAG_turbo_osr = false;  // TODO(titzer): interrupts in TF loops.
381   CompileRun("terminate(); while (true) { }");
382   CHECK(v8::V8::IsExecutionTerminating());
383 }
384
385
386 TEST(TerminateFromOtherThreadWhileMicrotaskRunning) {
387   semaphore = new v8::base::Semaphore(0);
388   TerminatorThread thread(CcTest::i_isolate());
389   thread.Start();
390
391   v8::Isolate* isolate = CcTest::isolate();
392   isolate->SetAutorunMicrotasks(false);
393   v8::HandleScope scope(isolate);
394   v8::Handle<v8::ObjectTemplate> global =
395       CreateGlobalTemplate(CcTest::isolate(), Signal, DoLoop);
396   v8::Handle<v8::Context> context =
397       v8::Context::New(CcTest::isolate(), NULL, global);
398   v8::Context::Scope context_scope(context);
399   isolate->EnqueueMicrotask(v8::Function::New(isolate, MicrotaskLoopForever));
400   // The second task should never be run because we bail out if we're
401   // terminating.
402   isolate->EnqueueMicrotask(v8::Function::New(isolate, MicrotaskShouldNotRun));
403   isolate->RunMicrotasks();
404
405   v8::V8::CancelTerminateExecution(isolate);
406   isolate->RunMicrotasks();  // should not run MicrotaskShouldNotRun
407
408   thread.Join();
409   delete semaphore;
410   semaphore = NULL;
411 }
412
413
414 static int callback_counter = 0;
415
416
417 static void CounterCallback(v8::Isolate* isolate, void* data) {
418   callback_counter++;
419 }
420
421
422 TEST(PostponeTerminateException) {
423   v8::Isolate* isolate = CcTest::isolate();
424   v8::HandleScope scope(isolate);
425   v8::Handle<v8::ObjectTemplate> global =
426       CreateGlobalTemplate(CcTest::isolate(), TerminateCurrentThread, DoLoop);
427   v8::Handle<v8::Context> context =
428       v8::Context::New(CcTest::isolate(), NULL, global);
429   v8::Context::Scope context_scope(context);
430
431   v8::TryCatch try_catch;
432   static const char* terminate_and_loop =
433       "terminate(); for (var i = 0; i < 10000; i++);";
434
435   { // Postpone terminate execution interrupts.
436     i::PostponeInterruptsScope p1(CcTest::i_isolate(),
437                                   i::StackGuard::TERMINATE_EXECUTION) ;
438
439     // API interrupts should still be triggered.
440     CcTest::isolate()->RequestInterrupt(&CounterCallback, NULL);
441     CHECK_EQ(0, callback_counter);
442     CompileRun(terminate_and_loop);
443     CHECK(!try_catch.HasTerminated());
444     CHECK_EQ(1, callback_counter);
445
446     { // Postpone API interrupts as well.
447       i::PostponeInterruptsScope p2(CcTest::i_isolate(),
448                                     i::StackGuard::API_INTERRUPT);
449
450       // None of the two interrupts should trigger.
451       CcTest::isolate()->RequestInterrupt(&CounterCallback, NULL);
452       CompileRun(terminate_and_loop);
453       CHECK(!try_catch.HasTerminated());
454       CHECK_EQ(1, callback_counter);
455     }
456
457     // Now the previously requested API interrupt should trigger.
458     CompileRun(terminate_and_loop);
459     CHECK(!try_catch.HasTerminated());
460     CHECK_EQ(2, callback_counter);
461   }
462
463   // Now the previously requested terminate execution interrupt should trigger.
464   CompileRun("for (var i = 0; i < 10000; i++);");
465   CHECK(try_catch.HasTerminated());
466   CHECK_EQ(2, callback_counter);
467 }
468
469
470 TEST(ErrorObjectAfterTermination) {
471   v8::Isolate* isolate = CcTest::isolate();
472   v8::HandleScope scope(isolate);
473   v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
474   v8::Context::Scope context_scope(context);
475   v8::V8::TerminateExecution(isolate);
476   v8::Local<v8::Value> error = v8::Exception::Error(v8_str("error"));
477   // TODO(yangguo): crbug/403509. Check for empty handle instead.
478   CHECK(error->IsUndefined());
479 }
480
481
482 void InnerTryCallTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) {
483   CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
484   v8::Handle<v8::Object> global = CcTest::global();
485   v8::Handle<v8::Function> loop =
486       v8::Handle<v8::Function>::Cast(global->Get(v8_str("loop")));
487   i::MaybeHandle<i::Object> result =
488       i::Execution::TryCall(v8::Utils::OpenHandle((*loop)),
489                             v8::Utils::OpenHandle((*global)), 0, NULL, NULL);
490   CHECK(result.is_null());
491   // TryCall ignores terminate execution, but rerequests the interrupt.
492   CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
493   CHECK(CompileRun("1 + 1;").IsEmpty());
494 }
495
496
497 TEST(TerminationInInnerTryCall) {
498   v8::Isolate* isolate = CcTest::isolate();
499   v8::HandleScope scope(isolate);
500   v8::Handle<v8::ObjectTemplate> global_template = CreateGlobalTemplate(
501       CcTest::isolate(), TerminateCurrentThread, DoLoopNoCall);
502   global_template->Set(
503       v8_str("inner_try_call_terminate"),
504       v8::FunctionTemplate::New(isolate, InnerTryCallTerminate));
505   v8::Handle<v8::Context> context =
506       v8::Context::New(CcTest::isolate(), NULL, global_template);
507   v8::Context::Scope context_scope(context);
508   {
509     v8::TryCatch try_catch;
510     CompileRun("inner_try_call_terminate()");
511     CHECK(try_catch.HasTerminated());
512   }
513   CHECK_EQ(4, CompileRun("2 + 2")->ToInt32()->Int32Value());
514   CHECK(!v8::V8::IsExecutionTerminating());
515 }
516
517
518 TEST(TerminateAndTryCall) {
519   i::FLAG_allow_natives_syntax = true;
520   v8::Isolate* isolate = CcTest::isolate();
521   v8::HandleScope scope(isolate);
522   v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(
523       isolate, TerminateCurrentThread, DoLoopCancelTerminate);
524   v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global);
525   v8::Context::Scope context_scope(context);
526   CHECK(!v8::V8::IsExecutionTerminating(isolate));
527   v8::TryCatch try_catch;
528   CHECK(!v8::V8::IsExecutionTerminating(isolate));
529   // Terminate execution has been triggered inside TryCall, but re-requested
530   // to trigger later.
531   CHECK(CompileRun("terminate(); reference_error();").IsEmpty());
532   CHECK(try_catch.HasCaught());
533   CHECK(!v8::V8::IsExecutionTerminating(isolate));
534   CHECK(CcTest::global()->Get(v8_str("terminate"))->IsFunction());
535   // The first stack check after terminate has been re-requested fails.
536   CHECK(CompileRun("1 + 1").IsEmpty());
537   CHECK(!v8::V8::IsExecutionTerminating(isolate));
538   // V8 then recovers.
539   CHECK_EQ(4, CompileRun("2 + 2")->ToInt32()->Int32Value());
540   CHECK(!v8::V8::IsExecutionTerminating(isolate));
541 }