Chromium Code Reviews| Index: src/factory.cc |
| diff --git a/src/factory.cc b/src/factory.cc |
| index 9323c2f1f03b02f6f80eeef070d142910cfbeb56..9ec4a3fa3f021c02553b3ebc9fb6febe0b6b5132 100644 |
| --- a/src/factory.cc |
| +++ b/src/factory.cc |
| @@ -1467,15 +1467,29 @@ Handle<JSFunction> Factory::CreateApiFunction( |
| result->shared()->set_construct_stub(*construct_stub); |
| result->shared()->DontAdaptArguments(); |
| - // Recursively copy parent templates' accessors, 'data' may be modified. |
| + // Recursively copy parent instance templates' accessors, |
| + // 'data' may be modified. |
| int max_number_of_additional_properties = 0; |
| + int max_number_of_static_properties = 0; |
| FunctionTemplateInfo* info = *obj; |
| while (true) { |
| - Object* props = info->property_accessors(); |
| - if (!props->IsUndefined()) { |
| - Handle<Object> props_handle(props, isolate()); |
| - NeanderArray props_array(props_handle); |
| - max_number_of_additional_properties += props_array.length(); |
| + if (!info->instance_template()->IsUndefined()) { |
| + Object* props = |
| + ObjectTemplateInfo::cast( |
| + info->instance_template())->property_accessors(); |
| + if (!props->IsUndefined()) { |
| + Handle<Object> props_handle(props, isolate()); |
| + NeanderArray props_array(props_handle); |
| + max_number_of_additional_properties += props_array.length(); |
| + } |
| + } |
| + if (!info->property_accessors()->IsUndefined()) { |
| + Object* props = info->property_accessors(); |
| + if (!props->IsUndefined()) { |
| + Handle<Object> props_handle(props, isolate()); |
| + NeanderArray props_array(props_handle); |
| + max_number_of_static_properties += props_array.length(); |
| + } |
| } |
| Object* parent = info->parent_template(); |
| if (parent->IsUndefined()) break; |
| @@ -1484,17 +1498,45 @@ Handle<JSFunction> Factory::CreateApiFunction( |
| Map::EnsureDescriptorSlack(map, max_number_of_additional_properties); |
| + // Use a temporary FixedArray to acculumate static accessors |
| + int valid_descriptors = 0; |
| + Handle<FixedArray> array; |
| + if (max_number_of_static_properties > 0) { |
| + array = NewFixedArray(max_number_of_static_properties); |
| + } |
| + |
| while (true) { |
| - Handle<Object> props = Handle<Object>(obj->property_accessors(), |
| - isolate()); |
| - if (!props->IsUndefined()) { |
| - Map::AppendCallbackDescriptors(map, props); |
| + // Install instance descriptors |
| + if (!obj->instance_template()->IsUndefined()) { |
| + Handle<ObjectTemplateInfo> instance = |
| + Handle<ObjectTemplateInfo>( |
| + ObjectTemplateInfo::cast(obj->instance_template()), isolate()); |
| + Handle<Object> props = Handle<Object>(instance->property_accessors(), |
| + isolate()); |
| + if (!props->IsUndefined()) { |
| + Map::AppendCallbackDescriptors(map, props); |
| + } |
| + } |
| + // Accumulate static accessors |
| + if (!obj->property_accessors()->IsUndefined()) { |
| + Handle<Object> props = Handle<Object>(obj->property_accessors(), |
| + isolate()); |
| + valid_descriptors = |
| + AccessorInfo::AppendUnique(props, array, valid_descriptors); |
| } |
| + // Climb parent chain |
| Handle<Object> parent = Handle<Object>(obj->parent_template(), isolate()); |
| if (parent->IsUndefined()) break; |
| obj = Handle<FunctionTemplateInfo>::cast(parent); |
| } |
| + // Install accumulated static accessors |
| + for (int i = 0; i < valid_descriptors; i++) { |
| + AccessorInfo* value = AccessorInfo::cast(array->get(i)); |
| + Handle<AccessorInfo> accessor(value, isolate()); |
|
Michael Starzinger
2013/09/03 14:00:57
nit: This can be simplified to just ...
Handle<Ac
|
| + SetAccessor(result, accessor); |
| + } |
| + |
| ASSERT(result->shared()->IsApiFunction()); |
| return result; |
| } |