Commit 2d5cc49b authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[inspector] don't use String16 in inspector test runner

String16 is not public part of src/inspector. All usage are replaced with vector of char/unit16_t to avoid potential linker problems.

BUG=chromium:635948
R=dgozman@chromium.org,machenbach@chromium.org

Review-Url: https://codereview.chromium.org/2403493002
Cr-Commit-Position: refs/heads/master@{#40098}
parent 234f1a84
......@@ -3,7 +3,6 @@ include_rules = [
"+src/base/macros.h",
"+src/base/platform/platform.h",
"+src/flags.h",
"+src/inspector/string-16.h",
"+src/locked-queue-inl.h",
"+src/utils.h",
"+src/vector.h",
......
......@@ -5,7 +5,8 @@
#include "test/inspector/inspector-impl.h"
#include "include/v8.h"
#include "src/inspector/string-16.h"
#include "src/vector.h"
namespace {
......@@ -40,10 +41,11 @@ InspectorClientImpl* InspectorClientFromContext(
return inspector_client;
}
v8_inspector::String16 ToString16(v8::Local<v8::String> str) {
std::unique_ptr<uint16_t[]> buffer(new uint16_t[str->Length()]);
str->Write(reinterpret_cast<uint16_t*>(buffer.get()), 0, str->Length());
return v8_inspector::String16(buffer.get(), str->Length());
v8::internal::Vector<uint16_t> ToVector(v8::Local<v8::String> str) {
v8::internal::Vector<uint16_t> buffer =
v8::internal::Vector<uint16_t>::New(str->Length());
str->Write(buffer.start(), 0, str->Length());
return buffer;
}
void MessageHandler(v8::Local<v8::Message> message,
......@@ -67,15 +69,15 @@ void MessageHandler(v8::Local<v8::Message> message,
column_number = message->GetStartColumn(context).FromJust() + 1;
v8_inspector::StringView detailed_message;
v8_inspector::String16 message_text_string = ToString16(message->Get());
v8_inspector::StringView message_text(message_text_string.characters16(),
v8::internal::Vector<uint16_t> message_text_string = ToVector(message->Get());
v8_inspector::StringView message_text(message_text_string.start(),
message_text_string.length());
v8_inspector::String16 url_string;
v8::internal::Vector<uint16_t> url_string;
if (message->GetScriptOrigin().ResourceName()->IsString()) {
url_string =
ToString16(message->GetScriptOrigin().ResourceName().As<v8::String>());
ToVector(message->GetScriptOrigin().ResourceName().As<v8::String>());
}
v8_inspector::StringView url(url_string.characters16(), url_string.length());
v8_inspector::StringView url(url_string.start(), url_string.length());
inspector->exceptionThrown(context, message_text, exception, detailed_message,
url, line_number, column_number,
......@@ -159,7 +161,8 @@ v8_inspector::V8InspectorSession* InspectorClientImpl::SessionFromContext(
class SendMessageToBackendTask : public TaskRunner::Task {
public:
explicit SendMessageToBackendTask(const v8_inspector::String16& message)
explicit SendMessageToBackendTask(
const v8::internal::Vector<uint16_t>& message)
: message_(message) {}
bool is_inspector_task() final { return true; }
......@@ -173,14 +176,12 @@ class SendMessageToBackendTask : public TaskRunner::Task {
session = InspectorClientImpl::SessionFromContext(context);
CHECK(session);
}
v8_inspector::StringView message_view(
reinterpret_cast<const uint16_t*>(message_.characters16()),
message_.length());
v8_inspector::StringView message_view(message_.start(), message_.length());
session->dispatchProtocolMessage(message_view);
}
private:
v8_inspector::String16 message_;
v8::internal::Vector<uint16_t> message_;
};
TaskRunner* SendMessageToBackendExtension::backend_task_runner_ = nullptr;
......@@ -197,6 +198,5 @@ void SendMessageToBackendExtension::SendMessageToBackend(
CHECK(backend_task_runner_);
CHECK(args.Length() == 1 && args[0]->IsString());
v8::Local<v8::String> message = args[0].As<v8::String>();
backend_task_runner_->Append(
new SendMessageToBackendTask(ToString16(message)));
backend_task_runner_->Append(new SendMessageToBackendTask(ToVector(message)));
}
......@@ -114,6 +114,13 @@ class SetTimeoutTask : public TaskRunner::Task {
v8::Global<v8::Function> function_;
};
v8::internal::Vector<uint16_t> ToVector(v8::Local<v8::String> str) {
v8::internal::Vector<uint16_t> buffer =
v8::internal::Vector<uint16_t>::New(str->Length());
str->Write(buffer.start(), 0, str->Length());
return buffer;
}
class SetTimeoutExtension : public v8::Extension {
public:
SetTimeoutExtension()
......@@ -139,23 +146,24 @@ class SetTimeoutExtension : public v8::Extension {
TaskRunner::FromContext(context)->Append(new SetTimeoutTask(
args.GetIsolate(), v8::Local<v8::Function>::Cast(args[0])));
} else {
v8::Local<v8::String> data = args[0].As<v8::String>();
std::unique_ptr<uint16_t[]> buffer(new uint16_t[data->Length()]);
data->Write(reinterpret_cast<uint16_t*>(buffer.get()), 0, data->Length());
v8_inspector::String16 source =
v8_inspector::String16(buffer.get(), data->Length());
TaskRunner::FromContext(context)->Append(new ExecuteStringTask(source));
TaskRunner::FromContext(context)->Append(
new ExecuteStringTask(ToVector(args[0].As<v8::String>())));
}
}
};
v8_inspector::String16 ToString16(const v8_inspector::StringView& string) {
v8::Local<v8::String> ToString(v8::Isolate* isolate,
const v8_inspector::StringView& string) {
if (string.is8Bit())
return v8_inspector::String16(
reinterpret_cast<const char*>(string.characters8()), string.length());
return v8_inspector::String16(
reinterpret_cast<const uint16_t*>(string.characters16()),
string.length());
return v8::String::NewFromOneByte(isolate, string.characters8(),
v8::NewStringType::kNormal,
string.length())
.ToLocalChecked();
else
return v8::String::NewFromTwoByte(isolate, string.characters16(),
v8::NewStringType::kNormal,
string.length())
.ToLocalChecked();
}
class FrontendChannelImpl : public InspectorClientImpl::FrontendChannel {
......@@ -165,11 +173,22 @@ class FrontendChannelImpl : public InspectorClientImpl::FrontendChannel {
virtual ~FrontendChannelImpl() {}
void SendMessageToFrontend(const v8_inspector::StringView& message) final {
v8_inspector::String16Builder script;
script.append("InspectorTest._dispatchMessage(");
script.append(ToString16(message));
script.append(")");
frontend_task_runner_->Append(new ExecuteStringTask(script.toString()));
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(v8::Isolate::GetCurrent());
v8::Local<v8::String> prefix =
v8::String::NewFromUtf8(isolate, "InspectorTest._dispatchMessage(",
v8::NewStringType::kInternalized)
.ToLocalChecked();
v8::Local<v8::String> message_string = ToString(isolate, message);
v8::Local<v8::String> suffix =
v8::String::NewFromUtf8(isolate, ")", v8::NewStringType::kInternalized)
.ToLocalChecked();
v8::Local<v8::String> result = v8::String::Concat(prefix, message_string);
result = v8::String::Concat(result, suffix);
frontend_task_runner_->Append(new ExecuteStringTask(ToVector(result)));
}
private:
......@@ -225,9 +244,7 @@ int main(int argc, char* argv[]) {
argv[i]);
Exit();
}
v8_inspector::String16 source =
v8_inspector::String16::fromUTF8(chars.start(), chars.length());
frontend_runner.Append(new ExecuteStringTask(source));
frontend_runner.Append(new ExecuteStringTask(chars));
}
frontend_runner.Join();
......
......@@ -20,6 +20,7 @@
'type': 'executable',
'dependencies': [
'../../src/v8.gyp:v8_libplatform',
'../../src/v8.gyp:v8',
],
'include_dirs': [
'../..',
......
......@@ -117,9 +117,14 @@ TaskRunner* TaskRunner::FromContext(v8::Local<v8::Context> context) {
context->GetAlignedPointerFromEmbedderData(kTaskRunnerIndex));
}
ExecuteStringTask::ExecuteStringTask(const v8_inspector::String16& expression)
ExecuteStringTask::ExecuteStringTask(
const v8::internal::Vector<uint16_t>& expression)
: expression_(expression) {}
ExecuteStringTask::ExecuteStringTask(
const v8::internal::Vector<const char>& expression)
: expression_utf8_(expression) {}
void ExecuteStringTask::Run(v8::Isolate* isolate,
const v8::Global<v8::Context>& context) {
v8::MicrotasksScope microtasks_scope(isolate,
......@@ -129,11 +134,18 @@ void ExecuteStringTask::Run(v8::Isolate* isolate,
v8::Context::Scope context_scope(local_context);
v8::ScriptOrigin origin(v8::String::Empty(isolate));
v8::Local<v8::String> source =
v8::String::NewFromTwoByte(isolate, expression_.characters16(),
v8::Local<v8::String> source;
if (expression_.length()) {
source = v8::String::NewFromTwoByte(isolate, expression_.start(),
v8::NewStringType::kNormal,
static_cast<int>(expression_.length()))
expression_.length())
.ToLocalChecked();
} else {
source = v8::String::NewFromUtf8(isolate, expression_utf8_.start(),
v8::NewStringType::kNormal,
expression_utf8_.length())
.ToLocalChecked();
}
v8::ScriptCompiler::Source scriptSource(source, origin);
v8::Local<v8::Script> script;
......
......@@ -10,8 +10,8 @@
#include "include/v8.h"
#include "src/base/macros.h"
#include "src/base/platform/platform.h"
#include "src/inspector/string-16.h"
#include "src/locked-queue-inl.h"
#include "src/vector.h"
class TaskRunner : public v8::base::Thread {
public:
......@@ -65,14 +65,17 @@ class TaskRunner : public v8::base::Thread {
class ExecuteStringTask : public TaskRunner::Task {
public:
explicit ExecuteStringTask(const v8_inspector::String16& expression);
explicit ExecuteStringTask(const v8::internal::Vector<uint16_t>& expression);
explicit ExecuteStringTask(
const v8::internal::Vector<const char>& expression);
bool is_inspector_task() override { return false; }
void Run(v8::Isolate* isolate,
const v8::Global<v8::Context>& context) override;
private:
v8_inspector::String16 expression_;
v8::internal::Vector<uint16_t> expression_;
v8::internal::Vector<const char> expression_utf8_;
DISALLOW_COPY_AND_ASSIGN(ExecuteStringTask);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment