Commit 64e3912f authored by Ross Mcilroy's avatar Ross Mcilroy Committed by Commit Bot

[cleanup] Remove deprecated calls to Write[OneByte/Utf8].

Replace with isolate version.

BUG=v8:7754

Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iac7091b983960d22b892074c5fd0a97dee9025c9
Reviewed-on: https://chromium-review.googlesource.com/1146332
Commit-Queue: Dan Elphick <delphick@chromium.org>
Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54604}
parent bc017d81
...@@ -184,7 +184,7 @@ void VTUNEJITInterface::event_handler(const v8::JitCodeEvent* event) { ...@@ -184,7 +184,7 @@ void VTUNEJITInterface::event_handler(const v8::JitCodeEvent* event) {
Local<String>::Cast(script->GetScriptName()); Local<String>::Cast(script->GetScriptName());
temp_file_name = temp_file_name =
new char[script_name->Utf8Length(event->isolate) + 1]; new char[script_name->Utf8Length(event->isolate) + 1];
script_name->WriteUtf8(temp_file_name); script_name->WriteUtf8(event->isolate, temp_file_name);
jmethod.source_file_name = temp_file_name; jmethod.source_file_name = temp_file_name;
} }
......
This diff is collapsed.
...@@ -294,7 +294,7 @@ class TestCodeEventHandler : public v8::CodeEventHandler { ...@@ -294,7 +294,7 @@ class TestCodeEventHandler : public v8::CodeEventHandler {
if (name.empty()) { if (name.empty()) {
v8::Local<v8::String> functionName = code_event->GetFunctionName(); v8::Local<v8::String> functionName = code_event->GetFunctionName();
std::string buffer(functionName->Utf8Length(isolate_) + 1, 0); std::string buffer(functionName->Utf8Length(isolate_) + 1, 0);
functionName->WriteUtf8(&buffer[0], functionName->WriteUtf8(isolate_, &buffer[0],
functionName->Utf8Length(isolate_) + 1); functionName->Utf8Length(isolate_) + 1);
// Sanitize name, removing unwanted \0 resulted from WriteUtf8 // Sanitize name, removing unwanted \0 resulted from WriteUtf8
name = std::string(buffer.c_str()); name = std::string(buffer.c_str());
...@@ -716,7 +716,7 @@ TEST(EquivalenceOfLoggingAndTraversal) { ...@@ -716,7 +716,7 @@ TEST(EquivalenceOfLoggingAndTraversal) {
v8::Local<v8::String> s = result->ToString(logger.env()).ToLocalChecked(); v8::Local<v8::String> s = result->ToString(logger.env()).ToLocalChecked();
i::ScopedVector<char> data(s->Utf8Length(isolate) + 1); i::ScopedVector<char> data(s->Utf8Length(isolate) + 1);
CHECK(data.start()); CHECK(data.start());
s->WriteUtf8(data.start()); s->WriteUtf8(isolate, data.start());
FATAL("%s\n", data.start()); FATAL("%s\n", data.start());
} }
} }
......
...@@ -951,7 +951,8 @@ TEST(Utf8Conversion) { ...@@ -951,7 +951,8 @@ TEST(Utf8Conversion) {
for (int j = 0; j < 11; j++) for (int j = 0; j < 11; j++)
buffer[j] = kNoChar; buffer[j] = kNoChar;
int chars_written; int chars_written;
int written = mixed->WriteUtf8(buffer, i, &chars_written); int written =
mixed->WriteUtf8(CcTest::isolate(), buffer, i, &chars_written);
CHECK_EQ(lengths[i], written); CHECK_EQ(lengths[i], written);
CHECK_EQ(char_lengths[i], chars_written); CHECK_EQ(char_lengths[i], chars_written);
// Check that the contents are correct // Check that the contents are correct
...@@ -1095,7 +1096,7 @@ TEST(JSONStringifySliceMadeExternal) { ...@@ -1095,7 +1096,7 @@ TEST(JSONStringifySliceMadeExternal) {
int length = underlying->Length(); int length = underlying->Length();
uc16* two_byte = NewArray<uc16>(length + 1); uc16* two_byte = NewArray<uc16>(length + 1);
underlying->Write(two_byte); underlying->Write(CcTest::isolate(), two_byte);
Resource* resource = new Resource(two_byte, length); Resource* resource = new Resource(two_byte, length);
CHECK(underlying->MakeExternal(resource)); CHECK(underlying->MakeExternal(resource));
CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString()); CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString());
......
...@@ -319,12 +319,12 @@ std::string GenerateSourceString(FuzzerArgs* args, const std::string& test) { ...@@ -319,12 +319,12 @@ std::string GenerateSourceString(FuzzerArgs* args, const std::string& test) {
return ss.str(); return ss.str();
} }
void PrintExceptionMessage(v8::TryCatch* try_catch) { void PrintExceptionMessage(v8::Isolate* isolate, v8::TryCatch* try_catch) {
CHECK(try_catch->HasCaught()); CHECK(try_catch->HasCaught());
static const int kBufferLength = 256; static const int kBufferLength = 256;
char buffer[kBufferLength + 1]; char buffer[kBufferLength + 1];
try_catch->Message()->Get()->WriteOneByte( try_catch->Message()->Get()->WriteOneByte(
reinterpret_cast<uint8_t*>(&buffer[0]), 0, kBufferLength); isolate, reinterpret_cast<uint8_t*>(&buffer[0]), 0, kBufferLength);
fprintf(stderr, "%s\n", buffer); fprintf(stderr, "%s\n", buffer);
} }
...@@ -337,9 +337,10 @@ bool ResultsAreIdentical(FuzzerArgs* args) { ...@@ -337,9 +337,10 @@ bool ResultsAreIdentical(FuzzerArgs* args) {
"assertEquals(fast.re.lastIndex, slow.re.lastIndex);\n"; "assertEquals(fast.re.lastIndex, slow.re.lastIndex);\n";
v8::Local<v8::Value> result; v8::Local<v8::Value> result;
v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(args->isolate)); v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(args->isolate);
v8::TryCatch try_catch(isolate);
if (!CompileRun(args->context, source.c_str()).ToLocal(&result)) { if (!CompileRun(args->context, source.c_str()).ToLocal(&result)) {
PrintExceptionMessage(&try_catch); PrintExceptionMessage(isolate, &try_catch);
args->isolate->clear_pending_exception(); args->isolate->clear_pending_exception();
return false; return false;
} }
...@@ -349,14 +350,15 @@ bool ResultsAreIdentical(FuzzerArgs* args) { ...@@ -349,14 +350,15 @@ bool ResultsAreIdentical(FuzzerArgs* args) {
void CompileRunAndVerify(FuzzerArgs* args, const std::string& source) { void CompileRunAndVerify(FuzzerArgs* args, const std::string& source) {
v8::Local<v8::Value> result; v8::Local<v8::Value> result;
v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(args->isolate)); v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(args->isolate);
v8::TryCatch try_catch(isolate);
if (!CompileRun(args->context, source.c_str()).ToLocal(&result)) { if (!CompileRun(args->context, source.c_str()).ToLocal(&result)) {
args->isolate->clear_pending_exception(); args->isolate->clear_pending_exception();
// No need to verify result if an exception was thrown here, since that // No need to verify result if an exception was thrown here, since that
// implies a syntax error somewhere in the pattern or string. We simply // implies a syntax error somewhere in the pattern or string. We simply
// ignore those. // ignore those.
if (kVerbose) { if (kVerbose) {
PrintExceptionMessage(&try_catch); PrintExceptionMessage(isolate, &try_catch);
fprintf(stderr, "Failed to run script:\n```\n%s\n```\n", source.c_str()); fprintf(stderr, "Failed to run script:\n```\n%s\n```\n", source.c_str());
} }
return; return;
......
...@@ -38,10 +38,11 @@ void Exit() { ...@@ -38,10 +38,11 @@ void Exit() {
Terminate(); Terminate();
} }
v8::internal::Vector<uint16_t> ToVector(v8::Local<v8::String> str) { v8::internal::Vector<uint16_t> ToVector(v8::Isolate* isolate,
v8::Local<v8::String> str) {
v8::internal::Vector<uint16_t> buffer = v8::internal::Vector<uint16_t> buffer =
v8::internal::Vector<uint16_t>::New(str->Length()); v8::internal::Vector<uint16_t>::New(str->Length());
str->Write(buffer.start(), 0, str->Length()); str->Write(isolate, buffer.start(), 0, str->Length());
return buffer; return buffer;
} }
...@@ -200,14 +201,14 @@ void RunAsyncTask(TaskRunner* task_runner, ...@@ -200,14 +201,14 @@ void RunAsyncTask(TaskRunner* task_runner,
class ExecuteStringTask : public TaskRunner::Task { class ExecuteStringTask : public TaskRunner::Task {
public: public:
ExecuteStringTask(int context_group_id, ExecuteStringTask(v8::Isolate* isolate, int context_group_id,
const v8::internal::Vector<uint16_t>& expression, const v8::internal::Vector<uint16_t>& expression,
v8::Local<v8::String> name, v8::Local<v8::String> name,
v8::Local<v8::Integer> line_offset, v8::Local<v8::Integer> line_offset,
v8::Local<v8::Integer> column_offset, v8::Local<v8::Integer> column_offset,
v8::Local<v8::Boolean> is_module) v8::Local<v8::Boolean> is_module)
: expression_(expression), : expression_(expression),
name_(ToVector(name)), name_(ToVector(isolate, name)),
line_offset_(line_offset.As<v8::Int32>()->Value()), line_offset_(line_offset.As<v8::Int32>()->Value()),
column_offset_(column_offset.As<v8::Int32>()->Value()), column_offset_(column_offset.As<v8::Int32>()->Value()),
is_module_(is_module->Value()), is_module_(is_module->Value()),
...@@ -430,7 +431,8 @@ class UtilsExtension : public IsolateData::SetupGlobalTask { ...@@ -430,7 +431,8 @@ class UtilsExtension : public IsolateData::SetupGlobalTask {
} }
backend_runner_->Append(new ExecuteStringTask( backend_runner_->Append(new ExecuteStringTask(
args[0].As<v8::Int32>()->Value(), ToVector(args[1].As<v8::String>()), args.GetIsolate(), args[0].As<v8::Int32>()->Value(),
ToVector(args.GetIsolate(), args[1].As<v8::String>()),
args[2].As<v8::String>(), args[3].As<v8::Int32>(), args[2].As<v8::String>(), args[3].As<v8::Int32>(),
args[4].As<v8::Int32>(), args[5].As<v8::Boolean>())); args[4].As<v8::Int32>(), args[5].As<v8::Boolean>()));
} }
...@@ -463,8 +465,10 @@ class UtilsExtension : public IsolateData::SetupGlobalTask { ...@@ -463,8 +465,10 @@ class UtilsExtension : public IsolateData::SetupGlobalTask {
"'reason', 'details')."); "'reason', 'details').");
Exit(); Exit();
} }
v8::internal::Vector<uint16_t> reason = ToVector(args[1].As<v8::String>()); v8::internal::Vector<uint16_t> reason =
v8::internal::Vector<uint16_t> details = ToVector(args[2].As<v8::String>()); ToVector(args.GetIsolate(), args[1].As<v8::String>());
v8::internal::Vector<uint16_t> details =
ToVector(args.GetIsolate(), args[2].As<v8::String>());
int context_group_id = args[0].As<v8::Int32>()->Value(); int context_group_id = args[0].As<v8::Int32>()->Value();
RunSyncTask(backend_runner_, [&context_group_id, &reason, RunSyncTask(backend_runner_, [&context_group_id, &reason,
&details](IsolateData* data) { &details](IsolateData* data) {
...@@ -537,7 +541,8 @@ class UtilsExtension : public IsolateData::SetupGlobalTask { ...@@ -537,7 +541,8 @@ class UtilsExtension : public IsolateData::SetupGlobalTask {
IsolateData::FromContext(context)->GetContextGroupId(context), IsolateData::FromContext(context)->GetContextGroupId(context),
args.GetIsolate(), args[2].As<v8::Function>()); args.GetIsolate(), args[2].As<v8::Function>());
v8::internal::Vector<uint16_t> state = ToVector(args[1].As<v8::String>()); v8::internal::Vector<uint16_t> state =
ToVector(args.GetIsolate(), args[1].As<v8::String>());
int context_group_id = args[0].As<v8::Int32>()->Value(); int context_group_id = args[0].As<v8::Int32>()->Value();
int session_id = 0; int session_id = 0;
RunSyncTask(backend_runner_, [&context_group_id, &session_id, &channel, RunSyncTask(backend_runner_, [&context_group_id, &session_id, &channel,
...@@ -575,7 +580,8 @@ class UtilsExtension : public IsolateData::SetupGlobalTask { ...@@ -575,7 +580,8 @@ class UtilsExtension : public IsolateData::SetupGlobalTask {
Exit(); Exit();
} }
backend_runner_->Append(new SendMessageToBackendTask( backend_runner_->Append(new SendMessageToBackendTask(
args[0].As<v8::Int32>()->Value(), ToVector(args[1].As<v8::String>()))); args[0].As<v8::Int32>()->Value(),
ToVector(args.GetIsolate(), args[1].As<v8::String>())));
} }
static std::map<int, std::unique_ptr<FrontendChannelImpl>> channels_; static std::map<int, std::unique_ptr<FrontendChannelImpl>> channels_;
...@@ -643,7 +649,8 @@ class SetTimeoutExtension : public IsolateData::SetupGlobalTask { ...@@ -643,7 +649,8 @@ class SetTimeoutExtension : public IsolateData::SetupGlobalTask {
RunAsyncTask( RunAsyncTask(
data->task_runner(), task_name_view, data->task_runner(), task_name_view,
new ExecuteStringTask( new ExecuteStringTask(
context_group_id, ToVector(args[0].As<v8::String>()), isolate, context_group_id,
ToVector(isolate, args[0].As<v8::String>()),
v8::String::Empty(isolate), v8::Integer::New(isolate, 0), v8::String::Empty(isolate), v8::Integer::New(isolate, 0),
v8::Integer::New(isolate, 0), v8::Boolean::New(isolate, false))); v8::Integer::New(isolate, 0), v8::Boolean::New(isolate, false)));
} }
...@@ -782,9 +789,11 @@ class InspectorExtension : public IsolateData::SetupGlobalTask { ...@@ -782,9 +789,11 @@ class InspectorExtension : public IsolateData::SetupGlobalTask {
} }
v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext();
IsolateData* data = IsolateData::FromContext(context); IsolateData* data = IsolateData::FromContext(context);
v8::internal::Vector<uint16_t> reason = ToVector(args[0].As<v8::String>()); v8::internal::Vector<uint16_t> reason =
ToVector(args.GetIsolate(), args[0].As<v8::String>());
v8_inspector::StringView reason_view(reason.start(), reason.length()); v8_inspector::StringView reason_view(reason.start(), reason.length());
v8::internal::Vector<uint16_t> details = ToVector(args[1].As<v8::String>()); v8::internal::Vector<uint16_t> details =
ToVector(args.GetIsolate(), args[1].As<v8::String>());
v8_inspector::StringView details_view(details.start(), details.length()); v8_inspector::StringView details_view(details.start(), details.length());
data->BreakProgram(data->GetContextGroupId(context), reason_view, data->BreakProgram(data->GetContextGroupId(context), reason_view,
details_view); details_view);
...@@ -812,9 +821,11 @@ class InspectorExtension : public IsolateData::SetupGlobalTask { ...@@ -812,9 +821,11 @@ class InspectorExtension : public IsolateData::SetupGlobalTask {
"Internal error: callWithScheduledBreak('reason', 'details')."); "Internal error: callWithScheduledBreak('reason', 'details').");
Exit(); Exit();
} }
v8::internal::Vector<uint16_t> reason = ToVector(args[1].As<v8::String>()); v8::internal::Vector<uint16_t> reason =
ToVector(args.GetIsolate(), args[1].As<v8::String>());
v8_inspector::StringView reason_view(reason.start(), reason.length()); v8_inspector::StringView reason_view(reason.start(), reason.length());
v8::internal::Vector<uint16_t> details = ToVector(args[2].As<v8::String>()); v8::internal::Vector<uint16_t> details =
ToVector(args.GetIsolate(), args[2].As<v8::String>());
v8_inspector::StringView details_view(details.start(), details.length()); v8_inspector::StringView details_view(details.start(), details.length());
v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext();
IsolateData* data = IsolateData::FromContext(context); IsolateData* data = IsolateData::FromContext(context);
...@@ -903,7 +914,7 @@ class InspectorExtension : public IsolateData::SetupGlobalTask { ...@@ -903,7 +914,7 @@ class InspectorExtension : public IsolateData::SetupGlobalTask {
v8::Local<v8::Context> context = isolate->GetCurrentContext(); v8::Local<v8::Context> context = isolate->GetCurrentContext();
IsolateData* data = IsolateData::FromContext(context); IsolateData* data = IsolateData::FromContext(context);
v8::internal::Vector<uint16_t> description = v8::internal::Vector<uint16_t> description =
ToVector(args[0].As<v8::String>()); ToVector(isolate, args[0].As<v8::String>());
v8_inspector::StringView description_view(description.start(), v8_inspector::StringView description_view(description.start(),
description.length()); description.length());
v8_inspector::V8StackTraceId id = v8_inspector::V8StackTraceId id =
...@@ -960,7 +971,7 @@ class InspectorExtension : public IsolateData::SetupGlobalTask { ...@@ -960,7 +971,7 @@ class InspectorExtension : public IsolateData::SetupGlobalTask {
if (with_empty_stack) context->Exit(); if (with_empty_stack) context->Exit();
v8::internal::Vector<uint16_t> task_name = v8::internal::Vector<uint16_t> task_name =
ToVector(args[1].As<v8::String>()); ToVector(isolate, args[1].As<v8::String>());
v8_inspector::StringView task_name_view(task_name.start(), v8_inspector::StringView task_name_view(task_name.start(),
task_name.length()); task_name.length());
......
...@@ -12,10 +12,11 @@ namespace { ...@@ -12,10 +12,11 @@ namespace {
const int kIsolateDataIndex = 2; const int kIsolateDataIndex = 2;
const int kContextGroupIdIndex = 3; const int kContextGroupIdIndex = 3;
v8::internal::Vector<uint16_t> ToVector(v8::Local<v8::String> str) { v8::internal::Vector<uint16_t> ToVector(v8::Isolate* isolate,
v8::Local<v8::String> str) {
v8::internal::Vector<uint16_t> buffer = v8::internal::Vector<uint16_t> buffer =
v8::internal::Vector<uint16_t>::New(str->Length()); v8::internal::Vector<uint16_t>::New(str->Length());
str->Write(buffer.start(), 0, str->Length()); str->Write(isolate, buffer.start(), 0, str->Length());
return buffer; return buffer;
} }
...@@ -137,7 +138,8 @@ v8::MaybeLocal<v8::Module> IsolateData::ModuleResolveCallback( ...@@ -137,7 +138,8 @@ v8::MaybeLocal<v8::Module> IsolateData::ModuleResolveCallback(
v8::Local<v8::Module> referrer) { v8::Local<v8::Module> referrer) {
IsolateData* data = IsolateData::FromContext(context); IsolateData* data = IsolateData::FromContext(context);
std::string str = *v8::String::Utf8Value(data->isolate(), specifier); std::string str = *v8::String::Utf8Value(data->isolate(), specifier);
return data->modules_[ToVector(specifier)].Get(data->isolate()); return data->modules_[ToVector(data->isolate(), specifier)].Get(
data->isolate());
} }
int IsolateData::ConnectSession(int context_group_id, int IsolateData::ConnectSession(int context_group_id,
...@@ -258,13 +260,14 @@ int IsolateData::HandleMessage(v8::Local<v8::Message> message, ...@@ -258,13 +260,14 @@ int IsolateData::HandleMessage(v8::Local<v8::Message> message,
column_number = message->GetStartColumn(context).FromJust() + 1; column_number = message->GetStartColumn(context).FromJust() + 1;
v8_inspector::StringView detailed_message; v8_inspector::StringView detailed_message;
v8::internal::Vector<uint16_t> message_text_string = ToVector(message->Get()); v8::internal::Vector<uint16_t> message_text_string =
ToVector(isolate, message->Get());
v8_inspector::StringView message_text(message_text_string.start(), v8_inspector::StringView message_text(message_text_string.start(),
message_text_string.length()); message_text_string.length());
v8::internal::Vector<uint16_t> url_string; v8::internal::Vector<uint16_t> url_string;
if (message->GetScriptOrigin().ResourceName()->IsString()) { if (message->GetScriptOrigin().ResourceName()->IsString()) {
url_string = url_string = ToVector(
ToVector(message->GetScriptOrigin().ResourceName().As<v8::String>()); isolate, message->GetScriptOrigin().ResourceName().As<v8::String>());
} }
v8_inspector::StringView url(url_string.start(), url_string.length()); v8_inspector::StringView url(url_string.start(), url_string.length());
......
...@@ -2514,7 +2514,8 @@ TEST_F(ValueSerializerTestWithWasm, DefaultSerializationDelegate) { ...@@ -2514,7 +2514,8 @@ TEST_F(ValueSerializerTestWithWasm, DefaultSerializationDelegate) {
Local<Message> message = InvalidEncodeTest(MakeWasm()); Local<Message> message = InvalidEncodeTest(MakeWasm());
size_t msg_len = static_cast<size_t>(message->Get()->Length()); size_t msg_len = static_cast<size_t>(message->Get()->Length());
std::unique_ptr<char[]> buff(new char[msg_len + 1]); std::unique_ptr<char[]> buff(new char[msg_len + 1]);
message->Get()->WriteOneByte(reinterpret_cast<uint8_t*>(buff.get())); message->Get()->WriteOneByte(isolate(),
reinterpret_cast<uint8_t*>(buff.get()));
// the message ends with the custom error string // the message ends with the custom error string
size_t custom_msg_len = strlen(kUnsupportedSerialization); size_t custom_msg_len = strlen(kUnsupportedSerialization);
ASSERT_GE(msg_len, custom_msg_len); ASSERT_GE(msg_len, custom_msg_len);
......
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