Commit 5d6d0234 authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

Use V8AtomicString for strings used as property keys.

V8 always internalizes strings when doing property lookup, so this can only
save the work of heap-allocating a new string that will just be looked up
later, and likely already exists in the internalized string table (e.g.
because it is the key of a property, or because it occurs as a string literal).

Found mainly by searching for string literals passed to V8String. Other
similar cases may yet remain.

No perf measurement was done, but this seems like it's easily the nicer
thing to do in these cases.

Change-Id: Idd645a83495f5ec1323f3ce87548d0f2a16aca19
Reviewed-on: https://chromium-review.googlesource.com/598540Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491561}
parent 390899a3
...@@ -17,9 +17,9 @@ DictionaryIterator::DictionaryIterator(v8::Local<v8::Object> iterator, ...@@ -17,9 +17,9 @@ DictionaryIterator::DictionaryIterator(v8::Local<v8::Object> iterator,
v8::Isolate* isolate) v8::Isolate* isolate)
: isolate_(isolate), : isolate_(isolate),
iterator_(iterator), iterator_(iterator),
next_key_(V8String(isolate, "next")), next_key_(V8AtomicString(isolate, "next")),
done_key_(V8String(isolate, "done")), done_key_(V8AtomicString(isolate, "done")),
value_key_(V8String(isolate, "value")), value_key_(V8AtomicString(isolate, "value")),
done_(false) { done_(false) {
DCHECK(!iterator.IsEmpty()); DCHECK(!iterator.IsEmpty());
} }
......
...@@ -351,9 +351,9 @@ struct NativeValueTraits<IDLSequence<T>> ...@@ -351,9 +351,9 @@ struct NativeValueTraits<IDLSequence<T>>
if (exception_state.HadException()) if (exception_state.HadException())
return; return;
v8::Local<v8::String> next_key = V8String(isolate, "next"); v8::Local<v8::String> next_key = V8AtomicString(isolate, "next");
v8::Local<v8::String> value_key = V8String(isolate, "value"); v8::Local<v8::String> value_key = V8AtomicString(isolate, "value");
v8::Local<v8::String> done_key = V8String(isolate, "done"); v8::Local<v8::String> done_key = V8AtomicString(isolate, "done");
v8::Local<v8::Context> context = isolate->GetCurrentContext(); v8::Local<v8::Context> context = isolate->GetCurrentContext();
while (true) { while (true) {
v8::Local<v8::Value> next; v8::Local<v8::Value> next;
......
...@@ -164,7 +164,7 @@ V0CustomElementConstructorBuilder::RetrieveCallback(const char* name) { ...@@ -164,7 +164,7 @@ V0CustomElementConstructorBuilder::RetrieveCallback(const char* name) {
v8::Local<v8::Value> value; v8::Local<v8::Value> value;
if (!prototype_ if (!prototype_
->Get(script_state_->GetContext(), ->Get(script_state_->GetContext(),
V8String(script_state_->GetIsolate(), name)) V8AtomicString(script_state_->GetIsolate(), name))
.ToLocal(&value) || .ToLocal(&value) ||
!value->IsFunction()) !value->IsFunction())
return v8::MaybeLocal<v8::Function>(); return v8::MaybeLocal<v8::Function>();
...@@ -215,7 +215,7 @@ bool V0CustomElementConstructorBuilder::CreateConstructor( ...@@ -215,7 +215,7 @@ bool V0CustomElementConstructorBuilder::CreateConstructor(
constructor_->SetName(v8_type->IsNull() ? v8_tag_name constructor_->SetName(v8_type->IsNull() ? v8_tag_name
: v8_type.As<v8::String>()); : v8_type.As<v8::String>());
v8::Local<v8::String> prototype_key = V8String(isolate, "prototype"); v8::Local<v8::String> prototype_key = V8AtomicString(isolate, "prototype");
if (!V8CallBoolean(constructor_->HasOwnProperty(context, prototype_key))) if (!V8CallBoolean(constructor_->HasOwnProperty(context, prototype_key)))
return false; return false;
// This sets the property *value*; calling Set is safe because // This sets the property *value*; calling Set is safe because
...@@ -231,7 +231,8 @@ bool V0CustomElementConstructorBuilder::CreateConstructor( ...@@ -231,7 +231,8 @@ bool V0CustomElementConstructorBuilder::CreateConstructor(
v8::PropertyAttribute(v8::ReadOnly | v8::DontEnum | v8::DontDelete)))) v8::PropertyAttribute(v8::ReadOnly | v8::DontEnum | v8::DontDelete))))
return false; return false;
v8::Local<v8::String> constructor_key = V8String(isolate, "constructor"); v8::Local<v8::String> constructor_key =
V8AtomicString(isolate, "constructor");
v8::Local<v8::Value> constructor_prototype; v8::Local<v8::Value> constructor_prototype;
if (!prototype_->Get(context, constructor_key) if (!prototype_->Get(context, constructor_key)
.ToLocal(&constructor_prototype)) .ToLocal(&constructor_prototype))
...@@ -244,7 +245,7 @@ bool V0CustomElementConstructorBuilder::CreateConstructor( ...@@ -244,7 +245,7 @@ bool V0CustomElementConstructorBuilder::CreateConstructor(
V8PrivateProperty::GetCustomElementIsInterfacePrototypeObject(isolate).Set( V8PrivateProperty::GetCustomElementIsInterfacePrototypeObject(isolate).Set(
prototype_, v8::True(isolate)); prototype_, v8::True(isolate));
if (!V8CallBoolean(prototype_->DefineOwnProperty( if (!V8CallBoolean(prototype_->DefineOwnProperty(
context, V8String(isolate, "constructor"), constructor_, context, V8AtomicString(isolate, "constructor"), constructor_,
v8::DontEnum))) v8::DontEnum)))
return false; return false;
...@@ -267,7 +268,8 @@ bool V0CustomElementConstructorBuilder::PrototypeIsValid( ...@@ -267,7 +268,8 @@ bool V0CustomElementConstructorBuilder::PrototypeIsValid(
v8::PropertyAttribute property_attribute; v8::PropertyAttribute property_attribute;
if (!prototype_ if (!prototype_
->GetPropertyAttributes(context, V8String(isolate, "constructor")) ->GetPropertyAttributes(context,
V8AtomicString(isolate, "constructor"))
.To(&property_attribute) || .To(&property_attribute) ||
(property_attribute & v8::DontDelete)) { (property_attribute & v8::DontDelete)) {
V0CustomElementException::ThrowException( V0CustomElementException::ThrowException(
......
...@@ -181,20 +181,21 @@ inline void V8SetReturnValue(const CallbackInfo& callback_info, ...@@ -181,20 +181,21 @@ inline void V8SetReturnValue(const CallbackInfo& callback_info,
DCHECK(descriptor.has_writable()); DCHECK(descriptor.has_writable());
v8::Local<v8::Object> desc = v8::Object::New(callback_info.GetIsolate()); v8::Local<v8::Object> desc = v8::Object::New(callback_info.GetIsolate());
desc->Set(callback_info.GetIsolate()->GetCurrentContext(), desc->Set(callback_info.GetIsolate()->GetCurrentContext(),
V8String(callback_info.GetIsolate(), "configurable"), V8AtomicString(callback_info.GetIsolate(), "configurable"),
ToV8(descriptor.configurable(), callback_info.Holder(), ToV8(descriptor.configurable(), callback_info.Holder(),
callback_info.GetIsolate())) callback_info.GetIsolate()))
.ToChecked(); .ToChecked();
desc->Set(callback_info.GetIsolate()->GetCurrentContext(), desc->Set(callback_info.GetIsolate()->GetCurrentContext(),
V8String(callback_info.GetIsolate(), "enumerable"), V8AtomicString(callback_info.GetIsolate(), "enumerable"),
ToV8(descriptor.enumerable(), callback_info.Holder(), ToV8(descriptor.enumerable(), callback_info.Holder(),
callback_info.GetIsolate())) callback_info.GetIsolate()))
.ToChecked(); .ToChecked();
desc->Set(callback_info.GetIsolate()->GetCurrentContext(), desc->Set(callback_info.GetIsolate()->GetCurrentContext(),
V8String(callback_info.GetIsolate(), "value"), descriptor.value()) V8AtomicString(callback_info.GetIsolate(), "value"),
descriptor.value())
.ToChecked(); .ToChecked();
desc->Set(callback_info.GetIsolate()->GetCurrentContext(), desc->Set(callback_info.GetIsolate()->GetCurrentContext(),
V8String(callback_info.GetIsolate(), "writable"), V8AtomicString(callback_info.GetIsolate(), "writable"),
ToV8(descriptor.writable(), callback_info.Holder(), ToV8(descriptor.writable(), callback_info.Holder(),
callback_info.GetIsolate())) callback_info.GetIsolate()))
.ToChecked(); .ToChecked();
......
...@@ -13,10 +13,11 @@ v8::Local<v8::Object> V8IteratorResultValue(v8::Isolate* isolate, ...@@ -13,10 +13,11 @@ v8::Local<v8::Object> V8IteratorResultValue(v8::Isolate* isolate,
if (value.IsEmpty()) if (value.IsEmpty())
value = v8::Undefined(isolate); value = v8::Undefined(isolate);
if (!V8CallBoolean(result->CreateDataProperty( if (!V8CallBoolean(result->CreateDataProperty(
isolate->GetCurrentContext(), V8String(isolate, "done"), isolate->GetCurrentContext(), V8AtomicString(isolate, "done"),
v8::Boolean::New(isolate, done))) || v8::Boolean::New(isolate, done))) ||
!V8CallBoolean(result->CreateDataProperty( !V8CallBoolean(
isolate->GetCurrentContext(), V8String(isolate, "value"), value))) result->CreateDataProperty(isolate->GetCurrentContext(),
V8AtomicString(isolate, "value"), value)))
return v8::Local<v8::Object>(); return v8::Local<v8::Object>();
return result; return result;
} }
...@@ -26,13 +27,13 @@ v8::MaybeLocal<v8::Value> V8UnpackIteratorResult(ScriptState* script_state, ...@@ -26,13 +27,13 @@ v8::MaybeLocal<v8::Value> V8UnpackIteratorResult(ScriptState* script_state,
bool* done) { bool* done) {
v8::MaybeLocal<v8::Value> maybe_value = v8::MaybeLocal<v8::Value> maybe_value =
result->Get(script_state->GetContext(), result->Get(script_state->GetContext(),
V8String(script_state->GetIsolate(), "value")); V8AtomicString(script_state->GetIsolate(), "value"));
if (maybe_value.IsEmpty()) if (maybe_value.IsEmpty())
return maybe_value; return maybe_value;
v8::Local<v8::Value> done_value; v8::Local<v8::Value> done_value;
if (!result if (!result
->Get(script_state->GetContext(), ->Get(script_state->GetContext(),
V8String(script_state->GetIsolate(), "done")) V8AtomicString(script_state->GetIsolate(), "done"))
.ToLocal(&done_value) || .ToLocal(&done_value) ||
!done_value->BooleanValue(script_state->GetContext()).To(done)) { !done_value->BooleanValue(script_state->GetContext()).To(done)) {
return v8::MaybeLocal<v8::Value>(); return v8::MaybeLocal<v8::Value>();
......
...@@ -62,9 +62,9 @@ void V8ObjectBuilder::AddInternal(const StringView& name, ...@@ -62,9 +62,9 @@ void V8ObjectBuilder::AddInternal(const StringView& name,
return; return;
if (value.IsEmpty() || if (value.IsEmpty() ||
object_ object_
->CreateDataProperty(script_state_->GetContext(), ->CreateDataProperty(
V8String(script_state_->GetIsolate(), name), script_state_->GetContext(),
value) V8AtomicString(script_state_->GetIsolate(), name), value)
.IsNothing()) .IsNothing())
object_.Clear(); object_.Clear();
} }
......
...@@ -219,7 +219,7 @@ static void CreateFunctionPropertyWithData(v8::Local<v8::Context> context, ...@@ -219,7 +219,7 @@ static void CreateFunctionPropertyWithData(v8::Local<v8::Context> context,
v8::ConstructorBehavior::kThrow) v8::ConstructorBehavior::kThrow)
.ToLocal(&to_string_function)) .ToLocal(&to_string_function))
CreateDataProperty(context, func, CreateDataProperty(context, func,
V8String(context->GetIsolate(), "toString"), V8AtomicString(context->GetIsolate(), "toString"),
to_string_function); to_string_function);
CreateDataProperty(context, object, func_name, func); CreateDataProperty(context, object, func_name, func);
} }
...@@ -405,21 +405,25 @@ void ThreadDebugger::GetEventListenersCallback( ...@@ -405,21 +405,25 @@ void ThreadDebugger::GetEventListenersCallback(
current_event_type = info.event_type; current_event_type = info.event_type;
listeners = v8::Array::New(isolate); listeners = v8::Array::New(isolate);
output_index = 0; output_index = 0;
CreateDataProperty(context, result, V8String(isolate, current_event_type), CreateDataProperty(context, result,
V8AtomicString(isolate, current_event_type),
listeners); listeners);
} }
v8::Local<v8::Object> listener_object = v8::Object::New(isolate); v8::Local<v8::Object> listener_object = v8::Object::New(isolate);
CreateDataProperty(context, listener_object, V8String(isolate, "listener"),
info.handler);
CreateDataProperty(context, listener_object, CreateDataProperty(context, listener_object,
V8String(isolate, "useCapture"), V8AtomicString(isolate, "listener"), info.handler);
CreateDataProperty(context, listener_object,
V8AtomicString(isolate, "useCapture"),
v8::Boolean::New(isolate, info.use_capture)); v8::Boolean::New(isolate, info.use_capture));
CreateDataProperty(context, listener_object, V8String(isolate, "passive"), CreateDataProperty(context, listener_object,
V8AtomicString(isolate, "passive"),
v8::Boolean::New(isolate, info.passive)); v8::Boolean::New(isolate, info.passive));
CreateDataProperty(context, listener_object, V8String(isolate, "once"), CreateDataProperty(context, listener_object,
V8AtomicString(isolate, "once"),
v8::Boolean::New(isolate, info.once)); v8::Boolean::New(isolate, info.once));
CreateDataProperty(context, listener_object, V8String(isolate, "type"), CreateDataProperty(context, listener_object,
V8AtomicString(isolate, "type"),
V8String(isolate, current_event_type)); V8String(isolate, current_event_type));
CreateDataPropertyInArray(context, listeners, output_index++, CreateDataPropertyInArray(context, listeners, output_index++,
listener_object); listener_object);
......
...@@ -110,7 +110,7 @@ void AnimationWorkletGlobalScope::registerAnimator( ...@@ -110,7 +110,7 @@ void AnimationWorkletGlobalScope::registerAnimator(
v8::Local<v8::Function>::Cast(ctorValue.V8Value()); v8::Local<v8::Function>::Cast(ctorValue.V8Value());
v8::Local<v8::Value> prototypeValue; v8::Local<v8::Value> prototypeValue;
if (!constructor->Get(context, V8String(isolate, "prototype")) if (!constructor->Get(context, V8AtomicString(isolate, "prototype"))
.ToLocal(&prototypeValue)) .ToLocal(&prototypeValue))
return; return;
...@@ -129,7 +129,7 @@ void AnimationWorkletGlobalScope::registerAnimator( ...@@ -129,7 +129,7 @@ void AnimationWorkletGlobalScope::registerAnimator(
v8::Local<v8::Object> prototype = v8::Local<v8::Object>::Cast(prototypeValue); v8::Local<v8::Object> prototype = v8::Local<v8::Object>::Cast(prototypeValue);
v8::Local<v8::Value> animateValue; v8::Local<v8::Value> animateValue;
if (!prototype->Get(context, V8String(isolate, "animate")) if (!prototype->Get(context, V8AtomicString(isolate, "animate"))
.ToLocal(&animateValue)) .ToLocal(&animateValue))
return; return;
......
...@@ -90,7 +90,7 @@ void PaintWorkletGlobalScope::registerPaint(const String& name, ...@@ -90,7 +90,7 @@ void PaintWorkletGlobalScope::registerPaint(const String& name,
v8::Local<v8::Function>::Cast(ctor_value.V8Value()); v8::Local<v8::Function>::Cast(ctor_value.V8Value());
v8::Local<v8::Value> input_properties_value; v8::Local<v8::Value> input_properties_value;
if (!constructor->Get(context, V8String(isolate, "inputProperties")) if (!constructor->Get(context, V8AtomicString(isolate, "inputProperties"))
.ToLocal(&input_properties_value)) .ToLocal(&input_properties_value))
return; return;
...@@ -120,7 +120,7 @@ void PaintWorkletGlobalScope::registerPaint(const String& name, ...@@ -120,7 +120,7 @@ void PaintWorkletGlobalScope::registerPaint(const String& name,
Vector<CSSSyntaxDescriptor> input_argument_types; Vector<CSSSyntaxDescriptor> input_argument_types;
if (RuntimeEnabledFeatures::CSSPaintAPIArgumentsEnabled()) { if (RuntimeEnabledFeatures::CSSPaintAPIArgumentsEnabled()) {
v8::Local<v8::Value> input_argument_type_values; v8::Local<v8::Value> input_argument_type_values;
if (!constructor->Get(context, V8String(isolate, "inputArguments")) if (!constructor->Get(context, V8AtomicString(isolate, "inputArguments"))
.ToLocal(&input_argument_type_values)) .ToLocal(&input_argument_type_values))
return; return;
...@@ -145,7 +145,7 @@ void PaintWorkletGlobalScope::registerPaint(const String& name, ...@@ -145,7 +145,7 @@ void PaintWorkletGlobalScope::registerPaint(const String& name,
// Parse 'alpha' AKA hasAlpha property. // Parse 'alpha' AKA hasAlpha property.
v8::Local<v8::Value> alpha_value; v8::Local<v8::Value> alpha_value;
if (!constructor->Get(context, V8String(isolate, "alpha")) if (!constructor->Get(context, V8AtomicString(isolate, "alpha"))
.ToLocal(&alpha_value)) .ToLocal(&alpha_value))
return; return;
if (!IsUndefinedOrNull(alpha_value) && !alpha_value->IsBoolean()) { if (!IsUndefinedOrNull(alpha_value) && !alpha_value->IsBoolean()) {
...@@ -158,7 +158,7 @@ void PaintWorkletGlobalScope::registerPaint(const String& name, ...@@ -158,7 +158,7 @@ void PaintWorkletGlobalScope::registerPaint(const String& name,
: true; : true;
v8::Local<v8::Value> prototype_value; v8::Local<v8::Value> prototype_value;
if (!constructor->Get(context, V8String(isolate, "prototype")) if (!constructor->Get(context, V8AtomicString(isolate, "prototype"))
.ToLocal(&prototype_value)) .ToLocal(&prototype_value))
return; return;
...@@ -178,7 +178,7 @@ void PaintWorkletGlobalScope::registerPaint(const String& name, ...@@ -178,7 +178,7 @@ void PaintWorkletGlobalScope::registerPaint(const String& name,
v8::Local<v8::Object>::Cast(prototype_value); v8::Local<v8::Object>::Cast(prototype_value);
v8::Local<v8::Value> paint_value; v8::Local<v8::Value> paint_value;
if (!prototype->Get(context, V8String(isolate, "paint")) if (!prototype->Get(context, V8AtomicString(isolate, "paint"))
.ToLocal(&paint_value)) .ToLocal(&paint_value))
return; return;
......
...@@ -83,7 +83,7 @@ void AudioWorkletGlobalScope::registerProcessor( ...@@ -83,7 +83,7 @@ void AudioWorkletGlobalScope::registerProcessor(
v8::Local<v8::Value> prototype_value_local; v8::Local<v8::Value> prototype_value_local;
bool prototype_extracted = bool prototype_extracted =
class_definition_local->Get(context, V8String(isolate, "prototype")) class_definition_local->Get(context, V8AtomicString(isolate, "prototype"))
.ToLocal(&prototype_value_local); .ToLocal(&prototype_value_local);
DCHECK(prototype_extracted); DCHECK(prototype_extracted);
...@@ -92,7 +92,7 @@ void AudioWorkletGlobalScope::registerProcessor( ...@@ -92,7 +92,7 @@ void AudioWorkletGlobalScope::registerProcessor(
v8::Local<v8::Value> process_value_local; v8::Local<v8::Value> process_value_local;
bool process_extracted = bool process_extracted =
prototype_object_local->Get(context, V8String(isolate, "process")) prototype_object_local->Get(context, V8AtomicString(isolate, "process"))
.ToLocal(&process_value_local); .ToLocal(&process_value_local);
DCHECK(process_extracted); DCHECK(process_extracted);
...@@ -121,8 +121,8 @@ void AudioWorkletGlobalScope::registerProcessor( ...@@ -121,8 +121,8 @@ void AudioWorkletGlobalScope::registerProcessor(
v8::Local<v8::Value> parameter_descriptors_value_local; v8::Local<v8::Value> parameter_descriptors_value_local;
bool did_get_parameter_descriptor = bool did_get_parameter_descriptor =
class_definition_local->Get(context, class_definition_local
V8String(isolate, "parameterDescriptors")) ->Get(context, V8AtomicString(isolate, "parameterDescriptors"))
.ToLocal(&parameter_descriptors_value_local); .ToLocal(&parameter_descriptors_value_local);
// If parameterDescriptor() is parsed and has a valid value, create a vector // If parameterDescriptor() is parsed and has a valid value, create a vector
......
...@@ -148,7 +148,7 @@ v8::Local<v8::Object> V8PerContextData::PrototypeForType( ...@@ -148,7 +148,7 @@ v8::Local<v8::Object> V8PerContextData::PrototypeForType(
if (constructor.IsEmpty()) if (constructor.IsEmpty())
return v8::Local<v8::Object>(); return v8::Local<v8::Object>();
v8::Local<v8::Value> prototype_value; v8::Local<v8::Value> prototype_value;
if (!constructor->Get(GetContext(), V8String(isolate_, "prototype")) if (!constructor->Get(GetContext(), V8AtomicString(isolate_, "prototype"))
.ToLocal(&prototype_value) || .ToLocal(&prototype_value) ||
!prototype_value->IsObject()) !prototype_value->IsObject())
return v8::Local<v8::Object>(); return v8::Local<v8::Object>();
......
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