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

[api] Avoid using v8::NewFromUtf8Lilteral if possible

Change-Id: I4e9a70339a59845c33432fe6a8dcaacebd2046a6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2237631Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68278}
parent 0ad867db
......@@ -120,8 +120,7 @@
* v8::ObjectTemplate::New(isolate);
* object_template->SetInternalFieldCount(
* kV8EmbedderWrapperObjectIndex + 1);
* object_template->Set(
v8::String::NewFromUtf8Literal(isolate, "method"), method_template);
* object_template->Set(isolate, "method", method_template);
*
* // Instantiate the wrapper JS object.
* v8::Local<v8::Object> object =
......
......@@ -108,21 +108,15 @@ v8::Local<v8::Context> CreateShellContext(v8::Isolate* isolate) {
// Create a template for the global object.
v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
// Bind the global 'print' function to the C++ Print callback.
global->Set(v8::String::NewFromUtf8Literal(isolate, "print"),
v8::FunctionTemplate::New(isolate, Print));
global->Set(isolate, "print", v8::FunctionTemplate::New(isolate, Print));
// Bind the global 'read' function to the C++ Read callback.
global->Set(v8::String::NewFromUtf8Literal(isolate, "read"),
v8::FunctionTemplate::New(isolate, Read));
global->Set(isolate, "read", v8::FunctionTemplate::New(isolate, Read));
// Bind the global 'load' function to the C++ Load callback.
global->Set(v8::String::NewFromUtf8Literal(isolate, "load"),
v8::FunctionTemplate::New(isolate, Load));
global->Set(isolate, "load", v8::FunctionTemplate::New(isolate, Load));
// Bind the 'quit' function
global->Set(v8::String::NewFromUtf8Literal(isolate, "quit"),
v8::FunctionTemplate::New(isolate, Quit));
global->Set(isolate, "quit", v8::FunctionTemplate::New(isolate, Quit));
// Bind the 'version' function
global->Set(v8::String::NewFromUtf8Literal(isolate, "version"),
v8::FunctionTemplate::New(isolate, Version));
global->Set(isolate, "version", v8::FunctionTemplate::New(isolate, Version));
return v8::Context::New(isolate, NULL, global);
}
......
......@@ -761,20 +761,18 @@ char* Shell::ReadCharsFromTcpPort(const char* name, int* size_out) {
void Shell::AddOSMethods(Isolate* isolate, Local<ObjectTemplate> os_templ) {
if (options.enable_os_system) {
os_templ->Set(String::NewFromUtf8Literal(isolate, "system"),
FunctionTemplate::New(isolate, System));
os_templ->Set(isolate, "system", FunctionTemplate::New(isolate, System));
}
os_templ->Set(String::NewFromUtf8Literal(isolate, "chdir"),
os_templ->Set(isolate, "chdir",
FunctionTemplate::New(isolate, ChangeDirectory));
os_templ->Set(String::NewFromUtf8Literal(isolate, "setenv"),
os_templ->Set(isolate, "setenv",
FunctionTemplate::New(isolate, SetEnvironment));
os_templ->Set(String::NewFromUtf8Literal(isolate, "unsetenv"),
os_templ->Set(isolate, "unsetenv",
FunctionTemplate::New(isolate, UnsetEnvironment));
os_templ->Set(String::NewFromUtf8Literal(isolate, "umask"),
FunctionTemplate::New(isolate, SetUMask));
os_templ->Set(String::NewFromUtf8Literal(isolate, "mkdirp"),
os_templ->Set(isolate, "umask", FunctionTemplate::New(isolate, SetUMask));
os_templ->Set(isolate, "mkdirp",
FunctionTemplate::New(isolate, MakeDirectory));
os_templ->Set(String::NewFromUtf8Literal(isolate, "rmdir"),
os_templ->Set(isolate, "rmdir",
FunctionTemplate::New(isolate, RemoveDirectory));
}
......
......@@ -4938,7 +4938,7 @@ TEST(Regress357137) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope hscope(isolate);
v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
global->Set(v8::String::NewFromUtf8Literal(isolate, "interrupt"),
global->Set(isolate, "interrupt",
v8::FunctionTemplate::New(isolate, RequestInterrupt));
v8::Local<v8::Context> context = v8::Context::New(isolate, nullptr, global);
CHECK(!context.IsEmpty());
......@@ -5327,8 +5327,7 @@ TEST(MessageObjectLeak) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
global->Set(v8::String::NewFromUtf8Literal(isolate, "check"),
v8::FunctionTemplate::New(isolate, CheckLeak));
global->Set(isolate, "check", v8::FunctionTemplate::New(isolate, CheckLeak));
v8::Local<v8::Context> context = v8::Context::New(isolate, nullptr, global);
v8::Context::Scope cscope(context);
......
......@@ -446,8 +446,7 @@ TEST(TracedGlobalToJSApiObjectWithModifiedMapSurvivesScavenge) {
// Create an API object which does not have the same map as constructor.
auto function_template = FunctionTemplate::New(isolate);
auto instance_t = function_template->InstanceTemplate();
instance_t->Set(v8::String::NewFromUtf8Literal(isolate, "a"),
v8::Number::New(isolate, 10));
instance_t->Set(isolate, "a", v8::Number::New(isolate, 10));
auto function =
function_template->GetFunction(context.local()).ToLocalChecked();
auto i = function->NewInstance(context.local()).ToLocalChecked();
......@@ -469,10 +468,8 @@ TEST(TracedGlobalTOJsApiObjectWithElementsSurvivesScavenge) {
// Create an API object which has elements.
auto function_template = FunctionTemplate::New(isolate);
auto instance_t = function_template->InstanceTemplate();
instance_t->Set(v8::String::NewFromUtf8Literal(isolate, "1"),
v8::Number::New(isolate, 10));
instance_t->Set(v8::String::NewFromUtf8Literal(isolate, "2"),
v8::Number::New(isolate, 10));
instance_t->Set(isolate, "1", v8::Number::New(isolate, 10));
instance_t->Set(isolate, "2", v8::Number::New(isolate, 10));
auto function =
function_template->GetFunction(context.local()).ToLocalChecked();
auto i = function->NewInstance(context.local()).ToLocalChecked();
......
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