1// Copyright 2014 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// Flags: --allow-natives-syntax
6
7function mod1() {
8  var v_1 = 1;
9  var v_2 = 1;
10  v_1++;
11  v_2 = {valueOf: function() { throw "gagh"; }};
12
13  function bug1() {
14    for (var i = 0; i < 1; v_2++) {
15      if (v_1 == 1) ;
16    }
17  }
18
19  return bug1;
20}
21
22var f = mod1();
23assertThrows(f);
24%OptimizeFunctionOnNextCall(f);
25assertThrows(f);
26
27
28var v_3 = 1;
29var v_4 = 1;
30v_3++;
31v_4 = {valueOf: function() { throw "gagh"; }};
32
33function bug2() {
34  for (var i = 0; i < 1; v_4++) {
35    if (v_3 == 1) ;
36  }
37}
38
39assertThrows(bug2);
40%OptimizeFunctionOnNextCall(bug2);
41assertThrows(bug2);
42