Commit c8e5a1ad authored by Toon Verwaest's avatar Toon Verwaest

Install the constructor property on custom prototype before optimizing it as a prototype

BUG=
R=ishell@chromium.org

Review URL: https://codereview.chromium.org/725593002

Cr-Commit-Position: refs/heads/master@{#25328}
parent 78332973
...@@ -1308,12 +1308,11 @@ Handle<JSFunction> Factory::NewFunction(Handle<String> name, ...@@ -1308,12 +1308,11 @@ Handle<JSFunction> Factory::NewFunction(Handle<String> name,
} }
Handle<JSFunction> Factory::NewFunction(Handle<String> name, Handle<JSFunction> Factory::NewFunction(Handle<String> name, Handle<Code> code,
Handle<Code> code,
Handle<Object> prototype, Handle<Object> prototype,
InstanceType type, InstanceType type, int instance_size,
int instance_size, bool read_only_prototype,
bool read_only_prototype) { bool install_constructor) {
// Allocate the function // Allocate the function
Handle<JSFunction> function = NewFunction( Handle<JSFunction> function = NewFunction(
name, code, prototype, read_only_prototype); name, code, prototype, read_only_prototype);
...@@ -1321,8 +1320,13 @@ Handle<JSFunction> Factory::NewFunction(Handle<String> name, ...@@ -1321,8 +1320,13 @@ Handle<JSFunction> Factory::NewFunction(Handle<String> name,
ElementsKind elements_kind = ElementsKind elements_kind =
type == JS_ARRAY_TYPE ? FAST_SMI_ELEMENTS : FAST_HOLEY_SMI_ELEMENTS; type == JS_ARRAY_TYPE ? FAST_SMI_ELEMENTS : FAST_HOLEY_SMI_ELEMENTS;
Handle<Map> initial_map = NewMap(type, instance_size, elements_kind); Handle<Map> initial_map = NewMap(type, instance_size, elements_kind);
if (prototype->IsTheHole() && !function->shared()->is_generator()) { if (!function->shared()->is_generator()) {
prototype = NewFunctionPrototype(function); if (prototype->IsTheHole()) {
prototype = NewFunctionPrototype(function);
} else if (install_constructor) {
JSObject::AddProperty(Handle<JSObject>::cast(prototype),
constructor_string(), function, DONT_ENUM);
}
} }
JSFunction::SetInitialMap(function, initial_map, JSFunction::SetInitialMap(function, initial_map,
...@@ -2278,8 +2282,8 @@ Handle<JSFunction> Factory::CreateApiFunction( ...@@ -2278,8 +2282,8 @@ Handle<JSFunction> Factory::CreateApiFunction(
break; break;
} }
result = NewFunction(empty_string(), code, prototype, type, result = NewFunction(empty_string(), code, prototype, type, instance_size,
instance_size, obj->read_only_prototype()); obj->read_only_prototype(), true);
} }
result->shared()->set_length(obj->length()); result->shared()->set_length(obj->length());
...@@ -2299,19 +2303,13 @@ Handle<JSFunction> Factory::CreateApiFunction( ...@@ -2299,19 +2303,13 @@ Handle<JSFunction> Factory::CreateApiFunction(
return result; return result;
} }
if (prototype->IsTheHole()) {
#ifdef DEBUG #ifdef DEBUG
LookupIterator it(handle(JSObject::cast(result->prototype())), LookupIterator it(handle(JSObject::cast(result->prototype())),
constructor_string(), constructor_string(), LookupIterator::OWN_SKIP_INTERCEPTOR);
LookupIterator::OWN_SKIP_INTERCEPTOR); MaybeHandle<Object> maybe_prop = Object::GetProperty(&it);
MaybeHandle<Object> maybe_prop = Object::GetProperty(&it); DCHECK(it.IsFound());
DCHECK(it.IsFound()); DCHECK(maybe_prop.ToHandleChecked().is_identical_to(result));
DCHECK(maybe_prop.ToHandleChecked().is_identical_to(result));
#endif #endif
} else {
JSObject::AddProperty(handle(JSObject::cast(result->prototype())),
constructor_string(), result, DONT_ENUM);
}
// Down from here is only valid for API functions that can be used as a // Down from here is only valid for API functions that can be used as a
// constructor (don't set the "remove prototype" flag). // constructor (don't set the "remove prototype" flag).
......
...@@ -485,12 +485,11 @@ class Factory FINAL { ...@@ -485,12 +485,11 @@ class Factory FINAL {
Handle<Context> context, Handle<Context> context,
PretenureFlag pretenure = TENURED); PretenureFlag pretenure = TENURED);
Handle<JSFunction> NewFunction(Handle<String> name, Handle<JSFunction> NewFunction(Handle<String> name, Handle<Code> code,
Handle<Code> code, Handle<Object> prototype, InstanceType type,
Handle<Object> prototype,
InstanceType type,
int instance_size, int instance_size,
bool read_only_prototype = false); bool read_only_prototype = false,
bool install_constructor = false);
Handle<JSFunction> NewFunction(Handle<String> name, Handle<JSFunction> NewFunction(Handle<String> name,
Handle<Code> code, Handle<Code> code,
InstanceType type, InstanceType type,
......
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