From: jkummerow@chromium.org Date: Thu, 12 Jun 2014 16:41:56 +0000 (+0000) Subject: Optimize prototype chain when creating initial maps for functions used as constructors X-Git-Tag: upstream/4.7.83~8696 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=301ae7dd561a9357bace5456aa5ba4f381d51ad9;p=platform%2Fupstream%2Fv8.git Optimize prototype chain when creating initial maps for functions used as constructors Review URL: https://codereview.chromium.org/332783002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21817 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/objects.cc b/src/objects.cc index 316428b..3d354b8 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -10129,6 +10129,10 @@ void JSFunction::EnsureHasInitialMap(Handle function) { Handle prototype; if (function->has_instance_prototype()) { prototype = handle(function->instance_prototype(), isolate); + for (Handle p = prototype; !p->IsNull() && !p->IsJSProxy(); + p = Object::GetPrototype(isolate, p)) { + JSObject::OptimizeAsPrototype(Handle::cast(p)); + } } else { prototype = isolate->factory()->NewFunctionPrototype(function); } diff --git a/test/mjsunit/dictionary-properties.js b/test/mjsunit/dictionary-properties.js new file mode 100644 index 0000000..c70c598 --- /dev/null +++ b/test/mjsunit/dictionary-properties.js @@ -0,0 +1,46 @@ +// Copyright 2014 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax + +// Test loading existent and nonexistent properties from dictionary +// mode objects. + +function SlowObject() { + this.foo = 1; + this.bar = 2; + this.qux = 3; + delete this.qux; + assertFalse(%HasFastProperties(this)); +} +function SlowObjectWithBaz() { + var o = new SlowObject(); + o.baz = 4; + return o; +} + +function Load(o) { + return o.baz; +} + +for (var i = 0; i < 10; i++) { + var o1 = new SlowObject(); + var o2 = SlowObjectWithBaz(); + assertEquals(undefined, Load(o1)); + assertEquals(4, Load(o2)); +} + +// Test objects getting optimized as fast prototypes. + +function SlowPrototype() { + this.foo = 1; +} +SlowPrototype.prototype.bar = 2; +SlowPrototype.prototype.baz = 3; +delete SlowPrototype.prototype.baz; + +assertFalse(%HasFastProperties(SlowPrototype.prototype)); +var fast_proto = new SlowPrototype(); +assertTrue(%HasFastProperties(SlowPrototype.prototype)); +assertTrue(%HasFastProperties(fast_proto.__proto__));