Chromium Code Reviews| Index: src/api-natives.cc |
| diff --git a/src/api-natives.cc b/src/api-natives.cc |
| index 3fe59e293d3ff2d1d8d3b3fd688897334e6e95c8..e991be2dfa48c06cdcb63a1a860c5ede003b25d1 100644 |
| --- a/src/api-natives.cc |
| +++ b/src/api-natives.cc |
| @@ -395,6 +395,28 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate, |
| return result; |
| } |
| +namespace { |
| +MaybeHandle<Object> GetInstancePrototype(Isolate* isolate, |
| + Object* function_template) { |
| + // Enter a new scope. Recursion could otherwise create a lot of handles. |
| + HandleScope scope(isolate); |
| + Handle<JSFunction> parent_instance; |
| + ASSIGN_RETURN_ON_EXCEPTION( |
| + isolate, parent_instance, |
| + InstantiateFunction( |
| + isolate, |
| + handle(FunctionTemplateInfo::cast(function_template), isolate)), |
| + JSFunction); |
| + Handle<Object> instance_prototype; |
| + // TODO(dcarney): decide what to do here. |
|
jochen (gone - plz use gerrit)
2016/11/25 06:46:13
maybe TODO(cbruni)?
|
| + ASSIGN_RETURN_ON_EXCEPTION( |
| + isolate, instance_prototype, |
| + JSObject::GetProperty(parent_instance, |
| + isolate->factory()->prototype_string()), |
| + JSFunction); |
| + return scope.CloseAndEscape(instance_prototype); |
| +} |
| +} // namespace |
| MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate, |
| Handle<FunctionTemplateInfo> data, |
| @@ -406,11 +428,18 @@ MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate, |
| return Handle<JSFunction>::cast(result); |
| } |
| } |
| - Handle<JSObject> prototype; |
| + Handle<Object> prototype; |
| if (!data->remove_prototype()) { |
| Object* prototype_templ = data->prototype_template(); |
| if (prototype_templ->IsUndefined(isolate)) { |
| - prototype = isolate->factory()->NewJSObject(isolate->object_function()); |
| + Object* protoype_provider_templ = data->prototype_provider_template(); |
| + if (protoype_provider_templ->IsUndefined(isolate)) { |
| + prototype = isolate->factory()->NewJSObject(isolate->object_function()); |
| + } else { |
| + ASSIGN_RETURN_ON_EXCEPTION( |
| + isolate, prototype, |
| + GetInstancePrototype(isolate, protoype_provider_templ), JSFunction); |
| + } |
| } else { |
| ASSIGN_RETURN_ON_EXCEPTION( |
| isolate, prototype, |
| @@ -422,22 +451,12 @@ MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate, |
| } |
| Object* parent = data->parent_template(); |
| if (!parent->IsUndefined(isolate)) { |
| - // Enter a new scope. Recursion could otherwise create a lot of handles. |
| - HandleScope scope(isolate); |
| - Handle<JSFunction> parent_instance; |
| - ASSIGN_RETURN_ON_EXCEPTION( |
| - isolate, parent_instance, |
| - InstantiateFunction( |
| - isolate, handle(FunctionTemplateInfo::cast(parent), isolate)), |
| - JSFunction); |
| - // TODO(dcarney): decide what to do here. |
| Handle<Object> parent_prototype; |
| - ASSIGN_RETURN_ON_EXCEPTION( |
| - isolate, parent_prototype, |
| - JSObject::GetProperty(parent_instance, |
| - isolate->factory()->prototype_string()), |
| - JSFunction); |
| - JSObject::ForceSetPrototype(prototype, parent_prototype); |
| + ASSIGN_RETURN_ON_EXCEPTION(isolate, parent_prototype, |
| + GetInstancePrototype(isolate, parent), |
| + JSFunction); |
| + JSObject::ForceSetPrototype(Handle<JSObject>::cast(prototype), |
| + parent_prototype); |
| } |
| } |
| Handle<JSFunction> function = ApiNatives::CreateApiFunction( |
| @@ -606,7 +625,7 @@ Handle<JSFunction> ApiNatives::CreateApiFunction( |
| if (prototype->IsTheHole(isolate)) { |
| prototype = isolate->factory()->NewFunctionPrototype(result); |
| - } else { |
| + } else if (obj->prototype_provider_template()->IsUndefined(isolate)) { |
| JSObject::AddProperty(Handle<JSObject>::cast(prototype), |
| isolate->factory()->constructor_string(), result, |
| DONT_ENUM); |