bigintarray-keyedstore-tobigint.js 1.4 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 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
// 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.

let TypedArrayConstructors = [
  BigUint64Array,
  BigInt64Array,
];

// Test KeyedStore in uninitialized and monomorphic states.
for (let C of TypedArrayConstructors) {
  let keyedSta = function(array) {
    var didRun = false;
    array[0] = {
      valueOf() {
        didRun = true;
        return 42n;
      }
    };

    return { didRun, array };
  };

  for (var i = 0; i < 3; ++i) {
    var { didRun, array } = keyedSta(new C(1));
    assertTrue(didRun);
    assertEquals(array[0], 42n);

    // OOB store
    // FIXME: Throw a TypeError when storing OOB in a TypedArray.
    var { didRun } = keyedSta(new C);
    assertTrue(didRun);
  }
}

// Test KeyedStore in polymorphic and megamorphic states.
do {
  let keyedSta = function(array) {
    var didRun = false;
    array[0] = {
      valueOf() {
        didRun = true;
        return 42n;
      }
    };

    return { didRun, array };
  };

  for (var i = 0; i < 3; ++i) {
    for (var C of TypedArrayConstructors) {
      var { didRun, array } = keyedSta(new C(1));
      assertTrue(didRun);
      assertEquals(array[0], 42n);

      // OOB store
      // FIXME: Throw a TypeError when storing OOB in a TypedArray.
      var { didRun } = keyedSta(new C);
      assertTrue(didRun);
    }
  }
} while (false);