classes-maps.js 1.38 KB
Newer Older
1 2 3 4
// Copyright 2014 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
// Flags: --allow-natives-syntax
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 63 64 65 66 67 68
'use strict';

(function TestMaps() {
  class Base {}
  class Derived extends Base {}

  let d1 = new Derived();
  let d2 = new Derived();

  assertTrue(%HaveSameMap(d1, d2));
}());


(function TestProtoModificationArray() {
  let called = 0;
  function F() {
    called++;
    assertFalse(Array.isArray(this));
  }
  class Derived extends Array {}
  assertSame(Derived.__proto__, Array);

  let d1 = new Derived();
  assertTrue(Array.isArray(d1));

  Derived.__proto__ = F;
  called = 0;
  let d2 = new Derived();
  assertSame(1, called);
  assertFalse(Array.isArray(d2));

  assertFalse(%HaveSameMap(d1, d2));
}());


(function TestProtoModification() {
  let called = 0;
  function F() {
    called++;
    let exn = null;
    try {
      this.byteLength;
    } catch (e) {
      exn = e;
    }
    assertTrue(exn instanceof TypeError);
  }
  class Derived extends Uint8Array {
    constructor() { super(10); }
  }
  assertSame(Derived.__proto__, Uint8Array);

  let d1 = new Derived();
  assertSame(10, d1.byteLength);

  Derived.__proto__ = F;
  called = 0;
  let d2 = new Derived();
  assertSame(1, called);
  assertThrows(function() { d2.byteLength; }, TypeError);

  assertFalse(%HaveSameMap(d1, d2));
}());