2009-08-19 15:14:11 +00:00
|
|
|
// Copyright 2009 the V8 project authors. All rights reserved.
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
#include "platform.h"
|
|
|
|
#include "cctest.h"
|
|
|
|
|
|
|
|
|
|
|
|
v8::internal::Semaphore* semaphore = NULL;
|
|
|
|
|
|
|
|
|
2013-06-20 12:28:27 +00:00
|
|
|
void Signal(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2009-08-19 15:14:11 +00:00
|
|
|
semaphore->Signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 12:28:27 +00:00
|
|
|
void TerminateCurrentThread(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
2013-09-19 07:33:45 +00:00
|
|
|
v8::V8::TerminateExecution(args.GetIsolate());
|
2009-08-19 15:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 12:28:27 +00:00
|
|
|
void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2009-08-19 15:14:11 +00:00
|
|
|
CHECK(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 12:28:27 +00:00
|
|
|
void Loop(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Handle<v8::String> source = v8::String::NewFromUtf8(
|
|
|
|
args.GetIsolate(), "try { doloop(); fail(); } catch(e) { fail(); }");
|
2010-03-04 12:13:04 +00:00
|
|
|
v8::Handle<v8::Value> result = v8::Script::Compile(source)->Run();
|
|
|
|
CHECK(result.IsEmpty());
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
2009-08-19 15:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 12:28:27 +00:00
|
|
|
void DoLoop(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2009-08-19 15:14:11 +00:00
|
|
|
v8::TryCatch try_catch;
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
2013-11-22 12:43:17 +00:00
|
|
|
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();
|
2009-08-19 15:14:11 +00:00
|
|
|
CHECK(try_catch.HasCaught());
|
|
|
|
CHECK(try_catch.Exception()->IsNull());
|
|
|
|
CHECK(try_catch.Message().IsEmpty());
|
|
|
|
CHECK(!try_catch.CanContinue());
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
2009-08-19 15:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 12:28:27 +00:00
|
|
|
void DoLoopNoCall(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2009-11-24 12:23:29 +00:00
|
|
|
v8::TryCatch try_catch;
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(),
|
|
|
|
"var term = true;"
|
|
|
|
"while(true) {"
|
|
|
|
" if (term) terminate();"
|
|
|
|
" term = false;"
|
|
|
|
"}"))->Run();
|
2009-11-24 12:23:29 +00:00
|
|
|
CHECK(try_catch.HasCaught());
|
|
|
|
CHECK(try_catch.Exception()->IsNull());
|
|
|
|
CHECK(try_catch.Message().IsEmpty());
|
|
|
|
CHECK(!try_catch.CanContinue());
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
2009-11-24 12:23:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-19 15:14:11 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> CreateGlobalTemplate(
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Isolate* isolate,
|
2013-06-20 12:28:27 +00:00
|
|
|
v8::FunctionCallback terminate,
|
|
|
|
v8::FunctionCallback doloop) {
|
2009-08-19 15:14:11 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
|
2013-11-22 12:43:17 +00:00
|
|
|
global->Set(v8::String::NewFromUtf8(isolate, "terminate"),
|
2009-08-19 15:14:11 +00:00
|
|
|
v8::FunctionTemplate::New(terminate));
|
2013-11-22 12:43:17 +00:00
|
|
|
global->Set(v8::String::NewFromUtf8(isolate, "fail"),
|
|
|
|
v8::FunctionTemplate::New(Fail));
|
|
|
|
global->Set(v8::String::NewFromUtf8(isolate, "loop"),
|
|
|
|
v8::FunctionTemplate::New(Loop));
|
|
|
|
global->Set(v8::String::NewFromUtf8(isolate, "doloop"),
|
|
|
|
v8::FunctionTemplate::New(doloop));
|
2009-08-19 15:14:11 +00:00
|
|
|
return global;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test that a single thread of JavaScript execution can terminate
|
|
|
|
// itself.
|
|
|
|
TEST(TerminateOnlyV8ThreadFromThreadItself) {
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2009-08-19 15:14:11 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> global =
|
2013-11-22 12:43:17 +00:00
|
|
|
CreateGlobalTemplate(CcTest::isolate(), TerminateCurrentThread, DoLoop);
|
2013-05-02 20:18:42 +00:00
|
|
|
v8::Handle<v8::Context> context =
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Context::New(CcTest::isolate(), NULL, global);
|
2009-11-24 12:23:29 +00:00
|
|
|
v8::Context::Scope context_scope(context);
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
2009-11-24 12:23:29 +00:00
|
|
|
// Run a loop that will be infinite if thread termination does not work.
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Handle<v8::String> source = v8::String::NewFromUtf8(
|
|
|
|
CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }");
|
2009-11-24 12:23:29 +00:00
|
|
|
v8::Script::Compile(source)->Run();
|
|
|
|
// Test that we can run the code again after thread termination.
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
2009-11-24 12:23:29 +00:00
|
|
|
v8::Script::Compile(source)->Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test that a single thread of JavaScript execution can terminate
|
|
|
|
// itself in a loop that performs no calls.
|
|
|
|
TEST(TerminateOnlyV8ThreadFromThreadItselfNoLoop) {
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(
|
|
|
|
CcTest::isolate(), TerminateCurrentThread, DoLoopNoCall);
|
2013-05-02 20:18:42 +00:00
|
|
|
v8::Handle<v8::Context> context =
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Context::New(CcTest::isolate(), NULL, global);
|
2009-08-19 15:14:11 +00:00
|
|
|
v8::Context::Scope context_scope(context);
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
2009-08-19 15:14:11 +00:00
|
|
|
// Run a loop that will be infinite if thread termination does not work.
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Handle<v8::String> source = v8::String::NewFromUtf8(
|
|
|
|
CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }");
|
2009-08-19 15:14:11 +00:00
|
|
|
v8::Script::Compile(source)->Run();
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
2009-08-19 15:14:11 +00:00
|
|
|
// Test that we can run the code again after thread termination.
|
|
|
|
v8::Script::Compile(source)->Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class TerminatorThread : public v8::internal::Thread {
|
2011-03-18 20:35:07 +00:00
|
|
|
public:
|
2011-06-10 09:36:35 +00:00
|
|
|
explicit TerminatorThread(i::Isolate* isolate)
|
2011-06-10 09:54:04 +00:00
|
|
|
: Thread("TerminatorThread"),
|
|
|
|
isolate_(reinterpret_cast<v8::Isolate*>(isolate)) { }
|
2009-08-19 15:14:11 +00:00
|
|
|
void Run() {
|
|
|
|
semaphore->Wait();
|
2011-06-10 09:54:04 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating(isolate_));
|
|
|
|
v8::V8::TerminateExecution(isolate_);
|
2009-08-19 15:14:11 +00:00
|
|
|
}
|
2011-06-10 09:54:04 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
v8::Isolate* isolate_;
|
2009-08-19 15:14:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Test that a single thread of JavaScript execution can be terminated
|
|
|
|
// from the side by another thread.
|
|
|
|
TEST(TerminateOnlyV8ThreadFromOtherThread) {
|
2013-09-02 12:26:06 +00:00
|
|
|
semaphore = new v8::internal::Semaphore(0);
|
2013-09-19 09:17:13 +00:00
|
|
|
TerminatorThread thread(CcTest::i_isolate());
|
2009-08-19 15:14:11 +00:00
|
|
|
thread.Start();
|
|
|
|
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> global =
|
|
|
|
CreateGlobalTemplate(CcTest::isolate(), Signal, DoLoop);
|
2013-05-02 20:18:42 +00:00
|
|
|
v8::Handle<v8::Context> context =
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Context::New(CcTest::isolate(), NULL, global);
|
2009-08-19 15:14:11 +00:00
|
|
|
v8::Context::Scope context_scope(context);
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
2009-08-19 15:14:11 +00:00
|
|
|
// Run a loop that will be infinite if thread termination does not work.
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Handle<v8::String> source = v8::String::NewFromUtf8(
|
|
|
|
CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }");
|
2009-08-19 15:14:11 +00:00
|
|
|
v8::Script::Compile(source)->Run();
|
|
|
|
|
|
|
|
thread.Join();
|
|
|
|
delete semaphore;
|
|
|
|
semaphore = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-01 13:55:45 +00:00
|
|
|
int call_count = 0;
|
|
|
|
|
|
|
|
|
2013-06-20 12:28:27 +00:00
|
|
|
void TerminateOrReturnObject(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2009-09-01 13:55:45 +00:00
|
|
|
if (++call_count == 10) {
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
|
|
|
v8::V8::TerminateExecution(args.GetIsolate());
|
2013-06-20 12:28:27 +00:00
|
|
|
return;
|
2009-09-01 13:55:45 +00:00
|
|
|
}
|
|
|
|
v8::Local<v8::Object> result = v8::Object::New();
|
2013-11-22 12:43:17 +00:00
|
|
|
result->Set(v8::String::NewFromUtf8(args.GetIsolate(), "x"),
|
|
|
|
v8::Integer::New(42));
|
2013-06-20 12:28:27 +00:00
|
|
|
args.GetReturnValue().Set(result);
|
2009-09-01 13:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 12:28:27 +00:00
|
|
|
void LoopGetProperty(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2009-09-01 13:55:45 +00:00
|
|
|
v8::TryCatch try_catch;
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Script::Compile(
|
|
|
|
v8::String::NewFromUtf8(args.GetIsolate(),
|
|
|
|
"function f() {"
|
|
|
|
" try {"
|
|
|
|
" while(true) {"
|
|
|
|
" terminate_or_return_object().x;"
|
|
|
|
" }"
|
|
|
|
" fail();"
|
|
|
|
" } catch(e) {"
|
|
|
|
" fail();"
|
|
|
|
" }"
|
|
|
|
"}"
|
|
|
|
"f()"))->Run();
|
2009-09-01 13:55:45 +00:00
|
|
|
CHECK(try_catch.HasCaught());
|
|
|
|
CHECK(try_catch.Exception()->IsNull());
|
|
|
|
CHECK(try_catch.Message().IsEmpty());
|
|
|
|
CHECK(!try_catch.CanContinue());
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
2009-09-01 13:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test that we correctly handle termination exceptions if they are
|
|
|
|
// triggered by the creation of error objects in connection with ICs.
|
2013-09-20 10:52:20 +00:00
|
|
|
TEST(TerminateLoadICException) {
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2009-09-01 13:55:45 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
|
2013-11-22 12:43:17 +00:00
|
|
|
global->Set(
|
|
|
|
v8::String::NewFromUtf8(CcTest::isolate(), "terminate_or_return_object"),
|
|
|
|
v8::FunctionTemplate::New(TerminateOrReturnObject));
|
|
|
|
global->Set(v8::String::NewFromUtf8(CcTest::isolate(), "fail"),
|
|
|
|
v8::FunctionTemplate::New(Fail));
|
|
|
|
global->Set(v8::String::NewFromUtf8(CcTest::isolate(), "loop"),
|
2009-09-01 13:55:45 +00:00
|
|
|
v8::FunctionTemplate::New(LoopGetProperty));
|
|
|
|
|
2013-05-02 20:18:42 +00:00
|
|
|
v8::Handle<v8::Context> context =
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Context::New(CcTest::isolate(), NULL, global);
|
2009-09-01 13:55:45 +00:00
|
|
|
v8::Context::Scope context_scope(context);
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
2009-09-01 13:55:45 +00:00
|
|
|
// Run a loop that will be infinite if thread termination does not work.
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Handle<v8::String> source = v8::String::NewFromUtf8(
|
|
|
|
CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }");
|
2009-09-01 13:55:45 +00:00
|
|
|
call_count = 0;
|
|
|
|
v8::Script::Compile(source)->Run();
|
|
|
|
// Test that we can run the code again after thread termination.
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
2009-09-01 13:55:45 +00:00
|
|
|
call_count = 0;
|
|
|
|
v8::Script::Compile(source)->Run();
|
|
|
|
}
|
2010-05-21 20:52:19 +00:00
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2013-06-20 12:28:27 +00:00
|
|
|
void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2010-05-21 20:52:19 +00:00
|
|
|
v8::TryCatch try_catch;
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
2013-11-22 12:43:17 +00:00
|
|
|
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();
|
2010-05-21 20:52:19 +00:00
|
|
|
CHECK(try_catch.HasCaught());
|
|
|
|
CHECK(try_catch.Exception()->IsNull());
|
|
|
|
CHECK(try_catch.Message().IsEmpty());
|
|
|
|
CHECK(!try_catch.CanContinue());
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(),
|
|
|
|
"function f() { fail(); } f()"))
|
|
|
|
->Run();
|
2010-05-21 20:52:19 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2010-05-21 20:52:19 +00:00
|
|
|
// Test that reentry into V8 while the termination exception is still pending
|
|
|
|
// (has not yet unwound the 0-level JS frame) does not crash.
|
|
|
|
TEST(TerminateAndReenterFromThreadItself) {
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(
|
|
|
|
CcTest::isolate(), TerminateCurrentThread, ReenterAfterTermination);
|
2013-05-02 20:18:42 +00:00
|
|
|
v8::Handle<v8::Context> context =
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Context::New(CcTest::isolate(), NULL, global);
|
2010-05-21 20:52:19 +00:00
|
|
|
v8::Context::Scope context_scope(context);
|
|
|
|
CHECK(!v8::V8::IsExecutionTerminating());
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Handle<v8::String> source = v8::String::NewFromUtf8(
|
|
|
|
CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }");
|
2010-05-21 20:52:19 +00:00
|
|
|
v8::Script::Compile(source)->Run();
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
2010-05-21 20:52:19 +00:00
|
|
|
// Check we can run JS again after termination.
|
2013-11-22 12:43:17 +00:00
|
|
|
CHECK(v8::Script::Compile(
|
|
|
|
v8::String::NewFromUtf8(CcTest::isolate(),
|
|
|
|
"function f() { return true; }"
|
|
|
|
"f()"))
|
|
|
|
->Run()
|
|
|
|
->IsTrue());
|
2010-05-21 20:52:19 +00:00
|
|
|
}
|
2013-04-22 15:01:45 +00:00
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2013-06-20 12:28:27 +00:00
|
|
|
void DoLoopCancelTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2013-04-22 15:01:45 +00:00
|
|
|
v8::TryCatch try_catch;
|
|
|
|
CHECK(!v8::V8::IsExecutionTerminating());
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(),
|
|
|
|
"var term = true;"
|
|
|
|
"while(true) {"
|
|
|
|
" if (term) terminate();"
|
|
|
|
" term = false;"
|
|
|
|
"}"
|
|
|
|
"fail();"))->Run();
|
2013-04-22 15:01:45 +00:00
|
|
|
CHECK(try_catch.HasCaught());
|
|
|
|
CHECK(try_catch.Exception()->IsNull());
|
|
|
|
CHECK(try_catch.Message().IsEmpty());
|
|
|
|
CHECK(!try_catch.CanContinue());
|
|
|
|
CHECK(v8::V8::IsExecutionTerminating());
|
|
|
|
CHECK(try_catch.HasTerminated());
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::V8::CancelTerminateExecution(CcTest::isolate());
|
2013-04-22 15:01:45 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating());
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2013-04-22 15:01:45 +00:00
|
|
|
// Test that a single thread of JavaScript execution can terminate
|
|
|
|
// itself and then resume execution.
|
|
|
|
TEST(TerminateCancelTerminateFromThreadItself) {
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2013-09-10 06:43:23 +00:00
|
|
|
v8::HandleScope scope(isolate);
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate(
|
|
|
|
isolate, TerminateCurrentThread, DoLoopCancelTerminate);
|
2013-09-10 06:43:23 +00:00
|
|
|
v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global);
|
2013-04-22 15:01:45 +00:00
|
|
|
v8::Context::Scope context_scope(context);
|
2013-09-20 10:52:20 +00:00
|
|
|
CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
|
2013-11-22 12:43:17 +00:00
|
|
|
v8::Handle<v8::String> source = v8::String::NewFromUtf8(
|
|
|
|
isolate, "try { doloop(); } catch(e) { fail(); } 'completed';");
|
2013-04-22 15:01:45 +00:00
|
|
|
// Check that execution completed with correct return value.
|
|
|
|
CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed")));
|
|
|
|
}
|