2016-10-02 16:45:33 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_
|
|
|
|
#define V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_
|
|
|
|
|
|
|
|
#include "include/v8-inspector.h"
|
|
|
|
#include "include/v8.h"
|
|
|
|
#include "src/base/macros.h"
|
|
|
|
#include "src/base/platform/platform.h"
|
|
|
|
#include "test/inspector/task-runner.h"
|
|
|
|
|
|
|
|
class InspectorClientImpl : public v8_inspector::V8InspectorClient {
|
|
|
|
public:
|
|
|
|
class FrontendChannel {
|
|
|
|
public:
|
|
|
|
virtual ~FrontendChannel() = default;
|
|
|
|
virtual void SendMessageToFrontend(
|
|
|
|
const v8_inspector::StringView& message) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
InspectorClientImpl(TaskRunner* task_runner,
|
|
|
|
FrontendChannel* frontend_channel,
|
|
|
|
v8::base::Semaphore* ready_semaphore);
|
|
|
|
virtual ~InspectorClientImpl();
|
|
|
|
|
2017-02-28 20:22:24 +00:00
|
|
|
void scheduleReconnect(v8::base::Semaphore* ready_semaphore);
|
2017-03-07 22:30:05 +00:00
|
|
|
void scheduleCreateContextGroup(v8::ExtensionConfiguration* extensions,
|
|
|
|
v8::base::Semaphore* ready_semaphore,
|
|
|
|
int* context_group_id);
|
2017-02-28 20:22:24 +00:00
|
|
|
|
2016-10-02 18:10:27 +00:00
|
|
|
static v8_inspector::V8Inspector* InspectorFromContext(
|
|
|
|
v8::Local<v8::Context> context);
|
2017-01-18 16:57:00 +00:00
|
|
|
static v8_inspector::V8InspectorSession* SessionFromContext(
|
|
|
|
v8::Local<v8::Context> context);
|
2016-10-02 18:10:27 +00:00
|
|
|
|
2017-03-07 22:30:05 +00:00
|
|
|
// context_group_id = 0 means default context group.
|
|
|
|
v8_inspector::V8InspectorSession* session(int context_group_id = 0);
|
2017-01-17 20:21:38 +00:00
|
|
|
|
2017-03-07 22:30:05 +00:00
|
|
|
void setCurrentTimeMSForTest(double time);
|
2017-01-18 16:57:00 +00:00
|
|
|
|
2016-10-02 16:45:33 +00:00
|
|
|
private:
|
|
|
|
// V8InspectorClient implementation.
|
2017-03-03 19:30:40 +00:00
|
|
|
bool formatAccessorsAsProperties(v8::Local<v8::Value>) override;
|
2016-10-02 16:45:33 +00:00
|
|
|
v8::Local<v8::Context> ensureDefaultContextInGroup(
|
|
|
|
int context_group_id) override;
|
|
|
|
double currentTimeMS() override;
|
|
|
|
void runMessageLoopOnPause(int context_group_id) override;
|
|
|
|
void quitMessageLoopOnPause() override;
|
|
|
|
|
|
|
|
friend class SendMessageToBackendTask;
|
|
|
|
|
|
|
|
friend class ConnectTask;
|
|
|
|
void connect(v8::Local<v8::Context> context);
|
2017-02-28 20:22:24 +00:00
|
|
|
friend class DisconnectTask;
|
|
|
|
void disconnect();
|
2017-03-07 22:30:05 +00:00
|
|
|
friend class CreateContextGroupTask;
|
|
|
|
int createContextGroup(v8::ExtensionConfiguration* extensions);
|
2016-10-02 16:45:33 +00:00
|
|
|
|
|
|
|
std::unique_ptr<v8_inspector::V8Inspector> inspector_;
|
|
|
|
std::unique_ptr<v8_inspector::V8Inspector::Channel> channel_;
|
2017-03-07 22:30:05 +00:00
|
|
|
|
|
|
|
std::map<int, std::unique_ptr<v8_inspector::V8InspectorSession>> sessions_;
|
|
|
|
std::map<int, std::unique_ptr<v8_inspector::StringBuffer>> states_;
|
2016-10-02 16:45:33 +00:00
|
|
|
|
|
|
|
v8::Isolate* isolate_;
|
|
|
|
|
|
|
|
TaskRunner* task_runner_;
|
|
|
|
FrontendChannel* frontend_channel_;
|
|
|
|
|
2017-01-17 20:21:38 +00:00
|
|
|
bool current_time_set_for_test_ = false;
|
|
|
|
double current_time_ = 0.0;
|
|
|
|
|
2016-10-02 16:45:33 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(InspectorClientImpl);
|
|
|
|
};
|
|
|
|
|
|
|
|
class SendMessageToBackendExtension : public v8::Extension {
|
|
|
|
public:
|
|
|
|
SendMessageToBackendExtension()
|
|
|
|
: v8::Extension("v8_inspector/frontend",
|
|
|
|
"native function sendMessageToBackend();") {}
|
|
|
|
virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
|
|
|
|
v8::Isolate* isolate, v8::Local<v8::String> name);
|
|
|
|
|
|
|
|
static void set_backend_task_runner(TaskRunner* task_runner) {
|
|
|
|
backend_task_runner_ = task_runner;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void SendMessageToBackend(
|
|
|
|
const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
|
|
|
|
static TaskRunner* backend_task_runner_;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // V8_TEST_INSPECTOR_PROTOCOL_INSPECTOR_IMPL_H_
|