regress-9041.js 1.77 KB
Newer Older
1 2 3 4 5 6 7
// 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

(function() {
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 34 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  class A {};

  function foo(a, fn) {
    const C = a.constructor;
    fn(a);
    return a instanceof C;
  };

  %PrepareFunctionForOptimization(foo);
  assertTrue(foo(new A(), a => {}));
  assertTrue(foo(new A(), a => {}));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(new A(), a => {}));
  assertFalse(foo(new A(), a => { a.__proto__ = {}; }));
})();

(function() {
  class A {};
  A.__proto__ = {};
  A.prototype = {};

  function foo() {
    var x = Object.create(Object.create(Object.create(A.prototype)));
    return x instanceof A;
  };

  %PrepareFunctionForOptimization(foo);
  assertTrue(foo());
  assertTrue(foo());
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo());
})();

(function() {
  class A {};
  A.prototype = {};
  A.__proto__ = {};
  var a = {__proto__: new A, gaga: 42};

  function foo() {
    A.bla;  // Make A.__proto__ fast again.
    a.gaga;
    return a instanceof A;
  };

  %PrepareFunctionForOptimization(foo);
  assertTrue(foo());
  assertTrue(foo());
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo());
})();

(function() {
  class A {};
  A.prototype = {};
  A.__proto__ = {};
  const boundA = Function.prototype.bind.call(A, {});
  boundA.prototype = {};
  boundA.__proto__ = {};
  var a = {__proto__: new boundA, gaga: 42};

  function foo() {
    A.bla;  // Make A.__proto__ fast again.
    boundA.bla;  // Make boundA.__proto__ fast again.
    a.gaga;
    return a instanceof boundA;
  };

  %PrepareFunctionForOptimization(foo);
  assertTrue(foo());
  assertTrue(foo());
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo());
81
})();