OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --allow-natives-syntax | 5 // Flags: --allow-natives-syntax |
6 | 6 |
7 (function TestDeoptFromCopmputedNameInObjectLiteral() { | 7 (function TestDeoptFromComputedNameInObjectLiteral() { |
8 function f() { | 8 function f() { |
9 var o = { | 9 var o = { |
10 toString: function() { | 10 toString: function() { |
11 %DeoptimizeFunction(f); | 11 %DeoptimizeFunction(f); |
12 return "x"; | 12 return "x"; |
13 } | 13 } |
14 }; | 14 }; |
15 return { [o]() { return 23 } }; | 15 return { [o]() { return 23 } }; |
16 } | 16 } |
17 assertEquals(23, f().x()); | 17 assertEquals(23, f().x()); |
18 assertEquals(23, f().x()); | 18 assertEquals(23, f().x()); |
19 %OptimizeFunctionOnNextCall(f); | 19 %OptimizeFunctionOnNextCall(f); |
20 assertEquals(23, f().x()); | 20 assertEquals(23, f().x()); |
21 })(); | 21 })(); |
22 | 22 |
23 (function TestDeoptFromCopmputedNameInClassLiteral() { | 23 (function TestDeoptFromComputedNameInObjectLiteralWithModifiedPrototype() { |
| 24 // The prototype chain should not be used if the definition |
| 25 // happens in the object literal. |
| 26 |
| 27 Object.defineProperty(Object.prototype, 'x_proto', { |
| 28 get: function () { |
| 29 return 21; |
| 30 }, |
| 31 set: function () { |
| 32 } |
| 33 }); |
| 34 |
| 35 |
| 36 function f() { |
| 37 var o = { |
| 38 toString: function() { |
| 39 %DeoptimizeFunction(f); |
| 40 return "x_proto"; |
| 41 } |
| 42 }; |
| 43 return { [o]() { return 23 } }; |
| 44 } |
| 45 assertEquals(23, f().x_proto()); |
| 46 assertEquals(23, f().x_proto()); |
| 47 %OptimizeFunctionOnNextCall(f); |
| 48 assertEquals(23, f().x_proto()); |
| 49 |
| 50 delete Object.prototype.c; |
| 51 |
| 52 })(); |
| 53 |
| 54 (function TestDeoptFromComputedNameInClassLiteral() { |
24 function g() { | 55 function g() { |
25 var o = { | 56 var o = { |
26 toString: function() { | 57 toString: function() { |
27 %DeoptimizeFunction(g); | 58 %DeoptimizeFunction(g); |
28 return "y"; | 59 return "y"; |
29 } | 60 } |
30 }; | 61 }; |
31 class C { | 62 class C { |
32 [o]() { return 42 }; | 63 [o]() { return 42 }; |
33 } | 64 } |
34 return new C(); | 65 return new C(); |
35 } | 66 } |
36 assertEquals(42, g().y()); | 67 assertEquals(42, g().y()); |
37 assertEquals(42, g().y()); | 68 assertEquals(42, g().y()); |
38 %OptimizeFunctionOnNextCall(g); | 69 %OptimizeFunctionOnNextCall(g); |
39 assertEquals(42, g().y()); | 70 assertEquals(42, g().y()); |
40 })(); | 71 })(); |
OLD | NEW |