regress-7421.js 1.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Debug = debug.Debug

// Test that the side-effect check is not bypassed in optimized code.

var exception = null;
var counter = 0;

function f1() {
  counter++;
}

function wrapper1() {
  for (var i = 0; i < 4; i++) {
    // Get this function optimized before calling to increment.
    // Check that that call performs the necessary side-effect checks.
20
    %OptimizeOsr();
21
    %PrepareFunctionForOptimization(wrapper1);
22 23 24
  }
  f1();
}
25
%PrepareFunctionForOptimization(wrapper1);
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

function f2() {
  counter++;
}

function wrapper2(call) {
  if (call) f2();
}

function listener(event, exec_state, event_data, data) {
  if (event != Debug.DebugEvent.Break) return;
  try {
    function success(expectation, source) {
      assertEquals(expectation,
                   exec_state.frame(0).evaluate(source, true).value());
    }
    function fail(source) {
      assertThrows(() => exec_state.frame(0).evaluate(source, true),
                   EvalError);
    }
    wrapper1();
    wrapper1();
    fail("wrapper1()");

50
    %PrepareFunctionForOptimization(wrapper2);
51 52 53 54 55 56
    wrapper2(true);
    wrapper2(false);
    wrapper2(true);
    %OptimizeFunctionOnNextCall(wrapper2);
    wrapper2(false);
    fail("wrapper2(true)");
57 58
    fail("%PrepareFunctionForOptimization(wrapper2); "+
         "%OptimizeFunctionOnNextCall(wrapper2); wrapper2(true)");
59

60
    %PrepareFunctionForOptimization(wrapper2);
61
    %DisableOptimizationFinalization();
62 63
    %OptimizeFunctionOnNextCall(wrapper2, "concurrent");
    wrapper2(false);
64
    fail("%FinalizeOptimization();" +
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
         "wrapper2(true);");
  } catch (e) {
    exception = e;
    print(e, e.stack);
  }
};

// Add the debug event listener.
Debug.setListener(listener);

function f() {
  debugger;
};

f();

assertNull(exception);