Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Unified Diff: test/inspector/task-runner.cc

Issue 2737603006: [inspector] added createContextGroup for tests (Closed)
Patch Set: a Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/inspector/task-runner.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/inspector/task-runner.cc
diff --git a/test/inspector/task-runner.cc b/test/inspector/task-runner.cc
index 4bfd784900b4e56efc51c2e54896c2c4f87cf003..2f2f45d19cec6cd8b094e124508f5d8aec0455ff 100644
--- a/test/inspector/task-runner.cc
+++ b/test/inspector/task-runner.cc
@@ -13,6 +13,7 @@
namespace {
const int kTaskRunnerIndex = 2;
+const int kContextGroupIdIndex = 3;
void ReportUncaughtException(v8::Isolate* isolate,
const v8::TryCatch& try_catch) {
@@ -46,7 +47,7 @@ TaskRunner::TaskRunner(v8::ExtensionConfiguration* extensions,
TaskRunner::~TaskRunner() { Join(); }
-void TaskRunner::InitializeContext() {
+void TaskRunner::InitializeIsolate() {
v8::Isolate::CreateParams params;
params.array_buffer_allocator =
v8::ArrayBuffer::Allocator::NewDefaultAllocator();
@@ -54,19 +55,36 @@ void TaskRunner::InitializeContext() {
isolate_->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
v8::Isolate::Scope isolate_scope(isolate_);
v8::HandleScope handle_scope(isolate_);
+ NewContextGroup();
+ if (ready_semaphore_) ready_semaphore_->Signal();
+}
+v8::Local<v8::Context> TaskRunner::NewContextGroup() {
v8::Local<v8::ObjectTemplate> global_template =
v8::ObjectTemplate::New(isolate_);
v8::Local<v8::Context> context =
v8::Context::New(isolate_, extensions_, global_template);
context->SetAlignedPointerInEmbedderData(kTaskRunnerIndex, this);
- context_.Reset(isolate_, context);
+ intptr_t context_group_id = ++last_context_group_id_;
+ // Should be 2-byte aligned.
+ context->SetAlignedPointerInEmbedderData(
+ kContextGroupIdIndex, reinterpret_cast<void*>(context_group_id * 2));
+ contexts_[context_group_id].Reset(isolate_, context);
+ return context;
+}
- if (ready_semaphore_) ready_semaphore_->Signal();
+v8::Local<v8::Context> TaskRunner::GetContext(int context_group_id) {
+ return contexts_[context_group_id].Get(isolate_);
+}
+
+int TaskRunner::GetContextGroupId(v8::Local<v8::Context> context) {
+ return reinterpret_cast<intptr_t>(
+ context->GetAlignedPointerFromEmbedderData(kContextGroupIdIndex)) /
+ 2;
}
void TaskRunner::Run() {
- InitializeContext();
+ InitializeIsolate();
RunMessageLoop(false);
}
@@ -78,7 +96,7 @@ void TaskRunner::RunMessageLoop(bool only_protocol) {
v8::Isolate::Scope isolate_scope(isolate_);
if (catch_exceptions_) {
v8::TryCatch try_catch(isolate_);
- task->Run(isolate_, context_);
+ task->Run(isolate_, contexts_.begin()->second);
delete task;
if (try_catch.HasCaught()) {
ReportUncaughtException(isolate_, try_catch);
@@ -87,7 +105,7 @@ void TaskRunner::RunMessageLoop(bool only_protocol) {
_exit(0);
}
} else {
- task->Run(isolate_, context_);
+ task->Run(isolate_, contexts_.begin()->second);
delete task;
}
}
« no previous file with comments | « test/inspector/task-runner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698