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

Side by Side Diff: test/mjsunit/getters-on-elements.js

Issue 35413006: Correct handling of arrays with callbacks in the prototype chain. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: A few test updates and simpler prototype updating. Created 7 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 // Flags: --allow-natives-syntax
29
30 // It's nice to run this in Firefox too.
31 var standalone = false;
32 if (standalone) {
33 assertTrue = function(val) {
34 if (val != true) {
35 print("FAILURE");
36 }
37 }
38
39 assertFalse = function(val) {
40 if (val != false) {
41 print("FAILURE");
42 }
43 }
44
45 optimize = function(name) { }
46 } else {
47 optimize = function(name) {
48 %OptimizeFunctionOnNextCall(name);
49 }
50 }
51
52 var calls = 0;
53 Array.prototype.__defineGetter__(0, function(val) {
54 calls++;
55 });
56
57 function dummy(value) {
58 try { value; } catch(e) { }
59 }
60
61 (function() {
62 function run(array, index) {
63 var runlength = 10;
64 calls = 0;
65 var accumulator = 0;
66 for (var i = 0; i < runlength; ++i) {
67 accumulator = accumulator + array[index];
68 }
69 // make sure the computation isn't perceived as redundant.
70 dummy(accumulator);
71 return calls == runlength;
72 }
73
74 // Try "warming up" the ic into a monomorphic state to see if we can trick it
75 // into ignoring the callback. The object map doesn't have the setter callback .
76 run({}, 0);
77 run({}, 0);
78 run({}, 0);
79
80 // Make sure the setter is called if the element is not defined,
81 // but is not called if the element is defined.
82 var typeArray = [1,2.5,true];
83 for (var types = 0; types < 3; types++) {
84 value = typeArray[types];
85 for (var i = 0; i < 2; i++) {
86 assertTrue(run([, value], 0)); // undefined
87 assertFalse(run([0, value], 0)); // defined.
88 assertTrue(run([, 3, value], 0)); // undefined
89 assertTrue(run(new Array(10), 0)); // undefined
90 // "sneak" an element in with shift.
91 o = []; o[1] = value; o.shift(1);
92 assertFalse(run(o, 0));
93 optimize(run);
94 run([], 0);
95 }
96 }
97
98 // Make sure we can turn it off.
99 delete Array.prototype[0];
100 assertFalse(run([], 0));
101 })();
102
103 Object.prototype.__defineGetter__(0, function(val) {
104 calls++;
105 });
106
107 (function() {
108 function run(obj) {
109 var runlength = 10;
110 calls = 0;
111 var accumulator = 0;
112 for (var i = 0; i < runlength; ++i) {
113 accumulator = accumulator + obj[0];
114 }
115 // make sure the computation isn't perceived as redundant.
116 dummy(accumulator);
117 return calls == runlength;
118 }
119
120 for (var i = 0; i < 2; i++) {
121 assertTrue(run({}));
122 o = { foo: 3 };
123 assertTrue(run(o));
124 o = {}; o[1] = 3;
125 assertTrue(run(o));
126 o = { 0: 0 };
127 assertFalse(run(o));
128 delete o[0];
129 assertTrue(run(o));
130 optimize(run);
131 run([]);
132 }
133 })();
134
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698