blob: 0bd90d13b404ca7befbac7817c8e688addf51f39 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Test that the methods for different TypedArray types have the same
6// identity.
7
8'use strict';
9
10let typedArrayConstructors = [
11 Uint8Array,
12 Int8Array,
13 Uint16Array,
14 Int16Array,
15 Uint32Array,
16 Int32Array,
17 Uint8ClampedArray,
18 Float32Array,
19 Float64Array];
20
21let TypedArray = Uint8Array.__proto__;
22let TypedArrayPrototype = TypedArray.prototype;
23
24assertEquals(TypedArray.__proto__, Function.prototype);
25assertEquals(TypedArrayPrototype.__proto__, Object.prototype);
26
27// There are extra own class properties due to it simply being a function
28let classProperties = new Set([
29 "length", "name", "arguments", "caller", "prototype", "BYTES_PER_ELEMENT"
30]);
Ben Murdochda12d292016-06-02 14:46:10 +010031let instanceProperties = new Set(["BYTES_PER_ELEMENT", "constructor", "prototype"]);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000032
33function functionProperties(object) {
34 return Object.getOwnPropertyNames(object).filter(function(name) {
35 return typeof Object.getOwnPropertyDescriptor(object, name).value
Ben Murdochda12d292016-06-02 14:46:10 +010036 == "function"
37 && name != 'constructor' && name != 'subarray';
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000038 });
39}
40
41let typedArrayMethods = functionProperties(Uint8Array.prototype);
42let typedArrayClassMethods = functionProperties(Uint8Array);
43
44for (let constructor of typedArrayConstructors) {
45 for (let property of Object.getOwnPropertyNames(constructor.prototype)) {
46 assertTrue(instanceProperties.has(property), property);
47 }
48 for (let property of Object.getOwnPropertyNames(constructor)) {
49 assertTrue(classProperties.has(property), property);
50 }
51}
52
53// Abstract %TypedArray% class can't be constructed directly
54
55assertThrows(() => new TypedArray(), TypeError);
56
57// The "prototype" property is nonconfigurable, nonenumerable, nonwritable,
58// both for %TypedArray% and for all subclasses
59
60let desc = Object.getOwnPropertyDescriptor(TypedArray, "prototype");
61assertFalse(desc.writable);
62assertFalse(desc.configurable);
63assertFalse(desc.enumerable);
64
65for (let constructor of typedArrayConstructors) {
66 let desc = Object.getOwnPropertyDescriptor(constructor, "prototype");
67 assertFalse(desc.writable);
68 assertFalse(desc.configurable);
69 assertFalse(desc.enumerable);
70}