summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/es6/typedarray-proto.js
blob: 346b2ea63ddabb233a3cd3e0b13fa5d2ee95105f (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2015 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.

// Test that the methods for different TypedArray types have the same
// identity.

'use strict';

let typedArrayConstructors = [
  Uint8Array,
  Int8Array,
  Uint16Array,
  Int16Array,
  Uint32Array,
  Int32Array,
  Uint8ClampedArray,
  Float32Array,
  Float64Array];

let TypedArray = Uint8Array.__proto__;
let TypedArrayPrototype = TypedArray.prototype;

assertEquals(TypedArray.__proto__, Function.prototype);
assertEquals(TypedArrayPrototype.__proto__, Object.prototype);

// There are extra own class properties due to it simply being a function
let classProperties = new Set([
  "length", "name", "arguments", "caller", "prototype", "BYTES_PER_ELEMENT"
]);
let instanceProperties = new Set([
  "BYTES_PER_ELEMENT", "constructor", "prototype",
  // length is also an instance property as a temporary workaround to
  // BUG(chromium:579905). TODO(littledan): remove the workaround
  "length"
]);

function functionProperties(object) {
  return Object.getOwnPropertyNames(object).filter(function(name) {
    return typeof Object.getOwnPropertyDescriptor(object, name).value
        == "function" && name != 'constructor';
  });
}

let typedArrayMethods = functionProperties(Uint8Array.prototype);
let typedArrayClassMethods = functionProperties(Uint8Array);

for (let constructor of typedArrayConstructors) {
  for (let property of Object.getOwnPropertyNames(constructor.prototype)) {
    assertTrue(instanceProperties.has(property), property);
  }
  for (let property of Object.getOwnPropertyNames(constructor)) {
    assertTrue(classProperties.has(property), property);
  }
}

// Abstract %TypedArray% class can't be constructed directly

assertThrows(() => new TypedArray(), TypeError);

// The "prototype" property is nonconfigurable, nonenumerable, nonwritable,
// both for %TypedArray% and for all subclasses

let desc = Object.getOwnPropertyDescriptor(TypedArray, "prototype");
assertFalse(desc.writable);
assertFalse(desc.configurable);
assertFalse(desc.enumerable);

for (let constructor of typedArrayConstructors) {
  let desc = Object.getOwnPropertyDescriptor(constructor, "prototype");
  assertFalse(desc.writable);
  assertFalse(desc.configurable);
  assertFalse(desc.enumerable);
}