From: Toon Verwaest Date: Thu, 13 Nov 2014 14:12:03 +0000 (+0100) Subject: Install the constructor property on custom prototype before optimizing it as a prototype X-Git-Tag: upstream/4.7.83~5712 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c8e5a1add7b0b3184db92135a0b8ace065ecc24d;p=platform%2Fupstream%2Fv8.git 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} --- diff --git a/src/factory.cc b/src/factory.cc index 26be6af..969973c 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -1308,12 +1308,11 @@ Handle Factory::NewFunction(Handle name, } -Handle Factory::NewFunction(Handle name, - Handle code, +Handle Factory::NewFunction(Handle name, Handle code, Handle prototype, - InstanceType type, - int instance_size, - bool read_only_prototype) { + InstanceType type, int instance_size, + bool read_only_prototype, + bool install_constructor) { // Allocate the function Handle function = NewFunction( name, code, prototype, read_only_prototype); @@ -1321,8 +1320,13 @@ Handle Factory::NewFunction(Handle name, ElementsKind elements_kind = type == JS_ARRAY_TYPE ? FAST_SMI_ELEMENTS : FAST_HOLEY_SMI_ELEMENTS; Handle initial_map = NewMap(type, instance_size, elements_kind); - if (prototype->IsTheHole() && !function->shared()->is_generator()) { - prototype = NewFunctionPrototype(function); + if (!function->shared()->is_generator()) { + if (prototype->IsTheHole()) { + prototype = NewFunctionPrototype(function); + } else if (install_constructor) { + JSObject::AddProperty(Handle::cast(prototype), + constructor_string(), function, DONT_ENUM); + } } JSFunction::SetInitialMap(function, initial_map, @@ -2278,8 +2282,8 @@ Handle Factory::CreateApiFunction( break; } - result = NewFunction(empty_string(), code, prototype, type, - instance_size, obj->read_only_prototype()); + result = NewFunction(empty_string(), code, prototype, type, instance_size, + obj->read_only_prototype(), true); } result->shared()->set_length(obj->length()); @@ -2299,19 +2303,13 @@ Handle Factory::CreateApiFunction( return result; } - if (prototype->IsTheHole()) { #ifdef DEBUG - LookupIterator it(handle(JSObject::cast(result->prototype())), - constructor_string(), - LookupIterator::OWN_SKIP_INTERCEPTOR); - MaybeHandle maybe_prop = Object::GetProperty(&it); - DCHECK(it.IsFound()); - DCHECK(maybe_prop.ToHandleChecked().is_identical_to(result)); + LookupIterator it(handle(JSObject::cast(result->prototype())), + constructor_string(), LookupIterator::OWN_SKIP_INTERCEPTOR); + MaybeHandle maybe_prop = Object::GetProperty(&it); + DCHECK(it.IsFound()); + DCHECK(maybe_prop.ToHandleChecked().is_identical_to(result)); #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 // constructor (don't set the "remove prototype" flag). diff --git a/src/factory.h b/src/factory.h index 1415823..a87f78b 100644 --- a/src/factory.h +++ b/src/factory.h @@ -485,12 +485,11 @@ class Factory FINAL { Handle context, PretenureFlag pretenure = TENURED); - Handle NewFunction(Handle name, - Handle code, - Handle prototype, - InstanceType type, + Handle NewFunction(Handle name, Handle code, + Handle prototype, InstanceType type, int instance_size, - bool read_only_prototype = false); + bool read_only_prototype = false, + bool install_constructor = false); Handle NewFunction(Handle name, Handle code, InstanceType type,