Commit 52ab610b authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[cleanup] Store ES6 class' start/end positions as one property.

... containing Tuple2 value instead of two properties. This CL reduces the
number of property queries in FunctionToString to one and it is memory-neutral.

Change-Id: Ia6fa267f3e5b6670013f1da3e03cd70bf24dd65a
Reviewed-on: https://chromium-review.googlesource.com/730744Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48926}
parent b6687e31
...@@ -214,8 +214,7 @@ ...@@ -214,8 +214,7 @@
V(call_site_frame_index_symbol) \ V(call_site_frame_index_symbol) \
V(console_context_id_symbol) \ V(console_context_id_symbol) \
V(console_context_name_symbol) \ V(console_context_name_symbol) \
V(class_end_position_symbol) \ V(class_positions_symbol) \
V(class_start_position_symbol) \
V(detailed_stack_trace_symbol) \ V(detailed_stack_trace_symbol) \
V(elements_transition_symbol) \ V(elements_transition_symbol) \
V(error_end_pos_symbol) \ V(error_end_pos_symbol) \
......
...@@ -13118,16 +13118,16 @@ Handle<String> JSFunction::ToString(Handle<JSFunction> function) { ...@@ -13118,16 +13118,16 @@ Handle<String> JSFunction::ToString(Handle<JSFunction> function) {
} }
// Check if we should print {function} as a class. // Check if we should print {function} as a class.
Handle<Object> class_start_position = JSReceiver::GetDataProperty( Handle<Object> maybe_class_positions = JSReceiver::GetDataProperty(
function, isolate->factory()->class_start_position_symbol()); function, isolate->factory()->class_positions_symbol());
if (class_start_position->IsSmi()) { if (maybe_class_positions->IsTuple2()) {
Handle<Object> class_end_position = JSReceiver::GetDataProperty( Tuple2* class_positions = Tuple2::cast(*maybe_class_positions);
function, isolate->factory()->class_end_position_symbol()); int start_position = Smi::ToInt(class_positions->value1());
int end_position = Smi::ToInt(class_positions->value2());
Handle<String> script_source( Handle<String> script_source(
String::cast(Script::cast(shared_info->script())->source()), isolate); String::cast(Script::cast(shared_info->script())->source()), isolate);
return isolate->factory()->NewSubString( return isolate->factory()->NewSubString(script_source, start_position,
script_source, Handle<Smi>::cast(class_start_position)->value(), end_position);
Handle<Smi>::cast(class_end_position)->value());
} }
// Check if we have source code for the {function}. // Check if we have source code for the {function}.
......
...@@ -166,18 +166,18 @@ static MaybeHandle<Object> DefineClass(Isolate* isolate, ...@@ -166,18 +166,18 @@ static MaybeHandle<Object> DefineClass(Isolate* isolate,
constructor, DONT_ENUM); constructor, DONT_ENUM);
// Install private properties that are used to construct the FunctionToString. // Install private properties that are used to construct the FunctionToString.
RETURN_ON_EXCEPTION( {
isolate, Handle<Smi> start(Smi::FromInt(start_position), isolate);
Object::SetProperty( Handle<Smi> end(Smi::FromInt(end_position), isolate);
constructor, isolate->factory()->class_start_position_symbol(), Handle<Tuple2> class_positions =
handle(Smi::FromInt(start_position), isolate), LanguageMode::kStrict), isolate->factory()->NewTuple2(start, end, NOT_TENURED);
Object); RETURN_ON_EXCEPTION(
RETURN_ON_EXCEPTION( isolate,
isolate, Object::SetProperty(constructor,
Object::SetProperty( isolate->factory()->class_positions_symbol(),
constructor, isolate->factory()->class_end_position_symbol(), class_positions, LanguageMode::kStrict),
handle(Smi::FromInt(end_position), isolate), LanguageMode::kStrict), Object);
Object); }
// Caller already has access to constructor, so return the prototype. // Caller already has access to constructor, so return the prototype.
return prototype; return prototype;
......
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