catch-block-load.js 1.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
// Copyright 2019 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.

// Flags: --allow-natives-syntax

const obj = { a: 42 };

function boom() {
  throw "boom";
}

// Ensure that we optimize the monomorphic case.
(function() {
  function bar(x) {
    try {
      boom();
      ++i;
    } catch(_) {
      %TurbofanStaticAssert(x.a == 42);
      return x.a;
    }
  }

  function foo() {
    return bar(obj);
  }

  %PrepareFunctionForOptimization(foo);
  %PrepareFunctionForOptimization(bar);

  foo();
  foo();
34
  %OptimizeFunctionForTopTier(foo);
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  foo();
})();

// And the megamorphic case.
(function() {
  function bar(x) {
    try {
      boom();
      ++i;
    } catch(_) {
      %TurbofanStaticAssert(x.a == 42);
      return x.a;
    }
  }

  function foo() {
    return bar(obj);
  }

  %PrepareFunctionForOptimization(foo);
  %PrepareFunctionForOptimization(bar);

  bar({b: 42});
  bar({c: 42});
  bar({d: 42});
  bar({e: 42});
  bar({f: 42});

  foo();
  foo();
65
  %OptimizeFunctionForTopTier(foo);
66 67
  foo();
})();