blob: 0f7bcd8cab28f87b0148a935846d1b80216be089 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2012 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
30function ToDictionaryMode(x) {
31 %OptimizeObjectForAddingMultipleProperties(x, 100);
32}
33
34var A, B, C;
35
36// The initial bug report was about calling a know function...
37A = {};
38Object.defineProperty(A, "foo", { value: function() { assertUnreachable(); }});
39
40B = Object.create(A);
41Object.defineProperty(B, "foo", { value: function() { return 111; }});
42
43C = Object.create(B);
44
45function bar(x) { return x.foo(); }
46
47assertEquals(111, bar(C));
48assertEquals(111, bar(C));
49ToDictionaryMode(B);
50%OptimizeFunctionOnNextCall(bar);
51assertEquals(111, bar(C));
52
53// Although this was not in the initial bug report: The same for getters...
54A = {};
55Object.defineProperty(A, "baz", { get: function() { assertUnreachable(); }});
56
57B = Object.create(A);
58Object.defineProperty(B, "baz", { get: function() { return 111; }});
59
60C = Object.create(B);
61
62function boo(x) { return x.baz; }
63
64assertEquals(111, boo(C));
65assertEquals(111, boo(C));
66ToDictionaryMode(B);
67%OptimizeFunctionOnNextCall(boo);
68assertEquals(111, boo(C));
69
70// And once more for setters...
71A = {};
72Object.defineProperty(A, "huh", { set: function(x) { assertUnreachable(); }});
73
74B = Object.create(A);
75var setterValue;
76Object.defineProperty(B, "huh", { set: function(x) { setterValue = x; }});
77
78C = Object.create(B);
79
80function fuu(x) {
81 setterValue = 222;
82 x.huh = 111;
83 return setterValue;
84}
85
86assertEquals(111, fuu(C));
87assertEquals(111, fuu(C));
88ToDictionaryMode(B);
89%OptimizeFunctionOnNextCall(fuu);
90assertEquals(111, fuu(C));