Commit e5440c76 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[v8] Update v8::String::NewFromUtf8 users

- Avoid v8::NewStringType::kNormal where possible
- Use v8::NewStringType::kInternalized for object properties

Bug: v8:10884
Change-Id: Ic7ec1e8dbdc1c56a72ed651da361b920c8145e7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2398544
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805700}
parent b4d31ffd
...@@ -42,8 +42,7 @@ class TestModule : public base::ModuleCache::Module { ...@@ -42,8 +42,7 @@ class TestModule : public base::ModuleCache::Module {
}; };
v8::Local<v8::String> ToV8String(const char* str) { v8::Local<v8::String> ToV8String(const char* str) {
return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), str, return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), str)
v8::NewStringType::kNormal)
.ToLocalChecked(); .ToLocalChecked();
} }
......
...@@ -160,9 +160,7 @@ bool V8UnitTest::RunJavascriptTestF(const std::string& test_fixture, ...@@ -160,9 +160,7 @@ bool V8UnitTest::RunJavascriptTestF(const std::string& test_fixture,
.Check(); .Check();
v8::Local<v8::Value> args[] = { v8::Local<v8::Value> args[] = {
v8::Boolean::New(isolate, false), v8::Boolean::New(isolate, false),
v8::String::NewFromUtf8(isolate, "RUN_TEST_F", v8::NewStringType::kNormal) v8::String::NewFromUtf8Literal(isolate, "RUN_TEST_F"), params};
.ToLocalChecked(),
params};
v8::TryCatch try_catch(isolate); v8::TryCatch try_catch(isolate);
v8::Local<v8::Value> result = v8::Local<v8::Value> result =
......
...@@ -122,13 +122,12 @@ TEST_F(GinJavaBridgeValueConverterTest, TypedArrays) { ...@@ -122,13 +122,12 @@ TEST_F(GinJavaBridgeValueConverterTest, TypedArrays) {
const char* typed_array_type = array_types[i + 1]; const char* typed_array_type = array_types[i + 1];
v8::Local<v8::Script> script( v8::Local<v8::Script> script(
v8::Script::Compile( v8::Script::Compile(
context, v8::String::NewFromUtf8( context,
isolate_, v8::String::NewFromUtf8(
base::StringPrintf(source_template, array_types[i], isolate_, base::StringPrintf(source_template, array_types[i],
typed_array_type) typed_array_type)
.c_str(), .c_str())
v8::NewStringType::kNormal) .ToLocalChecked())
.ToLocalChecked())
.ToLocalChecked()); .ToLocalChecked());
v8::Local<v8::Value> v8_typed_array = script->Run(context).ToLocalChecked(); v8::Local<v8::Value> v8_typed_array = script->Run(context).ToLocalChecked();
std::unique_ptr<base::Value> list_value( std::unique_ptr<base::Value> list_value(
......
...@@ -428,10 +428,8 @@ TEST_F(V8VarConverterTest, StrangeDictionaryKeyTest) { ...@@ -428,10 +428,8 @@ TEST_F(V8VarConverterTest, StrangeDictionaryKeyTest) {
"})();"; "})();";
v8::Local<v8::Script> script( v8::Local<v8::Script> script(
v8::Script::Compile(context, v8::Script::Compile(
v8::String::NewFromUtf8(isolate_, source, context, v8::String::NewFromUtf8(isolate_, source).ToLocalChecked())
v8::NewStringType::kNormal)
.ToLocalChecked())
.ToLocalChecked()); .ToLocalChecked());
v8::Local<v8::Object> object = v8::Local<v8::Object> object =
script->Run(context).ToLocalChecked().As<v8::Object>(); script->Run(context).ToLocalChecked().As<v8::Object>();
......
...@@ -231,9 +231,8 @@ class V8ValueConverterImplTest : public testing::Test { ...@@ -231,9 +231,8 @@ class V8ValueConverterImplTest : public testing::Test {
template <typename T> template <typename T>
v8::Local<T> CompileRun(v8::Local<v8::Context> context, const char* source) { v8::Local<T> CompileRun(v8::Local<v8::Context> context, const char* source) {
return v8::Script::Compile( return v8::Script::Compile(
context, v8::String::NewFromUtf8(isolate_, source, context,
v8::NewStringType::kNormal) v8::String::NewFromUtf8(isolate_, source).ToLocalChecked())
.ToLocalChecked())
.ToLocalChecked() .ToLocalChecked()
->Run(context) ->Run(context)
.ToLocalChecked() .ToLocalChecked()
...@@ -496,11 +495,8 @@ TEST_F(V8ValueConverterImplTest, WeirdTypes) { ...@@ -496,11 +495,8 @@ TEST_F(V8ValueConverterImplTest, WeirdTypes) {
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
v8::Local<v8::RegExp> regex( v8::Local<v8::RegExp> regex(
v8::RegExp::New( v8::RegExp::New(context, v8::String::NewFromUtf8Literal(isolate_, "."),
context, v8::RegExp::kNone)
v8::String::NewFromUtf8(isolate_, ".", v8::NewStringType::kNormal)
.ToLocalChecked(),
v8::RegExp::kNone)
.ToLocalChecked()); .ToLocalChecked());
V8ValueConverterImpl converter; V8ValueConverterImpl converter;
...@@ -719,8 +715,7 @@ TEST_F(V8ValueConverterImplTest, RecursiveObjects) { ...@@ -719,8 +715,7 @@ TEST_F(V8ValueConverterImplTest, RecursiveObjects) {
v8::String::NewFromUtf8(isolate_, "foo", v8::String::NewFromUtf8(isolate_, "foo",
v8::NewStringType::kInternalized) v8::NewStringType::kInternalized)
.ToLocalChecked(), .ToLocalChecked(),
v8::String::NewFromUtf8(isolate_, "bar", v8::NewStringType::kNormal) v8::String::NewFromUtf8Literal(isolate_, "bar"))
.ToLocalChecked())
.Check(); .Check();
object object
->Set(context, ->Set(context,
...@@ -738,11 +733,7 @@ TEST_F(V8ValueConverterImplTest, RecursiveObjects) { ...@@ -738,11 +733,7 @@ TEST_F(V8ValueConverterImplTest, RecursiveObjects) {
v8::Local<v8::Array> array = v8::Array::New(isolate_).As<v8::Array>(); v8::Local<v8::Array> array = v8::Array::New(isolate_).As<v8::Array>();
ASSERT_FALSE(array.IsEmpty()); ASSERT_FALSE(array.IsEmpty());
array array->Set(context, 0, v8::String::NewFromUtf8Literal(isolate_, "1")).Check();
->Set(context, 0,
v8::String::NewFromUtf8(isolate_, "1", v8::NewStringType::kNormal)
.ToLocalChecked())
.Check();
array->Set(context, 1, array).Check(); array->Set(context, 1, array).Check();
std::unique_ptr<base::ListValue> list_result( std::unique_ptr<base::ListValue> list_result(
......
...@@ -21,35 +21,25 @@ std::unique_ptr<base::Value> SummarizeV8Value(v8::Isolate* isolate, ...@@ -21,35 +21,25 @@ std::unique_ptr<base::Value> SummarizeV8Value(v8::Isolate* isolate,
v8::TryCatch try_catch(isolate); v8::TryCatch try_catch(isolate);
v8::Isolate::DisallowJavascriptExecutionScope scope( v8::Isolate::DisallowJavascriptExecutionScope scope(
isolate, v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE); isolate, v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE);
v8::Local<v8::String> name = v8::Local<v8::String> name = v8::String::NewFromUtf8Literal(isolate, "[");
v8::String::NewFromUtf8(isolate, "[", v8::NewStringType::kNormal)
.ToLocalChecked();
if (object->IsFunction()) { if (object->IsFunction()) {
name = v8::String::Concat( name = v8::String::Concat(
isolate, name, isolate, name, v8::String::NewFromUtf8Literal(isolate, "Function"));
v8::String::NewFromUtf8(isolate, "Function", v8::NewStringType::kNormal)
.ToLocalChecked());
v8::Local<v8::Value> fname = v8::Local<v8::Value> fname =
v8::Local<v8::Function>::Cast(object)->GetName(); v8::Local<v8::Function>::Cast(object)->GetName();
if (fname->IsString() && v8::Local<v8::String>::Cast(fname)->Length()) { if (fname->IsString() && v8::Local<v8::String>::Cast(fname)->Length()) {
name = v8::String::Concat( name = v8::String::Concat(isolate, name,
isolate, name, v8::String::NewFromUtf8Literal(isolate, " "));
v8::String::NewFromUtf8(isolate, " ", v8::NewStringType::kNormal)
.ToLocalChecked());
name = name =
v8::String::Concat(isolate, name, v8::Local<v8::String>::Cast(fname)); v8::String::Concat(isolate, name, v8::Local<v8::String>::Cast(fname));
name = v8::String::Concat( name = v8::String::Concat(isolate, name,
isolate, name, v8::String::NewFromUtf8Literal(isolate, "()"));
v8::String::NewFromUtf8(isolate, "()", v8::NewStringType::kNormal)
.ToLocalChecked());
} }
} else { } else {
name = v8::String::Concat(isolate, name, object->GetConstructorName()); name = v8::String::Concat(isolate, name, object->GetConstructorName());
} }
name = v8::String::Concat( name = v8::String::Concat(isolate, name,
isolate, name, v8::String::NewFromUtf8Literal(isolate, "]"));
v8::String::NewFromUtf8(isolate, "]", v8::NewStringType::kNormal)
.ToLocalChecked());
if (try_catch.HasCaught()) { if (try_catch.HasCaught()) {
return std::unique_ptr<base::Value>( return std::unique_ptr<base::Value>(
......
...@@ -15,10 +15,9 @@ namespace { ...@@ -15,10 +15,9 @@ namespace {
void GetBlobUuid(const v8::FunctionCallbackInfo<v8::Value>& args) { void GetBlobUuid(const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK_EQ(1, args.Length()); CHECK_EQ(1, args.Length());
blink::WebBlob blob = blink::WebBlob::FromV8Value(args[0]); blink::WebBlob blob = blink::WebBlob::FromV8Value(args[0]);
args.GetReturnValue().Set(v8::String::NewFromUtf8(args.GetIsolate(), args.GetReturnValue().Set(
blob.Uuid().Utf8().data(), v8::String::NewFromUtf8(args.GetIsolate(), blob.Uuid().Utf8().data())
v8::NewStringType::kNormal) .ToLocalChecked());
.ToLocalChecked());
} }
} // namespace } // namespace
......
...@@ -57,9 +57,7 @@ v8::Local<v8::Value> GetChildValue(v8::Local<v8::Object> value, ...@@ -57,9 +57,7 @@ v8::Local<v8::Value> GetChildValue(v8::Local<v8::Object> value,
v8::TryCatch try_catch(isolate); v8::TryCatch try_catch(isolate);
v8::Local<v8::String> key; v8::Local<v8::String> key;
v8::Local<v8::Value> child_value; v8::Local<v8::Value> child_value;
if (v8::String::NewFromUtf8(isolate, key_name.c_str(), if (v8::String::NewFromUtf8(isolate, key_name.c_str()).ToLocal(&key) &&
v8::NewStringType::kNormal)
.ToLocal(&key) &&
value->HasOwnProperty(context, key).FromMaybe(false) && value->HasOwnProperty(context, key).FromMaybe(false) &&
value->Get(context, key).ToLocal(&child_value)) { value->Get(context, key).ToLocal(&child_value)) {
return child_value; return child_value;
...@@ -89,8 +87,7 @@ void DisplaySourceCustomBindings::StartSession( ...@@ -89,8 +87,7 @@ void DisplaySourceCustomBindings::StartSession(
const int sink_id = sink_id_val.As<v8::Int32>()->Value(); const int sink_id = sink_id_val.As<v8::Int32>()->Value();
if (GetDisplaySession(sink_id)) { if (GetDisplaySession(sink_id)) {
isolate->ThrowException(v8::Exception::Error( isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(isolate, kSessionAlreadyStarted, v8::String::NewFromUtf8(isolate, kSessionAlreadyStarted)
v8::NewStringType::kNormal)
.ToLocalChecked())); .ToLocalChecked()));
return; return;
} }
...@@ -103,9 +100,7 @@ void DisplaySourceCustomBindings::StartSession( ...@@ -103,9 +100,7 @@ void DisplaySourceCustomBindings::StartSession(
if ((video_stream_val->IsNull() || video_stream_val->IsUndefined()) && if ((video_stream_val->IsNull() || video_stream_val->IsUndefined()) &&
(audio_stream_val->IsNull() || audio_stream_val->IsUndefined())) { (audio_stream_val->IsNull() || audio_stream_val->IsUndefined())) {
isolate->ThrowException(v8::Exception::Error( isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(isolate, kInvalidStreamArgs, v8::String::NewFromUtf8(isolate, kInvalidStreamArgs).ToLocalChecked()));
v8::NewStringType::kNormal)
.ToLocalChecked()));
return; return;
} }
...@@ -117,8 +112,7 @@ void DisplaySourceCustomBindings::StartSession( ...@@ -117,8 +112,7 @@ void DisplaySourceCustomBindings::StartSession(
.Component(); .Component();
if (video_track.IsNull()) { if (video_track.IsNull()) {
isolate->ThrowException(v8::Exception::Error( isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(isolate, kInvalidStreamArgs, v8::String::NewFromUtf8(isolate, kInvalidStreamArgs)
v8::NewStringType::kNormal)
.ToLocalChecked())); .ToLocalChecked()));
return; return;
} }
...@@ -129,8 +123,7 @@ void DisplaySourceCustomBindings::StartSession( ...@@ -129,8 +123,7 @@ void DisplaySourceCustomBindings::StartSession(
.Component(); .Component();
if (audio_track.IsNull()) { if (audio_track.IsNull()) {
isolate->ThrowException(v8::Exception::Error( isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(isolate, kInvalidStreamArgs, v8::String::NewFromUtf8(isolate, kInvalidStreamArgs)
v8::NewStringType::kNormal)
.ToLocalChecked())); .ToLocalChecked()));
return; return;
} }
...@@ -161,9 +154,7 @@ void DisplaySourceCustomBindings::StartSession( ...@@ -161,9 +154,7 @@ void DisplaySourceCustomBindings::StartSession(
DisplaySourceSessionFactory::CreateSession(session_params); DisplaySourceSessionFactory::CreateSession(session_params);
if (!session) { if (!session) {
isolate->ThrowException(v8::Exception::Error( isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(isolate, kErrorNotSupported, v8::String::NewFromUtf8(isolate, kErrorNotSupported).ToLocalChecked()));
v8::NewStringType::kNormal)
.ToLocalChecked()));
return; return;
} }
...@@ -194,10 +185,8 @@ void DisplaySourceCustomBindings::TerminateSession( ...@@ -194,10 +185,8 @@ void DisplaySourceCustomBindings::TerminateSession(
int sink_id = args[0].As<v8::Int32>()->Value(); int sink_id = args[0].As<v8::Int32>()->Value();
DisplaySourceSession* session = GetDisplaySession(sink_id); DisplaySourceSession* session = GetDisplaySession(sink_id);
if (!session) { if (!session) {
isolate->ThrowException( isolate->ThrowException(v8::Exception::Error(
v8::Exception::Error(v8::String::NewFromUtf8(isolate, kSessionNotFound, v8::String::NewFromUtf8(isolate, kSessionNotFound).ToLocalChecked()));
v8::NewStringType::kNormal)
.ToLocalChecked()));
return; return;
} }
...@@ -206,17 +195,14 @@ void DisplaySourceCustomBindings::TerminateSession( ...@@ -206,17 +195,14 @@ void DisplaySourceCustomBindings::TerminateSession(
if (state == DisplaySourceSession::Establishing) { if (state == DisplaySourceSession::Establishing) {
// 'session started' callback has not yet been invoked. // 'session started' callback has not yet been invoked.
// This session is not existing for the user. // This session is not existing for the user.
isolate->ThrowException( isolate->ThrowException(v8::Exception::Error(
v8::Exception::Error(v8::String::NewFromUtf8(isolate, kSessionNotFound, v8::String::NewFromUtf8(isolate, kSessionNotFound).ToLocalChecked()));
v8::NewStringType::kNormal)
.ToLocalChecked()));
return; return;
} }
if (state == DisplaySourceSession::Terminating) { if (state == DisplaySourceSession::Terminating) {
isolate->ThrowException(v8::Exception::Error( isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(isolate, kSessionAlreadyTerminating, v8::String::NewFromUtf8(isolate, kSessionAlreadyTerminating)
v8::NewStringType::kNormal)
.ToLocalChecked())); .ToLocalChecked()));
return; return;
} }
...@@ -245,8 +231,7 @@ void DisplaySourceCustomBindings::OnCallCompleted( ...@@ -245,8 +231,7 @@ void DisplaySourceCustomBindings::OnCallCompleted(
if (success) if (success)
callback_args[1] = v8::Null(isolate); callback_args[1] = v8::Null(isolate);
else else
callback_args[1] = v8::String::NewFromUtf8(isolate, error_message.c_str(), callback_args[1] = v8::String::NewFromUtf8(isolate, error_message.c_str())
v8::NewStringType::kNormal)
.ToLocalChecked(); .ToLocalChecked();
module_system->CallModuleMethodSafe("displaySource", "callCompletionCallback", module_system->CallModuleMethodSafe("displaySource", "callCompletionCallback",
......
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