| 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. |
| 7 | 11 |
| 8 'use strict'; | 12 var typedArrayConstructors = [ |
| 9 | |
| 10 let typedArrayConstructors = [ | |
| 11 Uint8Array, | 13 Uint8Array, |
| 12 Int8Array, | 14 Int8Array, |
| 13 Uint16Array, | 15 Uint16Array, |
| 14 Int16Array, | 16 Int16Array, |
| 15 Uint32Array, | 17 Uint32Array, |
| 16 Int32Array, | 18 Int32Array, |
| 17 Uint8ClampedArray, | 19 Uint8ClampedArray, |
| 18 Float32Array, | 20 Float32Array, |
| 19 Float64Array]; | 21 Float64Array]; |
| 20 | 22 |
| 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 | |
| 33 function functionProperties(object) { | 23 function functionProperties(object) { |
| 34 return Object.getOwnPropertyNames(object).filter(function(name) { | 24 return Object.getOwnPropertyNames(object).filter(function(name) { |
| 35 return typeof Object.getOwnPropertyDescriptor(object, name).value | 25 return typeof Object.getOwnPropertyDescriptor(object, name).value |
| 36 == "function" | 26 == "function" |
| 37 && name != 'constructor' && name != 'subarray'; | 27 && name != 'constructor' && name != 'subarray'; |
| 38 }); | 28 }); |
| 39 } | 29 } |
| 40 | 30 |
| 41 let typedArrayMethods = functionProperties(Uint8Array.prototype); | 31 var typedArrayMethods = functionProperties(Uint8Array.prototype); |
| 42 let typedArrayClassMethods = functionProperties(Uint8Array); | 32 var typedArrayClassMethods = functionProperties(Uint8Array); |
| 43 | 33 |
| 44 for (let constructor of typedArrayConstructors) { | 34 for (var constructor of typedArrayConstructors) { |
| 45 for (let property of Object.getOwnPropertyNames(constructor.prototype)) { | 35 for (var method of typedArrayMethods) { |
| 46 assertTrue(instanceProperties.has(property), property); | 36 assertEquals(constructor.prototype[method], |
| 37 Uint8Array.prototype[method], method); |
| 47 } | 38 } |
| 48 for (let property of Object.getOwnPropertyNames(constructor)) { | 39 for (var classMethod of typedArrayClassMethods) { |
| 49 assertTrue(classProperties.has(property), property); | 40 assertEquals(constructor[method], Uint8Array[method], classMethod); |
| 50 } | 41 } |
| 51 } | 42 } |
| 52 | |
| 53 // Abstract %TypedArray% class can't be constructed directly | |
| 54 | |
| 55 assertThrows(() => new TypedArray(), TypeError); | |
| 56 | |
| 57 // The "prototype" property is nonconfigurable, nonenumerable, nonwritable, | |
| 58 // both for %TypedArray% and for all subclasses | |
| 59 | |
| 60 let desc = Object.getOwnPropertyDescriptor(TypedArray, "prototype"); | |
| 61 assertFalse(desc.writable); | |
| 62 assertFalse(desc.configurable); | |
| 63 assertFalse(desc.enumerable); | |
| 64 | |
| 65 for (let constructor of typedArrayConstructors) { | |
| 66 let desc = Object.getOwnPropertyDescriptor(constructor, "prototype"); | |
| 67 assertFalse(desc.writable); | |
| 68 assertFalse(desc.configurable); | |
| 69 assertFalse(desc.enumerable); | |
| 70 } | |
| OLD | NEW |