OLD | NEW |
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 var typedArrayConstructors = [ | 7 var typedArrayConstructors = [ |
8 Uint8Array, | 8 Uint8Array, |
9 Int8Array, | 9 Int8Array, |
10 Uint16Array, | 10 Uint16Array, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // when the setter is on the new object's prototype | 102 // when the setter is on the new object's prototype |
103 function Bevy() {} | 103 function Bevy() {} |
104 Object.defineProperty(Bevy.prototype, "length", { | 104 Object.defineProperty(Bevy.prototype, "length", { |
105 set: function (v) { status = "fail"; } | 105 set: function (v) { status = "fail"; } |
106 }); | 106 }); |
107 Bevy.of = constructor.of; | 107 Bevy.of = constructor.of; |
108 var bevy = Bevy.of("quail"); | 108 var bevy = Bevy.of("quail"); |
109 assertEquals("pass", status); | 109 assertEquals("pass", status); |
110 | 110 |
111 // Check superficial features of %TypedArray%.of. | 111 // Check superficial features of %TypedArray%.of. |
112 var desc = Object.getOwnPropertyDescriptor(constructor, "of"); | 112 var desc = Object.getOwnPropertyDescriptor(constructor.__proto__, "of"); |
113 | 113 |
114 assertEquals(desc.configurable, false); | 114 assertEquals(desc.configurable, false); |
115 assertEquals(desc.enumerable, false); | 115 assertEquals(desc.enumerable, false); |
116 assertEquals(desc.writable, false); | 116 assertEquals(desc.writable, false); |
117 assertEquals(constructor.of.length, 0); | 117 assertEquals(constructor.of.length, 0); |
118 | 118 |
119 // %TypedArray%.of is not a constructor. | 119 // %TypedArray%.of is not a constructor. |
120 assertThrows(function() { new constructor.of(); }, TypeError); | 120 assertThrows(function() { new constructor.of(); }, TypeError); |
121 | 121 |
122 // For receivers which are not constructors %TypedArray%.of does not | 122 // For receivers which are not constructors %TypedArray%.of does not |
123 // allocate a typed array using a default constructor, but throws an | 123 // allocate a typed array using a default constructor, but throws an |
124 // exception. Note that this is different from Array.of, which uses | 124 // exception. Note that this is different from Array.of, which uses |
125 // Array as default constructor. | 125 // Array as default constructor. |
126 for (var x of [undefined, null, false, true, "cow", 42, 3.14]) { | 126 for (var x of [undefined, null, false, true, "cow", 42, 3.14]) { |
127 assertThrows(function () { constructor.of.call(x); }, TypeError); | 127 assertThrows(function () { constructor.of.call(x); }, TypeError); |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 for (var constructor of typedArrayConstructors) { | 131 for (var constructor of typedArrayConstructors) { |
132 TestTypedArrayOf(constructor); | 132 TestTypedArrayOf(constructor); |
133 } | 133 } |
OLD | NEW |