Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1414)

Unified Diff: test/mjsunit/array-push4.js

Issue 232873002: Partially fix semantics of Array.push() (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add missing test case Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/mjsunit/array-push3.js ('k') | test/mjsunit/array-push5.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/array-push4.js
diff --git a/test/mjsunit/array-push4.js b/test/mjsunit/array-push4.js
new file mode 100644
index 0000000000000000000000000000000000000000..678873fb3afce974cfdfbc9986d62cf97273d33f
--- /dev/null
+++ b/test/mjsunit/array-push4.js
@@ -0,0 +1,60 @@
+// 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
+
+var v = 0;
+var my_array_proto = {};
+my_array_proto.__proto__ = [].__proto__;
+Object.defineProperty(my_array_proto, "0", {
+get: function() { return "get " + v; },
+set: function(value) { v += value; }
+});
+
+
+// Test that element accessors are called in standard push cases.
+array = [];
+array.__proto__ = my_array_proto;
+
+array[0] = 10;
+assertEquals(0, array.length);
+assertEquals(10, v);
+assertEquals("get 10", array[0]);
+
+Array.prototype.push.call(array, 100);
+assertEquals(1, array.length);
+assertEquals(110, v);
+assertEquals("get 110", array[0]);
+
+array = [];
+array.__proto__ = my_array_proto;
+
+assertEquals(0, array.length);
+array.push(110);
+assertEquals(1, array.length);
+assertEquals(220, v);
+assertEquals("get 220", array[0]);
+
+// Test that elements setters/getters on prototype chain are property detected
+// and don't lead to overzealous optimization.
+v = 0;
+function push_wrapper_1(array, value) {
+ array.push(value);
+}
+array = [];
+array.__proto__ = my_array_proto;
+push_wrapper_1(array, 100);
+assertEquals(1, array.length);
+assertEquals(100, v);
+push_wrapper_1(array, 100);
+assertEquals(2, array.length);
+assertEquals(100, v);
+assertEquals("get 100", array[0]);
+%OptimizeFunctionOnNextCall(push_wrapper_1);
+array = [];
+array.__proto__ = my_array_proto;
+push_wrapper_1(array, 100);
+assertEquals(1, array.length);
+assertEquals(200, v);
+assertEquals("get 200", array[0]);
« no previous file with comments | « test/mjsunit/array-push3.js ('k') | test/mjsunit/array-push5.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698