Upgrade V8 to version 4.9.385.28

https://chromium.googlesource.com/v8/v8/+/4.9.385.28

FPIIM-449

Change-Id: I4b2e74289d4bf3667f2f3dc8aa2e541f63e26eb4
diff --git a/test/cctest/test-thread-termination.cc b/test/cctest/test-thread-termination.cc
index 21d3b95..05a3c33 100644
--- a/test/cctest/test-thread-termination.cc
+++ b/test/cctest/test-thread-termination.cc
@@ -40,8 +40,8 @@
 
 
 void TerminateCurrentThread(const v8::FunctionCallbackInfo<v8::Value>& args) {
-  CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
-  v8::V8::TerminateExecution(args.GetIsolate());
+  CHECK(!args.GetIsolate()->IsExecutionTerminating());
+  args.GetIsolate()->TerminateExecution();
 }
 
 
@@ -51,70 +51,70 @@
 
 
 void Loop(const v8::FunctionCallbackInfo<v8::Value>& args) {
-  CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
-  v8::Handle<v8::String> source = v8::String::NewFromUtf8(
-      args.GetIsolate(), "try { doloop(); fail(); } catch(e) { fail(); }");
-  v8::Handle<v8::Value> result = v8::Script::Compile(source)->Run();
+  CHECK(!args.GetIsolate()->IsExecutionTerminating());
+  v8::MaybeLocal<v8::Value> result =
+      CompileRun(args.GetIsolate()->GetCurrentContext(),
+                 "try { doloop(); fail(); } catch(e) { fail(); }");
   CHECK(result.IsEmpty());
-  CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
+  CHECK(args.GetIsolate()->IsExecutionTerminating());
 }
 
 
 void DoLoop(const v8::FunctionCallbackInfo<v8::Value>& args) {
-  v8::TryCatch try_catch;
-  CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
-  v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(),
-                                              "function f() {"
-                                              "  var term = true;"
-                                              "  try {"
-                                              "    while(true) {"
-                                              "      if (term) terminate();"
-                                              "      term = false;"
-                                              "    }"
-                                              "    fail();"
-                                              "  } catch(e) {"
-                                              "    fail();"
-                                              "  }"
-                                              "}"
-                                              "f()"))->Run();
+  v8::TryCatch try_catch(args.GetIsolate());
+  CHECK(!args.GetIsolate()->IsExecutionTerminating());
+  v8::MaybeLocal<v8::Value> result =
+      CompileRun(args.GetIsolate()->GetCurrentContext(),
+                 "function f() {"
+                 "  var term = true;"
+                 "  try {"
+                 "    while(true) {"
+                 "      if (term) terminate();"
+                 "      term = false;"
+                 "    }"
+                 "    fail();"
+                 "  } catch(e) {"
+                 "    fail();"
+                 "  }"
+                 "}"
+                 "f()");
+  CHECK(result.IsEmpty());
   CHECK(try_catch.HasCaught());
   CHECK(try_catch.Exception()->IsNull());
   CHECK(try_catch.Message().IsEmpty());
   CHECK(!try_catch.CanContinue());
-  CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
+  CHECK(args.GetIsolate()->IsExecutionTerminating());
 }
 
 
 void DoLoopNoCall(const v8::FunctionCallbackInfo<v8::Value>& args) {
-  v8::TryCatch try_catch;
-  CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
-  v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(),
-                                              "var term = true;"
-                                              "while(true) {"
-                                              "  if (term) terminate();"
-                                              "  term = false;"
-                                              "}"))->Run();
+  v8::TryCatch try_catch(args.GetIsolate());
+  CHECK(!args.GetIsolate()->IsExecutionTerminating());
+  v8::MaybeLocal<v8::Value> result =
+      CompileRun(args.GetIsolate()->GetCurrentContext(),
+                 "var term = true;"
+                 "while(true) {"
+                 "  if (term) terminate();"
+                 "  term = false;"
+                 "}");
+  CHECK(result.IsEmpty());
   CHECK(try_catch.HasCaught());
   CHECK(try_catch.Exception()->IsNull());
   CHECK(try_catch.Message().IsEmpty());
   CHECK(!try_catch.CanContinue());
-  CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
+  CHECK(args.GetIsolate()->IsExecutionTerminating());
 }
 
 
-v8::Handle<v8::ObjectTemplate> CreateGlobalTemplate(
-    v8::Isolate* isolate,
-    v8::FunctionCallback terminate,
+v8::Local<v8::ObjectTemplate> CreateGlobalTemplate(
+    v8::Isolate* isolate, v8::FunctionCallback terminate,
     v8::FunctionCallback doloop) {
-  v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
-  global->Set(v8::String::NewFromUtf8(isolate, "terminate"),
+  v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
+  global->Set(v8_str("terminate"),
               v8::FunctionTemplate::New(isolate, terminate));
-  global->Set(v8::String::NewFromUtf8(isolate, "fail"),
-              v8::FunctionTemplate::New(isolate, Fail));
-  global->Set(v8::String::NewFromUtf8(isolate, "loop"),
-              v8::FunctionTemplate::New(isolate, Loop));
-  global->Set(v8::String::NewFromUtf8(isolate, "doloop"),
-              v8::FunctionTemplate::New(isolate, doloop));
+  global->Set(v8_str("fail"), v8::FunctionTemplate::New(isolate, Fail));
+  global->Set(v8_str("loop"), v8::FunctionTemplate::New(isolate, Loop));
+  global->Set(v8_str("doloop"), v8::FunctionTemplate::New(isolate, doloop));
   return global;
 }
 
@@ -123,19 +123,22 @@
 // itself.
 TEST(TerminateOnlyV8ThreadFromThreadItself) {
   v8::HandleScope scope(CcTest::isolate());
-  v8::Handle<v8::ObjectTemplate> global =
+  v8::Local<v8::ObjectTemplate> global =
       CreateGlobalTemplate(CcTest::isolate(), TerminateCurrentThread, DoLoop);
-  v8::Handle<v8::Context> context =
+  v8::Local<v8::Context> context =
       v8::Context::New(CcTest::isolate(), NULL, global);
   v8::Context::Scope context_scope(context);
-  CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
+  CHECK(!CcTest::isolate()->IsExecutionTerminating());
   // Run a loop that will be infinite if thread termination does not work.
-  v8::Handle<v8::String> source = v8::String::NewFromUtf8(
-      CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }");
-  v8::Script::Compile(source)->Run();
+  v8::MaybeLocal<v8::Value> result =
+      CompileRun(CcTest::isolate()->GetCurrentContext(),
+                 "try { loop(); fail(); } catch(e) { fail(); }");
+  CHECK(result.IsEmpty());
   // Test that we can run the code again after thread termination.
-  CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
-  v8::Script::Compile(source)->Run();
+  CHECK(!CcTest::isolate()->IsExecutionTerminating());
+  result = CompileRun(CcTest::isolate()->GetCurrentContext(),
+                      "try { loop(); fail(); } catch(e) { fail(); }");
+  CHECK(result.IsEmpty());
 }
 
 
@@ -143,19 +146,21 @@
 // itself in a loop that performs no calls.
 TEST(TerminateOnlyV8ThreadFromThreadItselfNoLoop) {
   v8::HandleScope scope(CcTest::isolate());
-  v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(
+  v8::Local<v8::ObjectTemplate> global = CreateGlobalTemplate(
       CcTest::isolate(), TerminateCurrentThread, DoLoopNoCall);
-  v8::Handle<v8::Context> context =
+  v8::Local<v8::Context> context =
       v8::Context::New(CcTest::isolate(), NULL, global);
   v8::Context::Scope context_scope(context);
-  CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
+  CHECK(!CcTest::isolate()->IsExecutionTerminating());
   // Run a loop that will be infinite if thread termination does not work.
-  v8::Handle<v8::String> source = v8::String::NewFromUtf8(
-      CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }");
-  v8::Script::Compile(source)->Run();
-  CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
+  static const char* source = "try { loop(); fail(); } catch(e) { fail(); }";
+  v8::MaybeLocal<v8::Value> result =
+      CompileRun(CcTest::isolate()->GetCurrentContext(), source);
+  CHECK(result.IsEmpty());
+  CHECK(!CcTest::isolate()->IsExecutionTerminating());
   // Test that we can run the code again after thread termination.
-  v8::Script::Compile(source)->Run();
+  result = CompileRun(CcTest::isolate()->GetCurrentContext(), source);
+  CHECK(result.IsEmpty());
 }
 
 
@@ -166,8 +171,8 @@
         isolate_(reinterpret_cast<v8::Isolate*>(isolate)) {}
   void Run() {
     semaphore->Wait();
-    CHECK(!v8::V8::IsExecutionTerminating(isolate_));
-    v8::V8::TerminateExecution(isolate_);
+    CHECK(!isolate_->IsExecutionTerminating());
+    isolate_->TerminateExecution();
   }
 
  private:
@@ -183,17 +188,17 @@
   thread.Start();
 
   v8::HandleScope scope(CcTest::isolate());
-  v8::Handle<v8::ObjectTemplate> global =
+  v8::Local<v8::ObjectTemplate> global =
       CreateGlobalTemplate(CcTest::isolate(), Signal, DoLoop);
-  v8::Handle<v8::Context> context =
+  v8::Local<v8::Context> context =
       v8::Context::New(CcTest::isolate(), NULL, global);
   v8::Context::Scope context_scope(context);
-  CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
+  CHECK(!CcTest::isolate()->IsExecutionTerminating());
   // Run a loop that will be infinite if thread termination does not work.
-  v8::Handle<v8::String> source = v8::String::NewFromUtf8(
-      CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }");
-  v8::Script::Compile(source)->Run();
-
+  v8::MaybeLocal<v8::Value> result =
+      CompileRun(CcTest::isolate()->GetCurrentContext(),
+                 "try { loop(); fail(); } catch(e) { fail(); }");
+  CHECK(result.IsEmpty());
   thread.Join();
   delete semaphore;
   semaphore = NULL;
@@ -205,38 +210,42 @@
 
 void TerminateOrReturnObject(const v8::FunctionCallbackInfo<v8::Value>& args) {
   if (++call_count == 10) {
-    CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
-    v8::V8::TerminateExecution(args.GetIsolate());
+    CHECK(!args.GetIsolate()->IsExecutionTerminating());
+    args.GetIsolate()->TerminateExecution();
     return;
   }
   v8::Local<v8::Object> result = v8::Object::New(args.GetIsolate());
-  result->Set(v8::String::NewFromUtf8(args.GetIsolate(), "x"),
-              v8::Integer::New(args.GetIsolate(), 42));
+  v8::Maybe<bool> val =
+      result->Set(args.GetIsolate()->GetCurrentContext(), v8_str("x"),
+                  v8::Integer::New(args.GetIsolate(), 42));
+  CHECK(val.FromJust());
   args.GetReturnValue().Set(result);
 }
 
 
 void LoopGetProperty(const v8::FunctionCallbackInfo<v8::Value>& args) {
-  v8::TryCatch try_catch;
-  CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
-  v8::Script::Compile(
-      v8::String::NewFromUtf8(args.GetIsolate(),
-                              "function f() {"
-                              "  try {"
-                              "    while(true) {"
-                              "      terminate_or_return_object().x;"
-                              "    }"
-                              "    fail();"
-                              "  } catch(e) {"
-                              "    fail();"
-                              "  }"
-                              "}"
-                              "f()"))->Run();
+  v8::TryCatch try_catch(args.GetIsolate());
+  CHECK(!args.GetIsolate()->IsExecutionTerminating());
+  v8::MaybeLocal<v8::Value> result =
+      CompileRun(args.GetIsolate()->GetCurrentContext(),
+                 "function f() {"
+                 "  try {"
+                 "    while(true) {"
+                 "      terminate_or_return_object().x;"
+                 "    }"
+                 "    fail();"
+                 "  } catch(e) {"
+                 "    (function() {})();"  // trigger stack check.
+                 "    fail();"
+                 "  }"
+                 "}"
+                 "f()");
+  CHECK(result.IsEmpty());
   CHECK(try_catch.HasCaught());
   CHECK(try_catch.Exception()->IsNull());
   CHECK(try_catch.Message().IsEmpty());
   CHECK(!try_catch.CanContinue());
-  CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
+  CHECK(args.GetIsolate()->IsExecutionTerminating());
 }
 
 
@@ -245,56 +254,50 @@
 TEST(TerminateLoadICException) {
   v8::Isolate* isolate = CcTest::isolate();
   v8::HandleScope scope(isolate);
-  v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
-  global->Set(
-      v8::String::NewFromUtf8(isolate, "terminate_or_return_object"),
-      v8::FunctionTemplate::New(isolate, TerminateOrReturnObject));
-  global->Set(v8::String::NewFromUtf8(isolate, "fail"),
-              v8::FunctionTemplate::New(isolate, Fail));
-  global->Set(v8::String::NewFromUtf8(isolate, "loop"),
+  v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
+  global->Set(v8_str("terminate_or_return_object"),
+              v8::FunctionTemplate::New(isolate, TerminateOrReturnObject));
+  global->Set(v8_str("fail"), v8::FunctionTemplate::New(isolate, Fail));
+  global->Set(v8_str("loop"),
               v8::FunctionTemplate::New(isolate, LoopGetProperty));
 
-  v8::Handle<v8::Context> context =
-      v8::Context::New(isolate, NULL, global);
+  v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global);
   v8::Context::Scope context_scope(context);
-  CHECK(!v8::V8::IsExecutionTerminating(isolate));
+  CHECK(!isolate->IsExecutionTerminating());
   // Run a loop that will be infinite if thread termination does not work.
-  v8::Handle<v8::String> source = v8::String::NewFromUtf8(
-      isolate, "try { loop(); fail(); } catch(e) { fail(); }");
+  static const char* source = "try { loop(); fail(); } catch(e) { fail(); }";
   call_count = 0;
-  v8::Script::Compile(source)->Run();
+  v8::MaybeLocal<v8::Value> result =
+      CompileRun(isolate->GetCurrentContext(), source);
+  CHECK(result.IsEmpty());
   // Test that we can run the code again after thread termination.
-  CHECK(!v8::V8::IsExecutionTerminating(isolate));
+  CHECK(!isolate->IsExecutionTerminating());
   call_count = 0;
-  v8::Script::Compile(source)->Run();
+  result = CompileRun(isolate->GetCurrentContext(), source);
+  CHECK(result.IsEmpty());
 }
 
 
+v8::Persistent<v8::String> reenter_script_1;
+v8::Persistent<v8::String> reenter_script_2;
+
 void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) {
-  v8::TryCatch try_catch;
-  CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
-  v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(),
-                                              "function f() {"
-                                              "  var term = true;"
-                                              "  try {"
-                                              "    while(true) {"
-                                              "      if (term) terminate();"
-                                              "      term = false;"
-                                              "    }"
-                                              "    fail();"
-                                              "  } catch(e) {"
-                                              "    fail();"
-                                              "  }"
-                                              "}"
-                                              "f()"))->Run();
+  v8::TryCatch try_catch(args.GetIsolate());
+  v8::Isolate* isolate = args.GetIsolate();
+  CHECK(!isolate->IsExecutionTerminating());
+  v8::Local<v8::String> script =
+      v8::Local<v8::String>::New(isolate, reenter_script_1);
+  v8::MaybeLocal<v8::Value> result = CompileRun(script);
+  CHECK(result.IsEmpty());
   CHECK(try_catch.HasCaught());
   CHECK(try_catch.Exception()->IsNull());
   CHECK(try_catch.Message().IsEmpty());
   CHECK(!try_catch.CanContinue());
-  CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
-  v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(),
-                                              "function f() { fail(); } f()"))
-      ->Run();
+  CHECK(isolate->IsExecutionTerminating());
+  script = v8::Local<v8::String>::New(isolate, reenter_script_2);
+  v8::MaybeLocal<v8::Script> compiled_script =
+      v8::Script::Compile(isolate->GetCurrentContext(), script);
+  CHECK(compiled_script.IsEmpty());
 }
 
 
@@ -303,44 +306,56 @@
 TEST(TerminateAndReenterFromThreadItself) {
   v8::Isolate* isolate = CcTest::isolate();
   v8::HandleScope scope(isolate);
-  v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(
+  v8::Local<v8::ObjectTemplate> global = CreateGlobalTemplate(
       isolate, TerminateCurrentThread, ReenterAfterTermination);
-  v8::Handle<v8::Context> context =
-      v8::Context::New(isolate, NULL, global);
+  v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global);
   v8::Context::Scope context_scope(context);
-  CHECK(!v8::V8::IsExecutionTerminating());
-  v8::Handle<v8::String> source = v8::String::NewFromUtf8(
-      isolate, "try { loop(); fail(); } catch(e) { fail(); }");
-  v8::Script::Compile(source)->Run();
-  CHECK(!v8::V8::IsExecutionTerminating(isolate));
+  CHECK(!v8::Isolate::GetCurrent()->IsExecutionTerminating());
+  // Create script strings upfront as it won't work when terminating.
+  reenter_script_1.Reset(isolate, v8_str(
+                                      "function f() {"
+                                      "  var term = true;"
+                                      "  try {"
+                                      "    while(true) {"
+                                      "      if (term) terminate();"
+                                      "      term = false;"
+                                      "    }"
+                                      "    fail();"
+                                      "  } catch(e) {"
+                                      "    fail();"
+                                      "  }"
+                                      "}"
+                                      "f()"));
+  reenter_script_2.Reset(isolate, v8_str("function f() { fail(); } f()"));
+  CompileRun("try { loop(); fail(); } catch(e) { fail(); }");
+  CHECK(!isolate->IsExecutionTerminating());
   // Check we can run JS again after termination.
-  CHECK(v8::Script::Compile(
-      v8::String::NewFromUtf8(isolate,
-                              "function f() { return true; }"
-                              "f()"))
-            ->Run()
-            ->IsTrue());
+  CHECK(CompileRun("function f() { return true; } f()")->IsTrue());
+  reenter_script_1.Reset();
+  reenter_script_2.Reset();
 }
 
 
 void DoLoopCancelTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) {
-  v8::TryCatch try_catch;
-  CHECK(!v8::V8::IsExecutionTerminating());
-  v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(),
-                                              "var term = true;"
-                                              "while(true) {"
-                                              "  if (term) terminate();"
-                                              "  term = false;"
-                                              "}"
-                                              "fail();"))->Run();
+  v8::TryCatch try_catch(args.GetIsolate());
+  CHECK(!v8::Isolate::GetCurrent()->IsExecutionTerminating());
+  v8::MaybeLocal<v8::Value> result =
+      CompileRun(args.GetIsolate()->GetCurrentContext(),
+                 "var term = true;"
+                 "while(true) {"
+                 "  if (term) terminate();"
+                 "  term = false;"
+                 "}"
+                 "fail();");
+  CHECK(result.IsEmpty());
   CHECK(try_catch.HasCaught());
   CHECK(try_catch.Exception()->IsNull());
   CHECK(try_catch.Message().IsEmpty());
   CHECK(!try_catch.CanContinue());
-  CHECK(v8::V8::IsExecutionTerminating());
+  CHECK(v8::Isolate::GetCurrent()->IsExecutionTerminating());
   CHECK(try_catch.HasTerminated());
-  v8::V8::CancelTerminateExecution(CcTest::isolate());
-  CHECK(!v8::V8::IsExecutionTerminating());
+  CcTest::isolate()->CancelTerminateExecution();
+  CHECK(!v8::Isolate::GetCurrent()->IsExecutionTerminating());
 }
 
 
@@ -349,15 +364,18 @@
 TEST(TerminateCancelTerminateFromThreadItself) {
   v8::Isolate* isolate = CcTest::isolate();
   v8::HandleScope scope(isolate);
-  v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(
+  v8::Local<v8::ObjectTemplate> global = CreateGlobalTemplate(
       isolate, TerminateCurrentThread, DoLoopCancelTerminate);
-  v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global);
+  v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global);
   v8::Context::Scope context_scope(context);
-  CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
-  v8::Handle<v8::String> source = v8::String::NewFromUtf8(
-      isolate, "try { doloop(); } catch(e) { fail(); } 'completed';");
+  CHECK(!CcTest::isolate()->IsExecutionTerminating());
   // Check that execution completed with correct return value.
-  CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed")));
+  v8::Local<v8::Value> result =
+      CompileRun(isolate->GetCurrentContext(),
+                 "try { doloop(); } catch(e) { fail(); } 'completed';")
+          .ToLocalChecked();
+  CHECK(result->Equals(isolate->GetCurrentContext(), v8_str("completed"))
+            .FromJust());
 }
 
 
@@ -371,9 +389,11 @@
   v8::HandleScope scope(isolate);
   // Enqueue another should-not-run task to ensure we clean out the queue
   // when we terminate.
-  isolate->EnqueueMicrotask(v8::Function::New(isolate, MicrotaskShouldNotRun));
+  isolate->EnqueueMicrotask(
+      v8::Function::New(isolate->GetCurrentContext(), MicrotaskShouldNotRun)
+          .ToLocalChecked());
   CompileRun("terminate(); while (true) { }");
-  CHECK(v8::V8::IsExecutionTerminating());
+  CHECK(v8::Isolate::GetCurrent()->IsExecutionTerminating());
 }
 
 
@@ -385,18 +405,22 @@
   v8::Isolate* isolate = CcTest::isolate();
   isolate->SetAutorunMicrotasks(false);
   v8::HandleScope scope(isolate);
-  v8::Handle<v8::ObjectTemplate> global =
+  v8::Local<v8::ObjectTemplate> global =
       CreateGlobalTemplate(CcTest::isolate(), Signal, DoLoop);
-  v8::Handle<v8::Context> context =
+  v8::Local<v8::Context> context =
       v8::Context::New(CcTest::isolate(), NULL, global);
   v8::Context::Scope context_scope(context);
-  isolate->EnqueueMicrotask(v8::Function::New(isolate, MicrotaskLoopForever));
+  isolate->EnqueueMicrotask(
+      v8::Function::New(isolate->GetCurrentContext(), MicrotaskLoopForever)
+          .ToLocalChecked());
   // The second task should never be run because we bail out if we're
   // terminating.
-  isolate->EnqueueMicrotask(v8::Function::New(isolate, MicrotaskShouldNotRun));
+  isolate->EnqueueMicrotask(
+      v8::Function::New(isolate->GetCurrentContext(), MicrotaskShouldNotRun)
+          .ToLocalChecked());
   isolate->RunMicrotasks();
 
-  v8::V8::CancelTerminateExecution(isolate);
+  isolate->CancelTerminateExecution();
   isolate->RunMicrotasks();  // should not run MicrotaskShouldNotRun
 
   thread.Join();
@@ -416,19 +440,19 @@
 TEST(PostponeTerminateException) {
   v8::Isolate* isolate = CcTest::isolate();
   v8::HandleScope scope(isolate);
-  v8::Handle<v8::ObjectTemplate> global =
+  v8::Local<v8::ObjectTemplate> global =
       CreateGlobalTemplate(CcTest::isolate(), TerminateCurrentThread, DoLoop);
-  v8::Handle<v8::Context> context =
+  v8::Local<v8::Context> context =
       v8::Context::New(CcTest::isolate(), NULL, global);
   v8::Context::Scope context_scope(context);
 
-  v8::TryCatch try_catch;
+  v8::TryCatch try_catch(isolate);
   static const char* terminate_and_loop =
       "terminate(); for (var i = 0; i < 10000; i++);";
 
   { // Postpone terminate execution interrupts.
     i::PostponeInterruptsScope p1(CcTest::i_isolate(),
-                                  i::StackGuard::TERMINATE_EXECUTION) ;
+                                  i::StackGuard::TERMINATE_EXECUTION);
 
     // API interrupts should still be triggered.
     CcTest::isolate()->RequestInterrupt(&CounterCallback, NULL);
@@ -464,10 +488,81 @@
 TEST(ErrorObjectAfterTermination) {
   v8::Isolate* isolate = CcTest::isolate();
   v8::HandleScope scope(isolate);
-  v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
+  v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
   v8::Context::Scope context_scope(context);
-  v8::V8::TerminateExecution(isolate);
+  isolate->TerminateExecution();
   v8::Local<v8::Value> error = v8::Exception::Error(v8_str("error"));
   // TODO(yangguo): crbug/403509. Check for empty handle instead.
   CHECK(error->IsUndefined());
 }
+
+
+void InnerTryCallTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) {
+  CHECK(!args.GetIsolate()->IsExecutionTerminating());
+  v8::Local<v8::Object> global = CcTest::global();
+  v8::Local<v8::Function> loop = v8::Local<v8::Function>::Cast(
+      global->Get(CcTest::isolate()->GetCurrentContext(), v8_str("loop"))
+          .ToLocalChecked());
+  i::MaybeHandle<i::Object> result =
+      i::Execution::TryCall(CcTest::i_isolate(), v8::Utils::OpenHandle((*loop)),
+                            v8::Utils::OpenHandle((*global)), 0, NULL, NULL);
+  CHECK(result.is_null());
+  // TryCall ignores terminate execution, but rerequests the interrupt.
+  CHECK(!args.GetIsolate()->IsExecutionTerminating());
+  CHECK(CompileRun("1 + 1;").IsEmpty());
+}
+
+
+TEST(TerminationInInnerTryCall) {
+  v8::Isolate* isolate = CcTest::isolate();
+  v8::HandleScope scope(isolate);
+  v8::Local<v8::ObjectTemplate> global_template = CreateGlobalTemplate(
+      CcTest::isolate(), TerminateCurrentThread, DoLoopNoCall);
+  global_template->Set(
+      v8_str("inner_try_call_terminate"),
+      v8::FunctionTemplate::New(isolate, InnerTryCallTerminate));
+  v8::Local<v8::Context> context =
+      v8::Context::New(CcTest::isolate(), NULL, global_template);
+  v8::Context::Scope context_scope(context);
+  {
+    v8::TryCatch try_catch(isolate);
+    CompileRun("inner_try_call_terminate()");
+    CHECK(try_catch.HasTerminated());
+  }
+  v8::Maybe<int32_t> result = CompileRun("2 + 2")->Int32Value(
+      v8::Isolate::GetCurrent()->GetCurrentContext());
+  CHECK_EQ(4, result.FromJust());
+  CHECK(!v8::Isolate::GetCurrent()->IsExecutionTerminating());
+}
+
+
+TEST(TerminateAndTryCall) {
+  i::FLAG_allow_natives_syntax = true;
+  v8::Isolate* isolate = CcTest::isolate();
+  v8::HandleScope scope(isolate);
+  v8::Local<v8::ObjectTemplate> global = CreateGlobalTemplate(
+      isolate, TerminateCurrentThread, DoLoopCancelTerminate);
+  v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global);
+  v8::Context::Scope context_scope(context);
+  CHECK(!isolate->IsExecutionTerminating());
+  v8::TryCatch try_catch(isolate);
+  CHECK(!isolate->IsExecutionTerminating());
+  // Terminate execution has been triggered inside TryCall, but re-requested
+  // to trigger later.
+  CHECK(CompileRun("terminate(); reference_error();").IsEmpty());
+  CHECK(try_catch.HasCaught());
+  CHECK(!isolate->IsExecutionTerminating());
+  v8::Local<v8::Value> value =
+      CcTest::global()
+          ->Get(isolate->GetCurrentContext(), v8_str("terminate"))
+          .ToLocalChecked();
+  CHECK(value->IsFunction());
+  // The first stack check after terminate has been re-requested fails.
+  CHECK(CompileRun("1 + 1").IsEmpty());
+  CHECK(!isolate->IsExecutionTerminating());
+  // V8 then recovers.
+  v8::Maybe<int32_t> result = CompileRun("2 + 2")->Int32Value(
+      v8::Isolate::GetCurrent()->GetCurrentContext());
+  CHECK_EQ(4, result.FromJust());
+  CHECK(!isolate->IsExecutionTerminating());
+}