Commit d80e1f47 authored by Yang Guo's avatar Yang Guo Committed by Commit Bot

[regexp] add test for termination for long-running regexps.

R=jgruber@chromium.org

Change-Id: I9def56aa65e742f24ecfc25a01b20389e8867dc2
Reviewed-on: https://chromium-review.googlesource.com/931061Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51465}
parent 5da78ea4
...@@ -615,3 +615,42 @@ TEST(TerminateConsole) { ...@@ -615,3 +615,42 @@ TEST(TerminateConsole) {
CHECK(try_catch.HasCaught()); CHECK(try_catch.HasCaught());
CHECK(!isolate->IsExecutionTerminating()); CHECK(!isolate->IsExecutionTerminating());
} }
class TerminatorSleeperThread : public v8::base::Thread {
public:
explicit TerminatorSleeperThread(v8::Isolate* isolate, int sleep_ms)
: Thread(Options("TerminatorSlepperThread")),
isolate_(isolate),
sleep_ms_(sleep_ms) {}
void Run() {
v8::base::OS::Sleep(v8::base::TimeDelta::FromMilliseconds(sleep_ms_));
CHECK(!isolate_->IsExecutionTerminating());
isolate_->TerminateExecution();
}
private:
v8::Isolate* isolate_;
int sleep_ms_;
};
TEST(TerminateRegExp) {
i::FLAG_allow_natives_syntax = true;
v8::Isolate* isolate = CcTest::isolate();
ConsoleImpl console;
v8::debug::SetConsoleDelegate(isolate, &console);
v8::HandleScope scope(isolate);
v8::Local<v8::ObjectTemplate> global = CreateGlobalTemplate(
isolate, TerminateCurrentThread, DoLoopCancelTerminate);
v8::Local<v8::Context> context = v8::Context::New(isolate, nullptr, global);
v8::Context::Scope context_scope(context);
CHECK(!isolate->IsExecutionTerminating());
v8::TryCatch try_catch(isolate);
CHECK(!isolate->IsExecutionTerminating());
CHECK(!CompileRun("var re = /(x+)+y$/; re.test('x');").IsEmpty());
TerminatorSleeperThread terminator(isolate, 100);
terminator.Start();
CHECK(CompileRun("re.test('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); fail();")
.IsEmpty());
CHECK(try_catch.HasCaught());
CHECK(!isolate->IsExecutionTerminating());
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment