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