deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / test / mjsunit / compiler / try-deopt.js
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // TODO(mstarzinger): Add FLAG_turbo_exceptions once we want ClusterFuzz.
6 // Flags: --allow-natives-syntax --turbo-deoptimization
7
8 function DeoptFromTry(x) {
9   try {
10     %DeoptimizeFunction(DeoptFromTry);
11     throw x;
12   } catch (e) {
13     return e + 1;
14   }
15   return x + 2;
16 }
17 %OptimizeFunctionOnNextCall(DeoptFromTry);
18 assertEquals(24, DeoptFromTry(23));
19
20
21 function DeoptFromCatch(x) {
22   try {
23     throw x;
24   } catch (e) {
25     %DeoptimizeFunction(DeoptFromCatch);
26     return e + 1;
27   }
28   return x + 2;
29 }
30 %OptimizeFunctionOnNextCall(DeoptFromCatch);
31 assertEquals(24, DeoptFromCatch(23));
32
33
34 function DeoptFromFinally_Return(x) {
35   try {
36     throw x;
37   } finally {
38     %DeoptimizeFunction(DeoptFromFinally_Return);
39     return x + 1;
40   }
41   return x + 2;
42 }
43 %OptimizeFunctionOnNextCall(DeoptFromFinally_Return);
44 assertEquals(24, DeoptFromFinally_Return(23));
45
46
47 function DeoptFromFinally_ReThrow(x) {
48   try {
49     throw x;
50   } finally {
51     %DeoptimizeFunction(DeoptFromFinally_ReThrow);
52   }
53   return x + 2;
54 }
55 %OptimizeFunctionOnNextCall(DeoptFromFinally_ReThrow);
56 assertThrows("DeoptFromFinally_ReThrow(new Error)", Error);