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

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

Issue 2832723004: [test/inspector] remove any usage of v8::Extension (Closed)
Patch Set: ac Created 3 years, 8 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/inspector-impl.cc ('k') | test/inspector/runtime/evaluate-with-generate-preview.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/inspector/inspector-test.cc
diff --git a/test/inspector/inspector-test.cc b/test/inspector/inspector-test.cc
index a935717c9e6a49c416e45d3f9b58b70c2f6f4f41..0d19b8d82d2f14a78fa61a31d0c4eb1bc0eb964e 100644
--- a/test/inspector/inspector-test.cc
+++ b/test/inspector/inspector-test.cc
@@ -51,15 +51,11 @@ v8::Local<v8::String> ToV8String(v8::Isolate* isolate, const char* str) {
.ToLocalChecked();
}
-class UtilsExtension : public TaskRunner::Task {
+class UtilsExtension : public TaskRunner::SetupGlobalTask {
public:
~UtilsExtension() override = default;
- bool is_inspector_task() override { return true; }
void Run(v8::Isolate* isolate,
- const v8::Global<v8::Context>& context) override {
- v8::HandleScope handle_scope(isolate);
- v8::Local<v8::Context> local_context = context.Get(isolate);
- v8::Context::Scope context_scope(local_context);
+ v8::Local<v8::ObjectTemplate> global) override {
v8::Local<v8::ObjectTemplate> utils = v8::ObjectTemplate::New(isolate);
utils->Set(ToV8String(isolate, "print"),
v8::FunctionTemplate::New(isolate, &UtilsExtension::Print));
@@ -94,10 +90,7 @@ class UtilsExtension : public TaskRunner::Task {
utils->Set(ToV8String(isolate, "createContextGroup"),
v8::FunctionTemplate::New(isolate,
&UtilsExtension::CreateContextGroup));
- local_context->Global()
- ->Set(local_context, ToV8String(isolate, "utils"),
- utils->NewInstance(local_context).ToLocalChecked())
- .ToChecked();
+ global->Set(ToV8String(isolate, "utils"), utils);
}
static void set_backend_task_runner(TaskRunner* runner) {
@@ -282,23 +275,7 @@ class UtilsExtension : public TaskRunner::Task {
}
static void CreateContextGroup(
- const v8::FunctionCallbackInfo<v8::Value>& args) {
- if (args.Length() != 0) {
- fprintf(stderr, "Internal error: createContextGroup().");
- Exit();
- }
- const char* backend_extensions[] = {"v8_inspector/setTimeout",
- "v8_inspector/inspector"};
- v8::ExtensionConfiguration backend_configuration(
- arraysize(backend_extensions), backend_extensions);
- v8::base::Semaphore ready_semaphore(0);
- int context_group_id = 0;
- inspector_client_->scheduleCreateContextGroup(
- &backend_configuration, &ready_semaphore, &context_group_id);
- ready_semaphore.Wait();
- args.GetReturnValue().Set(
- v8::Int32::New(args.GetIsolate(), context_group_id));
- }
+ const v8::FunctionCallbackInfo<v8::Value>& args);
};
TaskRunner* UtilsExtension::backend_runner_ = nullptr;
@@ -330,15 +307,13 @@ class SetTimeoutTask : public AsyncTask {
v8::Global<v8::Function> function_;
};
-class SetTimeoutExtension : public v8::Extension {
+class SetTimeoutExtension : public TaskRunner::SetupGlobalTask {
public:
- SetTimeoutExtension()
- : v8::Extension("v8_inspector/setTimeout",
- "native function setTimeout();") {}
-
- virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
- v8::Isolate* isolate, v8::Local<v8::String> name) {
- return v8::FunctionTemplate::New(isolate, SetTimeoutExtension::SetTimeout);
+ void Run(v8::Isolate* isolate,
+ v8::Local<v8::ObjectTemplate> global) override {
+ global->Set(
+ ToV8String(isolate, "setTimeout"),
+ v8::FunctionTemplate::New(isolate, &SetTimeoutExtension::SetTimeout));
}
private:
@@ -376,79 +351,39 @@ bool StrictAccessCheck(v8::Local<v8::Context> accessing_context,
return accessing_context.IsEmpty();
}
-class InspectorExtension : public v8::Extension {
+class InspectorExtension : public TaskRunner::SetupGlobalTask {
public:
- InspectorExtension()
- : v8::Extension("v8_inspector/inspector",
- "native function attachInspector();"
- "native function detachInspector();"
- "native function setMaxAsyncTaskStacks();"
- "native function dumpAsyncTaskStacksStateForTest();"
- "native function breakProgram();"
- "native function createObjectWithStrictCheck();"
- "native function callWithScheduledBreak();"
- "native function allowAccessorFormatting();") {}
-
- virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
- v8::Isolate* isolate, v8::Local<v8::String> name) {
- v8::Local<v8::Context> context = isolate->GetCurrentContext();
- if (name->Equals(context,
- v8::String::NewFromUtf8(isolate, "attachInspector",
- v8::NewStringType::kNormal)
- .ToLocalChecked())
- .FromJust()) {
- return v8::FunctionTemplate::New(isolate, InspectorExtension::Attach);
- } else if (name->Equals(context,
- v8::String::NewFromUtf8(isolate, "detachInspector",
- v8::NewStringType::kNormal)
- .ToLocalChecked())
- .FromJust()) {
- return v8::FunctionTemplate::New(isolate, InspectorExtension::Detach);
- } else if (name->Equals(context, v8::String::NewFromUtf8(
- isolate, "setMaxAsyncTaskStacks",
- v8::NewStringType::kNormal)
- .ToLocalChecked())
- .FromJust()) {
- return v8::FunctionTemplate::New(
- isolate, InspectorExtension::SetMaxAsyncTaskStacks);
- } else if (name->Equals(context,
- v8::String::NewFromUtf8(
- isolate, "dumpAsyncTaskStacksStateForTest",
- v8::NewStringType::kNormal)
- .ToLocalChecked())
- .FromJust()) {
- return v8::FunctionTemplate::New(
- isolate, InspectorExtension::DumpAsyncTaskStacksStateForTest);
- } else if (name->Equals(context,
- v8::String::NewFromUtf8(isolate, "breakProgram",
- v8::NewStringType::kNormal)
- .ToLocalChecked())
- .FromJust()) {
- return v8::FunctionTemplate::New(isolate,
- InspectorExtension::BreakProgram);
- } else if (name->Equals(context, v8::String::NewFromUtf8(
- isolate, "createObjectWithStrictCheck",
- v8::NewStringType::kNormal)
- .ToLocalChecked())
- .FromJust()) {
- return v8::FunctionTemplate::New(
- isolate, InspectorExtension::CreateObjectWithStrictCheck);
- } else if (name->Equals(context, v8::String::NewFromUtf8(
- isolate, "callWithScheduledBreak",
- v8::NewStringType::kNormal)
- .ToLocalChecked())
- .FromJust()) {
- return v8::FunctionTemplate::New(
- isolate, InspectorExtension::CallWithScheduledBreak);
- } else if (name->Equals(context, v8::String::NewFromUtf8(
- isolate, "allowAccessorFormatting",
- v8::NewStringType::kNormal)
- .ToLocalChecked())
- .FromJust()) {
- return v8::FunctionTemplate::New(
- isolate, InspectorExtension::AllowAccessorFormatting);
- }
- return v8::Local<v8::FunctionTemplate>();
+ ~InspectorExtension() override = default;
+ void Run(v8::Isolate* isolate,
+ v8::Local<v8::ObjectTemplate> global) override {
+ v8::Local<v8::ObjectTemplate> inspector = v8::ObjectTemplate::New(isolate);
+ inspector->Set(
+ ToV8String(isolate, "attachInspector"),
+ v8::FunctionTemplate::New(isolate, &InspectorExtension::Attach));
+ inspector->Set(
+ ToV8String(isolate, "detachInspector"),
+ v8::FunctionTemplate::New(isolate, &InspectorExtension::Detach));
+ inspector->Set(ToV8String(isolate, "setMaxAsyncTaskStacks"),
+ v8::FunctionTemplate::New(
+ isolate, &InspectorExtension::SetMaxAsyncTaskStacks));
+ inspector->Set(
+ ToV8String(isolate, "dumpAsyncTaskStacksStateForTest"),
+ v8::FunctionTemplate::New(
+ isolate, &InspectorExtension::DumpAsyncTaskStacksStateForTest));
+ inspector->Set(
+ ToV8String(isolate, "breakProgram"),
+ v8::FunctionTemplate::New(isolate, &InspectorExtension::BreakProgram));
+ inspector->Set(
+ ToV8String(isolate, "createObjectWithStrictCheck"),
+ v8::FunctionTemplate::New(
+ isolate, &InspectorExtension::CreateObjectWithStrictCheck));
+ inspector->Set(ToV8String(isolate, "callWithScheduledBreak"),
+ v8::FunctionTemplate::New(
+ isolate, &InspectorExtension::CallWithScheduledBreak));
+ inspector->Set(ToV8String(isolate, "allowAccessorFormatting"),
+ v8::FunctionTemplate::New(
+ isolate, &InspectorExtension::AllowAccessorFormatting));
+ global->Set(ToV8String(isolate, "inspector"), inspector);
}
private:
@@ -578,6 +513,24 @@ class InspectorExtension : public v8::Extension {
}
};
+void UtilsExtension::CreateContextGroup(
dgozman 2017/04/21 23:10:44 Inline this back into place.
kozy 2017/04/21 23:16:54 It uses SetTimeoutExtension and InspectorExtension
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ if (args.Length() != 0) {
+ fprintf(stderr, "Internal error: createContextGroup().");
+ Exit();
+ }
+ v8::base::Semaphore ready_semaphore(0);
+ int context_group_id = 0;
+ TaskRunner::SetupGlobalTasks setup_global;
+ setup_global.emplace_back(new SetTimeoutExtension());
+ setup_global.emplace_back(new InspectorExtension());
+ inspector_client_->scheduleCreateContextGroup(
+ std::move(setup_global), &ready_semaphore, &context_group_id);
+ ready_semaphore.Wait();
+ args.GetReturnValue().Set(
+ v8::Int32::New(args.GetIsolate(), context_group_id));
+}
+
v8::Local<v8::String> ToString(v8::Isolate* isolate,
const v8_inspector::StringView& string) {
if (string.is8Bit())
@@ -634,30 +587,23 @@ int main(int argc, char* argv[]) {
v8::V8::InitializeExternalStartupData(argv[0]);
v8::V8::Initialize();
- SetTimeoutExtension set_timeout_extension;
- v8::RegisterExtension(&set_timeout_extension);
- InspectorExtension inspector_extension;
- v8::RegisterExtension(&inspector_extension);
- SendMessageToBackendExtension send_message_to_backend_extension;
- v8::RegisterExtension(&send_message_to_backend_extension);
-
v8::base::Semaphore ready_semaphore(0);
- const char* backend_extensions[] = {"v8_inspector/setTimeout",
- "v8_inspector/inspector"};
- v8::ExtensionConfiguration backend_configuration(
- arraysize(backend_extensions), backend_extensions);
- TaskRunner backend_runner(&backend_configuration, false, &ready_semaphore);
+ TaskRunner::SetupGlobalTasks backend_extensions;
+ backend_extensions.emplace_back(new SetTimeoutExtension());
+ backend_extensions.emplace_back(new InspectorExtension());
+ TaskRunner backend_runner(std::move(backend_extensions), false,
+ &ready_semaphore);
ready_semaphore.Wait();
SendMessageToBackendExtension::set_backend_task_runner(&backend_runner);
UtilsExtension::set_backend_task_runner(&backend_runner);
- const char* frontend_extensions[] = {"v8_inspector/frontend"};
- v8::ExtensionConfiguration frontend_configuration(
- arraysize(frontend_extensions), frontend_extensions);
- TaskRunner frontend_runner(&frontend_configuration, true, &ready_semaphore);
+ TaskRunner::SetupGlobalTasks frontend_extensions;
+ frontend_extensions.emplace_back(new UtilsExtension());
+ frontend_extensions.emplace_back(new SendMessageToBackendExtension());
+ TaskRunner frontend_runner(std::move(frontend_extensions), true,
+ &ready_semaphore);
ready_semaphore.Wait();
- frontend_runner.Append(new UtilsExtension());
FrontendChannelImpl frontend_channel(&frontend_runner);
InspectorClientImpl inspector_client(&backend_runner, &frontend_channel,
« no previous file with comments | « test/inspector/inspector-impl.cc ('k') | test/inspector/runtime/evaluate-with-generate-preview.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698