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