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

Side by Side Diff: test/mjsunit/harmony/typedarrays-of.js

Issue 1192433003: Revert of Add %TypedArray% to proto chain (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 months 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/harmony/typedarrays.js ('k') | test/mjsunit/regress/regress-typedarray-length.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 // Based on Mozilla Array.of() tests at http://dxr.mozilla.org/mozilla-central/s ource/js/src/jit-test/tests/collections 5 // Based on Mozilla Array.of() tests at http://dxr.mozilla.org/mozilla-central/s ource/js/src/jit-test/tests/collections
6 6
7 // Flags: --harmony-arrays 7 // Flags: --harmony-arrays
8 8
9 var typedArrayConstructors = [ 9 var typedArrayConstructors = [
10 Uint8Array, 10 Uint8Array,
11 Int8Array, 11 Int8Array,
12 Uint16Array, 12 Uint16Array,
13 Int16Array, 13 Int16Array,
14 Uint32Array, 14 Uint32Array,
15 Int32Array, 15 Int32Array,
16 Uint8ClampedArray, 16 Uint8ClampedArray,
17 Float32Array, 17 Float32Array,
18 Float64Array 18 Float64Array];
19 ];
20 19
21 function getPropertyDescriptor(object, field, expectedDepth) {
22 for (var depth = 0; depth < expectedDepth; depth++) {
23 assertFalse(Object.hasOwnProperty(object, field));
24 object = object.__proto__;
25 }
26 return Object.getOwnPropertyDescriptor(object, field);
27 }
28 20
29 function TestTypedArrayOf(constructor) { 21 function TestTypedArrayOf(constructor) {
30 // %TypedArray%.of basics. 22 // %TypedArray%.of basics.
31 var a = constructor.of(); 23 var a = constructor.of();
32 assertEquals(0, a.length); 24 assertEquals(0, a.length);
33 assertEquals(constructor.prototype, Object.getPrototypeOf(a)); 25 assertEquals(constructor.prototype, Object.getPrototypeOf(a));
34 assertEquals(false, Array.isArray(a)); 26 assertEquals(false, Array.isArray(a));
35 27
36 // Items are coerced to numerical values. 28 // Items are coerced to numerical values.
37 a = constructor.of(undefined, null, [], true, false, 3.14); 29 a = constructor.of(undefined, null, [], true, false, 3.14);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // when the setter is on the new object's prototype 104 // when the setter is on the new object's prototype
113 function Bevy() {} 105 function Bevy() {}
114 Object.defineProperty(Bevy.prototype, "length", { 106 Object.defineProperty(Bevy.prototype, "length", {
115 set: function (v) { status = "fail"; } 107 set: function (v) { status = "fail"; }
116 }); 108 });
117 Bevy.of = constructor.of; 109 Bevy.of = constructor.of;
118 var bevy = Bevy.of("quail"); 110 var bevy = Bevy.of("quail");
119 assertEquals("pass", status); 111 assertEquals("pass", status);
120 112
121 // Check superficial features of %TypedArray%.of. 113 // Check superficial features of %TypedArray%.of.
122 var desc = getPropertyDescriptor(constructor, "of", 1); 114 var desc = Object.getOwnPropertyDescriptor(constructor, "of");
123 115
124 assertEquals(desc.configurable, false); 116 assertEquals(desc.configurable, false);
125 assertEquals(desc.enumerable, false); 117 assertEquals(desc.enumerable, false);
126 assertEquals(desc.writable, false); 118 assertEquals(desc.writable, false);
127 assertEquals(constructor.of.length, 0); 119 assertEquals(constructor.of.length, 0);
128 120
129 // %TypedArray%.of is not a constructor. 121 // %TypedArray%.of is not a constructor.
130 assertThrows(function() { new constructor.of(); }, TypeError); 122 assertThrows(function() { new constructor.of(); }, TypeError);
131 123
132 // For receivers which are not constructors %TypedArray%.of does not 124 // For receivers which are not constructors %TypedArray%.of does not
133 // allocate a typed array using a default constructor, but throws an 125 // allocate a typed array using a default constructor, but throws an
134 // exception. Note that this is different from Array.of, which uses 126 // exception. Note that this is different from Array.of, which uses
135 // Array as default constructor. 127 // Array as default constructor.
136 for (var x of [undefined, null, false, true, "cow", 42, 3.14]) { 128 for (var x of [undefined, null, false, true, "cow", 42, 3.14]) {
137 assertThrows(function () { constructor.of.call(x); }, TypeError); 129 assertThrows(function () { constructor.of.call(x); }, TypeError);
138 } 130 }
139 } 131 }
140 132
141 for (var constructor of typedArrayConstructors) { 133 for (var constructor of typedArrayConstructors) {
142 TestTypedArrayOf(constructor); 134 TestTypedArrayOf(constructor);
143 } 135 }
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/typedarrays.js ('k') | test/mjsunit/regress/regress-typedarray-length.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698