[regexp] add test for termination for long-running regexps.
R=jgruber@chromium.org Change-Id: I9def56aa65e742f24ecfc25a01b20389e8867dc2 Reviewed-on: https://chromium-review.googlesource.com/931061 Reviewed-by: Yang Guo <yangguo@chromium.org> Reviewed-by: Jakob Gruber <jgruber@chromium.org> Commit-Queue: Yang Guo <yangguo@chromium.org> Cr-Commit-Position: refs/heads/master@{#51465}
This commit is contained in:
parent
5da78ea40b
commit
d80e1f47ed
@ -615,3 +615,42 @@ TEST(TerminateConsole) {
|
||||
CHECK(try_catch.HasCaught());
|
||||
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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user