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