2017-05-17 00:30:52 +00:00
|
|
|
// Copyright 2017 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.
|
|
|
|
|
|
|
|
#include "test/inspector/isolate-data.h"
|
|
|
|
|
2017-05-22 20:46:42 +00:00
|
|
|
#include "src/inspector/test-interface.h"
|
2017-05-17 00:30:52 +00:00
|
|
|
#include "test/inspector/task-runner.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
const int kIsolateDataIndex = 2;
|
2017-05-18 23:11:20 +00:00
|
|
|
const int kContextGroupIdIndex = 3;
|
2017-05-17 00:30:52 +00:00
|
|
|
|
2018-07-23 02:35:30 +00:00
|
|
|
v8::internal::Vector<uint16_t> ToVector(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::String> str) {
|
2017-05-17 00:30:52 +00:00
|
|
|
v8::internal::Vector<uint16_t> buffer =
|
|
|
|
v8::internal::Vector<uint16_t>::New(str->Length());
|
2018-07-23 02:35:30 +00:00
|
|
|
str->Write(isolate, buffer.start(), 0, str->Length());
|
2017-05-17 00:30:52 +00:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2017-05-22 00:48:27 +00:00
|
|
|
v8::Local<v8::String> ToString(v8::Isolate* isolate,
|
|
|
|
const v8_inspector::StringView& string) {
|
|
|
|
if (string.is8Bit())
|
|
|
|
return v8::String::NewFromOneByte(isolate, string.characters8(),
|
|
|
|
v8::NewStringType::kNormal,
|
|
|
|
static_cast<int>(string.length()))
|
|
|
|
.ToLocalChecked();
|
|
|
|
else
|
|
|
|
return v8::String::NewFromTwoByte(isolate, string.characters16(),
|
|
|
|
v8::NewStringType::kNormal,
|
|
|
|
static_cast<int>(string.length()))
|
|
|
|
.ToLocalChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Print(v8::Isolate* isolate, const v8_inspector::StringView& string) {
|
|
|
|
v8::Local<v8::String> v8_string = ToString(isolate, string);
|
2017-08-24 21:49:48 +00:00
|
|
|
v8::String::Utf8Value utf8_string(isolate, v8_string);
|
2017-05-22 00:48:27 +00:00
|
|
|
fwrite(*utf8_string, sizeof(**utf8_string), utf8_string.length(), stdout);
|
|
|
|
}
|
|
|
|
|
2017-06-05 17:37:25 +00:00
|
|
|
class Inspectable : public v8_inspector::V8InspectorSession::Inspectable {
|
|
|
|
public:
|
|
|
|
Inspectable(v8::Isolate* isolate, v8::Local<v8::Value> object)
|
|
|
|
: object_(isolate, object) {}
|
|
|
|
~Inspectable() override {}
|
|
|
|
v8::Local<v8::Value> get(v8::Local<v8::Context> context) override {
|
|
|
|
return object_.Get(context->GetIsolate());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
v8::Global<v8::Value> object_;
|
|
|
|
};
|
|
|
|
|
2017-05-17 00:30:52 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
IsolateData::IsolateData(TaskRunner* task_runner,
|
|
|
|
IsolateData::SetupGlobalTasks setup_global_tasks,
|
2017-05-22 20:46:42 +00:00
|
|
|
v8::StartupData* startup_data, bool with_inspector)
|
2017-05-17 00:30:52 +00:00
|
|
|
: task_runner_(task_runner),
|
2017-05-22 20:46:42 +00:00
|
|
|
setup_global_tasks_(std::move(setup_global_tasks)) {
|
2017-05-17 00:30:52 +00:00
|
|
|
v8::Isolate::CreateParams params;
|
|
|
|
params.array_buffer_allocator =
|
|
|
|
v8::ArrayBuffer::Allocator::NewDefaultAllocator();
|
|
|
|
params.snapshot_blob = startup_data;
|
2018-05-08 13:44:36 +00:00
|
|
|
params.only_terminate_in_safe_scope = true;
|
2017-11-16 15:29:57 +00:00
|
|
|
isolate_.reset(v8::Isolate::New(params));
|
2017-05-17 00:30:52 +00:00
|
|
|
isolate_->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
|
2017-05-22 20:46:42 +00:00
|
|
|
if (with_inspector) {
|
2017-05-22 00:48:27 +00:00
|
|
|
isolate_->AddMessageListener(&IsolateData::MessageHandler);
|
2017-06-01 21:33:59 +00:00
|
|
|
isolate_->SetPromiseRejectCallback(&IsolateData::PromiseRejectHandler);
|
2017-11-16 15:29:57 +00:00
|
|
|
inspector_ = v8_inspector::V8Inspector::create(isolate_.get(), this);
|
2017-05-22 00:48:27 +00:00
|
|
|
}
|
2017-11-16 15:29:57 +00:00
|
|
|
v8::HandleScope handle_scope(isolate_.get());
|
2017-08-23 19:40:46 +00:00
|
|
|
not_inspectable_private_.Reset(
|
2017-11-16 15:29:57 +00:00
|
|
|
isolate_.get(),
|
|
|
|
v8::Private::ForApi(isolate_.get(), v8::String::NewFromUtf8(
|
|
|
|
isolate_.get(), "notInspectable",
|
|
|
|
v8::NewStringType::kNormal)
|
|
|
|
.ToLocalChecked()));
|
2017-05-17 00:30:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IsolateData* IsolateData::FromContext(v8::Local<v8::Context> context) {
|
|
|
|
return static_cast<IsolateData*>(
|
|
|
|
context->GetAlignedPointerFromEmbedderData(kIsolateDataIndex));
|
|
|
|
}
|
|
|
|
|
|
|
|
int IsolateData::CreateContextGroup() {
|
2017-11-16 15:29:57 +00:00
|
|
|
v8::HandleScope handle_scope(isolate_.get());
|
2017-05-17 00:30:52 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> global_template =
|
2017-11-16 15:29:57 +00:00
|
|
|
v8::ObjectTemplate::New(isolate_.get());
|
2017-05-17 00:30:52 +00:00
|
|
|
for (auto it = setup_global_tasks_.begin(); it != setup_global_tasks_.end();
|
|
|
|
++it) {
|
2017-11-16 15:29:57 +00:00
|
|
|
(*it)->Run(isolate_.get(), global_template);
|
2017-05-17 00:30:52 +00:00
|
|
|
}
|
|
|
|
v8::Local<v8::Context> context =
|
2017-11-16 15:29:57 +00:00
|
|
|
v8::Context::New(isolate_.get(), nullptr, global_template);
|
2017-05-17 00:30:52 +00:00
|
|
|
context->SetAlignedPointerInEmbedderData(kIsolateDataIndex, this);
|
|
|
|
int context_group_id = ++last_context_group_id_;
|
2017-05-18 23:11:20 +00:00
|
|
|
// Should be 2-byte aligned.
|
|
|
|
context->SetAlignedPointerInEmbedderData(
|
|
|
|
kContextGroupIdIndex, reinterpret_cast<void*>(context_group_id * 2));
|
2017-11-16 15:29:57 +00:00
|
|
|
contexts_[context_group_id].Reset(isolate_.get(), context);
|
2017-05-22 00:48:27 +00:00
|
|
|
if (inspector_) FireContextCreated(context, context_group_id);
|
2017-05-17 00:30:52 +00:00
|
|
|
return context_group_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Context> IsolateData::GetContext(int context_group_id) {
|
2017-11-16 15:29:57 +00:00
|
|
|
return contexts_[context_group_id].Get(isolate_.get());
|
2017-05-17 00:30:52 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 23:11:20 +00:00
|
|
|
int IsolateData::GetContextGroupId(v8::Local<v8::Context> context) {
|
|
|
|
return static_cast<int>(
|
|
|
|
reinterpret_cast<intptr_t>(
|
|
|
|
context->GetAlignedPointerFromEmbedderData(kContextGroupIdIndex)) /
|
|
|
|
2);
|
|
|
|
}
|
|
|
|
|
2017-05-17 00:30:52 +00:00
|
|
|
void IsolateData::RegisterModule(v8::Local<v8::Context> context,
|
|
|
|
v8::internal::Vector<uint16_t> name,
|
|
|
|
v8::ScriptCompiler::Source* source) {
|
|
|
|
v8::Local<v8::Module> module;
|
|
|
|
if (!v8::ScriptCompiler::CompileModule(isolate(), source).ToLocal(&module))
|
|
|
|
return;
|
2017-05-29 11:57:50 +00:00
|
|
|
if (!module->InstantiateModule(context, &IsolateData::ModuleResolveCallback)
|
|
|
|
.FromMaybe(false)) {
|
2017-05-17 00:30:52 +00:00
|
|
|
return;
|
2017-05-29 11:57:50 +00:00
|
|
|
}
|
2017-05-17 00:30:52 +00:00
|
|
|
v8::Local<v8::Value> result;
|
|
|
|
if (!module->Evaluate(context).ToLocal(&result)) return;
|
2017-11-16 15:29:57 +00:00
|
|
|
modules_[name] = v8::Global<v8::Module>(isolate_.get(), module);
|
2017-05-17 00:30:52 +00:00
|
|
|
}
|
|
|
|
|
2017-05-22 00:48:27 +00:00
|
|
|
// static
|
2017-05-17 00:30:52 +00:00
|
|
|
v8::MaybeLocal<v8::Module> IsolateData::ModuleResolveCallback(
|
|
|
|
v8::Local<v8::Context> context, v8::Local<v8::String> specifier,
|
|
|
|
v8::Local<v8::Module> referrer) {
|
|
|
|
IsolateData* data = IsolateData::FromContext(context);
|
2017-11-16 15:29:57 +00:00
|
|
|
std::string str = *v8::String::Utf8Value(data->isolate(), specifier);
|
2018-07-23 02:35:30 +00:00
|
|
|
return data->modules_[ToVector(data->isolate(), specifier)].Get(
|
|
|
|
data->isolate());
|
2017-05-17 00:30:52 +00:00
|
|
|
}
|
2017-05-22 00:48:27 +00:00
|
|
|
|
|
|
|
int IsolateData::ConnectSession(int context_group_id,
|
2017-05-22 20:46:42 +00:00
|
|
|
const v8_inspector::StringView& state,
|
|
|
|
v8_inspector::V8Inspector::Channel* channel) {
|
2017-05-22 00:48:27 +00:00
|
|
|
int session_id = ++last_session_id_;
|
2017-05-22 20:46:42 +00:00
|
|
|
sessions_[session_id] = inspector_->connect(context_group_id, channel, state);
|
2017-05-22 00:48:27 +00:00
|
|
|
context_group_by_session_[sessions_[session_id].get()] = context_group_id;
|
|
|
|
return session_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<v8_inspector::StringBuffer> IsolateData::DisconnectSession(
|
|
|
|
int session_id) {
|
|
|
|
auto it = sessions_.find(session_id);
|
|
|
|
CHECK(it != sessions_.end());
|
|
|
|
context_group_by_session_.erase(it->second.get());
|
|
|
|
std::unique_ptr<v8_inspector::StringBuffer> result = it->second->stateJSON();
|
|
|
|
sessions_.erase(it);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsolateData::SendMessage(int session_id,
|
|
|
|
const v8_inspector::StringView& message) {
|
|
|
|
auto it = sessions_.find(session_id);
|
|
|
|
if (it != sessions_.end()) it->second->dispatchProtocolMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsolateData::BreakProgram(int context_group_id,
|
|
|
|
const v8_inspector::StringView& reason,
|
|
|
|
const v8_inspector::StringView& details) {
|
|
|
|
for (int session_id : GetSessionIds(context_group_id)) {
|
|
|
|
auto it = sessions_.find(session_id);
|
|
|
|
if (it != sessions_.end()) it->second->breakProgram(reason, details);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsolateData::SchedulePauseOnNextStatement(
|
|
|
|
int context_group_id, const v8_inspector::StringView& reason,
|
|
|
|
const v8_inspector::StringView& details) {
|
|
|
|
for (int session_id : GetSessionIds(context_group_id)) {
|
|
|
|
auto it = sessions_.find(session_id);
|
|
|
|
if (it != sessions_.end())
|
|
|
|
it->second->schedulePauseOnNextStatement(reason, details);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsolateData::CancelPauseOnNextStatement(int context_group_id) {
|
|
|
|
for (int session_id : GetSessionIds(context_group_id)) {
|
|
|
|
auto it = sessions_.find(session_id);
|
|
|
|
if (it != sessions_.end()) it->second->cancelPauseOnNextStatement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-22 20:46:42 +00:00
|
|
|
void IsolateData::AsyncTaskScheduled(const v8_inspector::StringView& name,
|
|
|
|
void* task, bool recurring) {
|
|
|
|
inspector_->asyncTaskScheduled(name, task, recurring);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsolateData::AsyncTaskStarted(void* task) {
|
|
|
|
inspector_->asyncTaskStarted(task);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsolateData::AsyncTaskFinished(void* task) {
|
|
|
|
inspector_->asyncTaskFinished(task);
|
|
|
|
}
|
|
|
|
|
2017-11-22 19:46:33 +00:00
|
|
|
v8_inspector::V8StackTraceId IsolateData::StoreCurrentStackTrace(
|
|
|
|
const v8_inspector::StringView& description) {
|
|
|
|
return inspector_->storeCurrentStackTrace(description);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsolateData::ExternalAsyncTaskStarted(
|
|
|
|
const v8_inspector::V8StackTraceId& parent) {
|
|
|
|
inspector_->externalAsyncTaskStarted(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsolateData::ExternalAsyncTaskFinished(
|
|
|
|
const v8_inspector::V8StackTraceId& parent) {
|
|
|
|
inspector_->externalAsyncTaskFinished(parent);
|
|
|
|
}
|
|
|
|
|
2017-06-05 17:37:25 +00:00
|
|
|
void IsolateData::AddInspectedObject(int session_id,
|
|
|
|
v8::Local<v8::Value> object) {
|
|
|
|
auto it = sessions_.find(session_id);
|
|
|
|
if (it == sessions_.end()) return;
|
2017-11-16 15:29:57 +00:00
|
|
|
std::unique_ptr<Inspectable> inspectable(
|
|
|
|
new Inspectable(isolate_.get(), object));
|
2017-06-05 17:37:25 +00:00
|
|
|
it->second->addInspectedObject(std::move(inspectable));
|
|
|
|
}
|
|
|
|
|
2017-05-22 20:46:42 +00:00
|
|
|
void IsolateData::SetMaxAsyncTaskStacksForTest(int limit) {
|
|
|
|
v8_inspector::SetMaxAsyncTaskStacksForTest(inspector_.get(), limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsolateData::DumpAsyncTaskStacksStateForTest() {
|
|
|
|
v8_inspector::DumpAsyncTaskStacksStateForTest(inspector_.get());
|
|
|
|
}
|
|
|
|
|
2017-05-22 00:48:27 +00:00
|
|
|
// static
|
2017-06-01 21:33:59 +00:00
|
|
|
int IsolateData::HandleMessage(v8::Local<v8::Message> message,
|
|
|
|
v8::Local<v8::Value> exception) {
|
2017-05-22 00:48:27 +00:00
|
|
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
|
|
|
v8::Local<v8::Context> context = isolate->GetEnteredContext();
|
2017-06-01 21:33:59 +00:00
|
|
|
if (context.IsEmpty()) return 0;
|
2017-05-22 00:48:27 +00:00
|
|
|
v8_inspector::V8Inspector* inspector =
|
|
|
|
IsolateData::FromContext(context)->inspector_.get();
|
|
|
|
|
|
|
|
v8::Local<v8::StackTrace> stack = message->GetStackTrace();
|
|
|
|
int script_id =
|
|
|
|
static_cast<int>(message->GetScriptOrigin().ScriptID()->Value());
|
|
|
|
if (!stack.IsEmpty() && stack->GetFrameCount() > 0) {
|
2018-07-25 16:46:08 +00:00
|
|
|
int top_script_id = stack->GetFrame(isolate, 0)->GetScriptId();
|
2017-05-22 00:48:27 +00:00
|
|
|
if (top_script_id == script_id) script_id = 0;
|
|
|
|
}
|
|
|
|
int line_number = message->GetLineNumber(context).FromMaybe(0);
|
|
|
|
int column_number = 0;
|
|
|
|
if (message->GetStartColumn(context).IsJust())
|
|
|
|
column_number = message->GetStartColumn(context).FromJust() + 1;
|
|
|
|
|
|
|
|
v8_inspector::StringView detailed_message;
|
2018-07-23 02:35:30 +00:00
|
|
|
v8::internal::Vector<uint16_t> message_text_string =
|
|
|
|
ToVector(isolate, message->Get());
|
2017-05-22 00:48:27 +00:00
|
|
|
v8_inspector::StringView message_text(message_text_string.start(),
|
|
|
|
message_text_string.length());
|
|
|
|
v8::internal::Vector<uint16_t> url_string;
|
|
|
|
if (message->GetScriptOrigin().ResourceName()->IsString()) {
|
2018-07-23 02:35:30 +00:00
|
|
|
url_string = ToVector(
|
|
|
|
isolate, message->GetScriptOrigin().ResourceName().As<v8::String>());
|
2017-05-22 00:48:27 +00:00
|
|
|
}
|
|
|
|
v8_inspector::StringView url(url_string.start(), url_string.length());
|
|
|
|
|
2017-06-01 21:33:59 +00:00
|
|
|
return inspector->exceptionThrown(
|
|
|
|
context, message_text, exception, detailed_message, url, line_number,
|
|
|
|
column_number, inspector->createStackTrace(stack), script_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void IsolateData::MessageHandler(v8::Local<v8::Message> message,
|
|
|
|
v8::Local<v8::Value> exception) {
|
|
|
|
HandleMessage(message, exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void IsolateData::PromiseRejectHandler(v8::PromiseRejectMessage data) {
|
|
|
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
|
|
|
v8::Local<v8::Context> context = isolate->GetEnteredContext();
|
|
|
|
if (context.IsEmpty()) return;
|
|
|
|
v8::Local<v8::Promise> promise = data.GetPromise();
|
|
|
|
v8::Local<v8::Private> id_private = v8::Private::ForApi(
|
|
|
|
isolate,
|
|
|
|
v8::String::NewFromUtf8(isolate, "id", v8::NewStringType::kNormal)
|
|
|
|
.ToLocalChecked());
|
|
|
|
|
|
|
|
if (data.GetEvent() == v8::kPromiseHandlerAddedAfterReject) {
|
|
|
|
v8::Local<v8::Value> id;
|
|
|
|
if (!promise->GetPrivate(context, id_private).ToLocal(&id)) return;
|
|
|
|
if (!id->IsInt32()) return;
|
|
|
|
v8_inspector::V8Inspector* inspector =
|
|
|
|
IsolateData::FromContext(context)->inspector_.get();
|
|
|
|
const char* reason_str = "Handler added to rejected promise";
|
|
|
|
inspector->exceptionRevoked(
|
|
|
|
context, id.As<v8::Int32>()->Value(),
|
|
|
|
v8_inspector::StringView(reinterpret_cast<const uint8_t*>(reason_str),
|
|
|
|
strlen(reason_str)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Value> exception = data.GetValue();
|
|
|
|
int exception_id = HandleMessage(
|
|
|
|
v8::Exception::CreateMessage(isolate, exception), exception);
|
|
|
|
if (exception_id) {
|
|
|
|
promise
|
|
|
|
->SetPrivate(isolate->GetCurrentContext(), id_private,
|
|
|
|
v8::Int32::New(isolate, exception_id))
|
|
|
|
.ToChecked();
|
|
|
|
}
|
2017-05-22 00:48:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IsolateData::FireContextCreated(v8::Local<v8::Context> context,
|
|
|
|
int context_group_id) {
|
|
|
|
v8_inspector::V8ContextInfo info(context, context_group_id,
|
|
|
|
v8_inspector::StringView());
|
|
|
|
info.hasMemoryOnConsole = true;
|
|
|
|
inspector_->contextCreated(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsolateData::FireContextDestroyed(v8::Local<v8::Context> context) {
|
|
|
|
inspector_->contextDestroyed(context);
|
|
|
|
}
|
|
|
|
|
2017-08-01 21:17:31 +00:00
|
|
|
void IsolateData::FreeContext(v8::Local<v8::Context> context) {
|
|
|
|
int context_group_id = GetContextGroupId(context);
|
|
|
|
auto it = contexts_.find(context_group_id);
|
|
|
|
if (it == contexts_.end()) return;
|
|
|
|
contexts_.erase(it);
|
|
|
|
}
|
|
|
|
|
2017-05-22 00:48:27 +00:00
|
|
|
std::vector<int> IsolateData::GetSessionIds(int context_group_id) {
|
|
|
|
std::vector<int> result;
|
|
|
|
for (auto& it : sessions_) {
|
|
|
|
if (context_group_by_session_[it.second.get()] == context_group_id)
|
|
|
|
result.push_back(it.first);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsolateData::formatAccessorsAsProperties(v8::Local<v8::Value> object) {
|
|
|
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
v8::Local<v8::Private> shouldFormatAccessorsPrivate = v8::Private::ForApi(
|
|
|
|
isolate, v8::String::NewFromUtf8(isolate, "allowAccessorFormatting",
|
|
|
|
v8::NewStringType::kNormal)
|
|
|
|
.ToLocalChecked());
|
|
|
|
CHECK(object->IsObject());
|
|
|
|
return object.As<v8::Object>()
|
|
|
|
->HasPrivate(context, shouldFormatAccessorsPrivate)
|
|
|
|
.FromMaybe(false);
|
|
|
|
}
|
|
|
|
|
2017-08-23 19:40:46 +00:00
|
|
|
bool IsolateData::isInspectableHeapObject(v8::Local<v8::Object> object) {
|
|
|
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
v8::MicrotasksScope microtasks_scope(
|
|
|
|
isolate, v8::MicrotasksScope::kDoNotRunMicrotasks);
|
|
|
|
return !object->HasPrivate(context, not_inspectable_private_.Get(isolate))
|
|
|
|
.FromMaybe(false);
|
|
|
|
}
|
|
|
|
|
2017-05-22 00:48:27 +00:00
|
|
|
v8::Local<v8::Context> IsolateData::ensureDefaultContextInGroup(
|
|
|
|
int context_group_id) {
|
|
|
|
return GetContext(context_group_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsolateData::SetCurrentTimeMS(double time) {
|
|
|
|
current_time_ = time;
|
|
|
|
current_time_set_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
double IsolateData::currentTimeMS() {
|
|
|
|
if (current_time_set_) return current_time_;
|
2017-08-25 07:12:51 +00:00
|
|
|
return v8::internal::V8::GetCurrentPlatform()->CurrentClockTimeMillis();
|
2017-05-22 00:48:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IsolateData::SetMemoryInfo(v8::Local<v8::Value> memory_info) {
|
2017-11-16 15:29:57 +00:00
|
|
|
memory_info_.Reset(isolate_.get(), memory_info);
|
2017-05-22 00:48:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IsolateData::SetLogConsoleApiMessageCalls(bool log) {
|
|
|
|
log_console_api_message_calls_ = log;
|
|
|
|
}
|
|
|
|
|
2017-10-18 18:47:30 +00:00
|
|
|
void IsolateData::SetLogMaxAsyncCallStackDepthChanged(bool log) {
|
|
|
|
log_max_async_call_stack_depth_changed_ = log;
|
|
|
|
}
|
|
|
|
|
2017-05-22 00:48:27 +00:00
|
|
|
v8::MaybeLocal<v8::Value> IsolateData::memoryInfo(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Context>) {
|
|
|
|
if (memory_info_.IsEmpty()) return v8::MaybeLocal<v8::Value>();
|
|
|
|
return memory_info_.Get(isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsolateData::runMessageLoopOnPause(int) {
|
|
|
|
task_runner_->RunMessageLoop(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsolateData::quitMessageLoopOnPause() { task_runner_->QuitMessageLoop(); }
|
|
|
|
|
|
|
|
void IsolateData::consoleAPIMessage(int contextGroupId,
|
|
|
|
v8::Isolate::MessageErrorLevel level,
|
|
|
|
const v8_inspector::StringView& message,
|
|
|
|
const v8_inspector::StringView& url,
|
|
|
|
unsigned lineNumber, unsigned columnNumber,
|
|
|
|
v8_inspector::V8StackTrace* stack) {
|
|
|
|
if (!log_console_api_message_calls_) return;
|
2017-11-16 15:29:57 +00:00
|
|
|
Print(isolate_.get(), message);
|
2017-05-22 00:48:27 +00:00
|
|
|
fprintf(stdout, " (");
|
2017-11-16 15:29:57 +00:00
|
|
|
Print(isolate_.get(), url);
|
2017-05-22 00:48:27 +00:00
|
|
|
fprintf(stdout, ":%d:%d)", lineNumber, columnNumber);
|
2017-11-16 15:29:57 +00:00
|
|
|
Print(isolate_.get(), stack->toString()->string());
|
2017-05-22 00:48:27 +00:00
|
|
|
fprintf(stdout, "\n");
|
|
|
|
}
|
2017-10-18 18:47:30 +00:00
|
|
|
|
|
|
|
void IsolateData::maxAsyncCallStackDepthChanged(int depth) {
|
|
|
|
if (!log_max_async_call_stack_depth_changed_) return;
|
|
|
|
fprintf(stdout, "maxAsyncCallStackDepthChanged: %d\n", depth);
|
|
|
|
}
|
2018-08-09 17:27:00 +00:00
|
|
|
|
|
|
|
void IsolateData::SetResourceNamePrefix(v8::Local<v8::String> prefix) {
|
|
|
|
resource_name_prefix_.Reset(v8::Isolate::GetCurrent(), prefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class StringBufferImpl : public v8_inspector::StringBuffer {
|
|
|
|
public:
|
|
|
|
StringBufferImpl(v8::Isolate* isolate, v8::Local<v8::String> string)
|
|
|
|
: data_(ToVector(isolate, string)),
|
|
|
|
view_(data_.start(), data_.length()) {}
|
|
|
|
const v8_inspector::StringView& string() override { return view_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
v8::internal::Vector<uint16_t> data_;
|
|
|
|
v8_inspector::StringView view_;
|
|
|
|
};
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
std::unique_ptr<v8_inspector::StringBuffer> IsolateData::resourceNameToUrl(
|
|
|
|
const v8_inspector::StringView& resourceName) {
|
|
|
|
if (resource_name_prefix_.IsEmpty()) return nullptr;
|
|
|
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Local<v8::String> name = ToString(isolate, resourceName);
|
|
|
|
v8::Local<v8::String> prefix = resource_name_prefix_.Get(isolate);
|
|
|
|
v8::Local<v8::String> url = v8::String::Concat(isolate, prefix, name);
|
|
|
|
return std::unique_ptr<StringBufferImpl>(new StringBufferImpl(isolate, url));
|
|
|
|
}
|