array-prototype-indexof.js 782 Bytes
Newer Older
1 2 3 4
// 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.

5 6
// indexOf

7 8
/* Test behaviors when the prototype has elements */

9 10 11 12 13 14 15 16 17 18 19 20 21
(function() {
  const iarr = [,3];

  function indexOf(arr, val) {
    return arr.indexOf(val);
  }

  assertEquals(-1, indexOf(iarr, 2));
  assertEquals(1, indexOf(iarr, 3));

  iarr.__proto__ = [2];
  assertEquals(0, indexOf(iarr, 2));
})();
22

23 24
// This pollutes the Array prototype, so we should not run more tests
// in the same environment after this.
25 26 27 28 29 30 31 32 33 34 35 36
(function () {
  var array = [,];

  function indexOf(val) {
    return array.indexOf(val);
  }

  assertEquals(indexOf(6), -1);

  array.__proto__.push(6);
  assertEquals(indexOf(6), 0);
})();