OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Test that the methods for different TypedArray types have the same | 5 // Test that the methods for different TypedArray types have the same |
6 // identity. | 6 // identity. |
7 // TODO(dehrenberg): Test that the TypedArray proto hierarchy is set | |
8 // up properly. | |
9 // TODO(dehrenberg): subarray is currently left out because that still | |
10 // uses per-type methods. When that's fixed, stop leaving it out. | |
11 | 7 |
12 var typedArrayConstructors = [ | 8 'use strict'; |
| 9 |
| 10 let typedArrayConstructors = [ |
13 Uint8Array, | 11 Uint8Array, |
14 Int8Array, | 12 Int8Array, |
15 Uint16Array, | 13 Uint16Array, |
16 Int16Array, | 14 Int16Array, |
17 Uint32Array, | 15 Uint32Array, |
18 Int32Array, | 16 Int32Array, |
19 Uint8ClampedArray, | 17 Uint8ClampedArray, |
20 Float32Array, | 18 Float32Array, |
21 Float64Array]; | 19 Float64Array]; |
22 | 20 |
| 21 let TypedArray = Uint8Array.__proto__; |
| 22 let TypedArrayPrototype = TypedArray.prototype; |
| 23 |
| 24 assertEquals(TypedArray.__proto__, Function.prototype); |
| 25 assertEquals(TypedArrayPrototype.__proto__, Object.prototype); |
| 26 |
| 27 // There are extra own class properties due to it simply being a function |
| 28 let classProperties = new Set([ |
| 29 "length", "name", "arguments", "caller", "prototype", "BYTES_PER_ELEMENT" |
| 30 ]); |
| 31 let instanceProperties = new Set(["BYTES_PER_ELEMENT", "constructor", "prototype
"]); |
| 32 |
23 function functionProperties(object) { | 33 function functionProperties(object) { |
24 return Object.getOwnPropertyNames(object).filter(function(name) { | 34 return Object.getOwnPropertyNames(object).filter(function(name) { |
25 return typeof Object.getOwnPropertyDescriptor(object, name).value | 35 return typeof Object.getOwnPropertyDescriptor(object, name).value |
26 == "function" | 36 == "function" |
27 && name != 'constructor' && name != 'subarray'; | 37 && name != 'constructor' && name != 'subarray'; |
28 }); | 38 }); |
29 } | 39 } |
30 | 40 |
31 var typedArrayMethods = functionProperties(Uint8Array.prototype); | 41 let typedArrayMethods = functionProperties(Uint8Array.prototype); |
32 var typedArrayClassMethods = functionProperties(Uint8Array); | 42 let typedArrayClassMethods = functionProperties(Uint8Array); |
33 | 43 |
34 for (var constructor of typedArrayConstructors) { | 44 for (let constructor of typedArrayConstructors) { |
35 for (var method of typedArrayMethods) { | 45 for (let property of Object.getOwnPropertyNames(constructor.prototype)) { |
36 assertEquals(constructor.prototype[method], | 46 assertTrue(instanceProperties.has(property), property); |
37 Uint8Array.prototype[method], method); | |
38 } | 47 } |
39 for (var classMethod of typedArrayClassMethods) { | 48 for (let property of Object.getOwnPropertyNames(constructor)) { |
40 assertEquals(constructor[method], Uint8Array[method], classMethod); | 49 assertTrue(classProperties.has(property), property); |
41 } | 50 } |
42 } | 51 } |
| 52 |
| 53 // Abstract %TypedArray% class can't be constructed directly |
| 54 |
| 55 assertThrows(() => new TypedArray(), TypeError); |
OLD | NEW |