Chromium Code Reviews| Index: test/inspector/inspector-test.cc |
| diff --git a/test/inspector/inspector-test.cc b/test/inspector/inspector-test.cc |
| index 54cdd7f4099681c47613a2ee1148f8324cb17450..f118e3ed0a7026950980c370bce659efa577d813 100644 |
| --- a/test/inspector/inspector-test.cc |
| +++ b/test/inspector/inspector-test.cc |
| @@ -212,6 +212,62 @@ class SetTimeoutExtension : public v8::Extension { |
| } |
| }; |
| +class InspectorExtension : public v8::Extension { |
| + public: |
| + InspectorExtension() |
| + : v8::Extension("v8_inspector/inspector", |
| + "native function attachInspector();" |
| + "native function detachInspector();") {} |
| + |
| + 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); |
| + } |
| + return v8::Local<v8::FunctionTemplate>(); |
| + } |
| + |
| + private: |
| + static void Attach(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| + v8::Isolate* isolate = args.GetIsolate(); |
| + v8::Local<v8::Context> context = isolate->GetEnteredContext(); |
|
kozy
2016/10/21 15:06:53
GetCurrentContext()
robwu
2016/10/21 20:32:45
Done.
|
| + v8_inspector::V8Inspector* inspector = |
| + InspectorClientImpl::InspectorFromContext(context); |
| + if (!inspector) { |
| + fprintf(stderr, "Inspector client not found - cannot attach!"); |
| + Exit(); |
| + } |
| + fprintf(stdout, "Attaching context.\n"); |
| + inspector->contextDestroyed(context); |
|
kozy
2016/10/21 15:06:53
Do you really need this call? Otherwise it looks l
robwu
2016/10/21 20:32:45
Oops. Removed.
|
| + inspector->contextCreated( |
| + v8_inspector::V8ContextInfo(context, 1, v8_inspector::StringView())); |
| + } |
| + |
| + static void Detach(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| + v8::Isolate* isolate = args.GetIsolate(); |
| + v8::Local<v8::Context> context = isolate->GetEnteredContext(); |
| + v8_inspector::V8Inspector* inspector = |
| + InspectorClientImpl::InspectorFromContext(context); |
| + if (!inspector) { |
| + fprintf(stderr, "Inspector client not found - cannot detach!"); |
| + Exit(); |
| + } |
| + fprintf(stdout, "Detaching context.\n"); |
| + inspector->contextDestroyed(context); |
| + } |
| +}; |
| + |
| v8::Local<v8::String> ToString(v8::Isolate* isolate, |
| const v8_inspector::StringView& string) { |
| if (string.is8Bit()) |
| @@ -267,6 +323,8 @@ int main(int argc, char* argv[]) { |
| SetTimeoutExtension set_timeout_extension; |
| v8::RegisterExtension(&set_timeout_extension); |
| + InspectorExtension inspector_extension; |
| + v8::RegisterExtension(&inspector_extension); |
| UtilsExtension utils_extension; |
| v8::RegisterExtension(&utils_extension); |
| SendMessageToBackendExtension send_message_to_backend_extension; |
| @@ -274,7 +332,8 @@ int main(int argc, char* argv[]) { |
| v8::base::Semaphore ready_semaphore(0); |
| - const char* backend_extensions[] = {"v8_inspector/setTimeout"}; |
| + 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); |