array-some.js 2.54 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// 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.

// Flags: --allow-natives-syntax

// Basic loop peeling test case with Array.prototype.some().
(function() {
  function foo(a, o) {
    return a.some(x => x === o.x);
  }

13
  %PrepareFunctionForOptimization(foo);
14 15 16 17 18
  assertTrue(foo([1, 2, 3], {x:3}));
  assertFalse(foo([0, 1, 2], {x:3}));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo([1, 2, 3], {x:3}));
  assertFalse(foo([0, 1, 2], {x:3}));
19

20
  // Packed
21 22
  // Non-extensible
  %PrepareFunctionForOptimization(foo);
23 24
  assertTrue(foo(Object.preventExtensions([1, 2, '3']), {x:'3'}));
  assertFalse(foo(Object.preventExtensions([0, 1, '2']), {x:'3'}));
25
  %OptimizeFunctionOnNextCall(foo);
26 27
  assertTrue(foo(Object.preventExtensions([1, 2, '3']), {x:'3'}));
  assertFalse(foo(Object.preventExtensions([0, 1, '2']), {x:'3'}));
28 29 30

  // Sealed
  %PrepareFunctionForOptimization(foo);
31 32
  assertTrue(foo(Object.seal([1, 2, '3']), {x:'3'}));
  assertFalse(foo(Object.seal([0, 1, '2']), {x:'3'}));
33
  %OptimizeFunctionOnNextCall(foo);
34 35
  assertTrue(foo(Object.seal([1, 2, '3']), {x:'3'}));
  assertFalse(foo(Object.seal([0, 1, '2']), {x:'3'}));
36 37 38

  // Frozen
  %PrepareFunctionForOptimization(foo);
39 40
  assertTrue(foo(Object.freeze([1, 2, '3']), {x:'3'}));
  assertFalse(foo(Object.freeze([0, 1, '2']), {x:'3'}));
41
  %OptimizeFunctionOnNextCall(foo);
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
  assertTrue(foo(Object.freeze([1, 2, '3']), {x:'3'}));
  assertFalse(foo(Object.freeze([0, 1, '2']), {x:'3'}));

  // Holey
  // Non-extensible
  %PrepareFunctionForOptimization(foo);
  assertTrue(foo(Object.preventExtensions([, 1, 2, '3']), {x:'3'}));
  assertFalse(foo(Object.preventExtensions([, 0, 1, '2']), {x:'3'}));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(Object.preventExtensions([, 1, 2, '3']), {x:'3'}));
  assertFalse(foo(Object.preventExtensions([, 0, 1, '2']), {x:'3'}));

  // Sealed
  %PrepareFunctionForOptimization(foo);
  assertTrue(foo(Object.seal([, 1, 2, '3']), {x:'3'}));
  assertFalse(foo(Object.seal([, 0, 1, '2']), {x:'3'}));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(Object.seal([, 1, 2, '3']), {x:'3'}));
  assertFalse(foo(Object.seal([, 0, 1, '2']), {x:'3'}));

  // Frozen
  %PrepareFunctionForOptimization(foo);
  assertTrue(foo(Object.freeze([, 1, 2, '3']), {x:'3'}));
  assertFalse(foo(Object.freeze([, 0, 1, '2']), {x:'3'}));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(Object.freeze([, 1, 2, '3']), {x:'3'}));
  assertFalse(foo(Object.freeze([, 0, 1, '2']), {x:'3'}));
69
})();