Revision: 21817
Author: [email protected]
Date: Thu Jun 12 16:41:56 2014 UTC
Log: Optimize prototype chain when creating initial maps for functions
used as constructors
Review URL: https://codereview.chromium.org/332783002
http://code.google.com/p/v8/source/detail?r=21817
Added:
/branches/bleeding_edge/test/mjsunit/dictionary-properties.js
Modified:
/branches/bleeding_edge/src/objects.cc
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/dictionary-properties.js Thu Jun
12 16:41:56 2014 UTC
@@ -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__));
=======================================
--- /branches/bleeding_edge/src/objects.cc Thu Jun 12 15:08:33 2014 UTC
+++ /branches/bleeding_edge/src/objects.cc Thu Jun 12 16:41:56 2014 UTC
@@ -10129,6 +10129,10 @@
Handle<Object> prototype;
if (function->has_instance_prototype()) {
prototype = handle(function->instance_prototype(), isolate);
+ for (Handle<Object> p = prototype; !p->IsNull() && !p->IsJSProxy();
+ p = Object::GetPrototype(isolate, p)) {
+ JSObject::OptimizeAsPrototype(Handle<JSObject>::cast(p));
+ }
} else {
prototype = isolate->factory()->NewFunctionPrototype(function);
}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.