Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(784)

Side by Side Diff: test/mjsunit/es6/typedarray-proto.js

Issue 1541233002: Use ES2015-style TypedArray prototype chain (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Test of prototype property descriptor Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/es6/typedarray-of.js ('k') | test/mjsunit/get-prototype-of.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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);
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 }
OLDNEW
« no previous file with comments | « test/mjsunit/es6/typedarray-of.js ('k') | test/mjsunit/get-prototype-of.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698