| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 | |
| 28 // Flags: --harmony-sharedarraybuffer | |
| 29 | |
| 30 // SharedArrayBuffer | |
| 31 | |
| 32 function TestByteLength(param, expectedByteLength) { | |
| 33 var sab = new SharedArrayBuffer(param); | |
| 34 assertSame(expectedByteLength, sab.byteLength); | |
| 35 } | |
| 36 | |
| 37 function TestArrayBufferCreation() { | |
| 38 TestByteLength(1, 1); | |
| 39 TestByteLength(256, 256); | |
| 40 TestByteLength(2.567, 2); | |
| 41 | |
| 42 TestByteLength("abc", 0); | |
| 43 | |
| 44 TestByteLength(0, 0); | |
| 45 | |
| 46 assertThrows(function() { new SharedArrayBuffer(-10); }, RangeError); | |
| 47 assertThrows(function() { new SharedArrayBuffer(-2.567); }, RangeError); | |
| 48 | |
| 49 /* TODO[dslomov]: Reenable the test | |
| 50 assertThrows(function() { | |
| 51 var ab1 = new SharedArrayBuffer(0xFFFFFFFFFFFF) | |
| 52 }, RangeError); | |
| 53 */ | |
| 54 | |
| 55 var sab = new SharedArrayBuffer(); | |
| 56 assertSame(0, sab.byteLength); | |
| 57 assertEquals("[object SharedArrayBuffer]", | |
| 58 Object.prototype.toString.call(sab)); | |
| 59 } | |
| 60 | |
| 61 TestArrayBufferCreation(); | |
| 62 | |
| 63 function TestByteLengthNotWritable() { | |
| 64 var sab = new SharedArrayBuffer(1024); | |
| 65 assertSame(1024, sab.byteLength); | |
| 66 | |
| 67 assertThrows(function() { "use strict"; sab.byteLength = 42; }, TypeError); | |
| 68 } | |
| 69 | |
| 70 TestByteLengthNotWritable(); | |
| 71 | |
| 72 function TestArrayBufferNoSlice() { | |
| 73 var sab = new SharedArrayBuffer(10); | |
| 74 assertEquals(undefined, sab.slice); | |
| 75 } | |
| 76 | |
| 77 TestArrayBufferNoSlice(); | |
| 78 | |
| 79 // Typed arrays using SharedArrayBuffers | |
| 80 | |
| 81 // TODO(binji): how many of these tests are necessary if there are no new | |
| 82 // TypedArray types? | |
| 83 | |
| 84 function MakeSharedTypedArray(constr, numElements) { | |
| 85 var sab = new SharedArrayBuffer(constr.BYTES_PER_ELEMENT * numElements); | |
| 86 return new constr(sab); | |
| 87 } | |
| 88 | |
| 89 function TestTypedArray(constr, elementSize, typicalElement) { | |
| 90 assertSame(elementSize, constr.BYTES_PER_ELEMENT); | |
| 91 | |
| 92 var sab = new SharedArrayBuffer(256*elementSize); | |
| 93 | |
| 94 var a0 = new constr(30); | |
| 95 assertEquals("[object " + constr.name + "]", | |
| 96 Object.prototype.toString.call(a0)); | |
| 97 | |
| 98 // TODO(binji): Should this return false here? It is a view, but it doesn't | |
| 99 // view a SharedArrayBuffer... | |
| 100 assertTrue(SharedArrayBuffer.isView(a0)); | |
| 101 assertSame(elementSize, a0.BYTES_PER_ELEMENT); | |
| 102 assertSame(30, a0.length); | |
| 103 assertSame(30*elementSize, a0.byteLength); | |
| 104 assertSame(0, a0.byteOffset); | |
| 105 assertSame(30*elementSize, a0.buffer.byteLength); | |
| 106 | |
| 107 var aOverBufferLen0 = new constr(sab, 128*elementSize, 0); | |
| 108 assertSame(sab, aOverBufferLen0.buffer); | |
| 109 assertSame(elementSize, aOverBufferLen0.BYTES_PER_ELEMENT); | |
| 110 assertSame(0, aOverBufferLen0.length); | |
| 111 assertSame(0, aOverBufferLen0.byteLength); | |
| 112 assertSame(128*elementSize, aOverBufferLen0.byteOffset); | |
| 113 | |
| 114 var a1 = new constr(sab, 128*elementSize, 128); | |
| 115 assertSame(sab, a1.buffer); | |
| 116 assertSame(elementSize, a1.BYTES_PER_ELEMENT); | |
| 117 assertSame(128, a1.length); | |
| 118 assertSame(128*elementSize, a1.byteLength); | |
| 119 assertSame(128*elementSize, a1.byteOffset); | |
| 120 | |
| 121 | |
| 122 var a2 = new constr(sab, 64*elementSize, 128); | |
| 123 assertSame(sab, a2.buffer); | |
| 124 assertSame(elementSize, a2.BYTES_PER_ELEMENT); | |
| 125 assertSame(128, a2.length); | |
| 126 assertSame(128*elementSize, a2.byteLength); | |
| 127 assertSame(64*elementSize, a2.byteOffset); | |
| 128 | |
| 129 var a3 = new constr(sab, 192*elementSize); | |
| 130 assertSame(sab, a3.buffer); | |
| 131 assertSame(64, a3.length); | |
| 132 assertSame(64*elementSize, a3.byteLength); | |
| 133 assertSame(192*elementSize, a3.byteOffset); | |
| 134 | |
| 135 var a4 = new constr(sab); | |
| 136 assertSame(sab, a4.buffer); | |
| 137 assertSame(256, a4.length); | |
| 138 assertSame(256*elementSize, a4.byteLength); | |
| 139 assertSame(0, a4.byteOffset); | |
| 140 | |
| 141 | |
| 142 var i; | |
| 143 for (i = 0; i < 128; i++) { | |
| 144 a1[i] = typicalElement; | |
| 145 } | |
| 146 | |
| 147 for (i = 0; i < 128; i++) { | |
| 148 assertSame(typicalElement, a1[i]); | |
| 149 } | |
| 150 | |
| 151 for (i = 0; i < 64; i++) { | |
| 152 assertSame(0, a2[i]); | |
| 153 } | |
| 154 | |
| 155 for (i = 64; i < 128; i++) { | |
| 156 assertSame(typicalElement, a2[i]); | |
| 157 } | |
| 158 | |
| 159 for (i = 0; i < 64; i++) { | |
| 160 assertSame(typicalElement, a3[i]); | |
| 161 } | |
| 162 | |
| 163 for (i = 0; i < 128; i++) { | |
| 164 assertSame(0, a4[i]); | |
| 165 } | |
| 166 | |
| 167 for (i = 128; i < 256; i++) { | |
| 168 assertSame(typicalElement, a4[i]); | |
| 169 } | |
| 170 | |
| 171 var aAtTheEnd = new constr(sab, 256*elementSize); | |
| 172 assertSame(elementSize, aAtTheEnd.BYTES_PER_ELEMENT); | |
| 173 assertSame(0, aAtTheEnd.length); | |
| 174 assertSame(0, aAtTheEnd.byteLength); | |
| 175 assertSame(256*elementSize, aAtTheEnd.byteOffset); | |
| 176 | |
| 177 assertThrows(function () { new constr(sab, 257*elementSize); }, RangeError); | |
| 178 assertThrows( | |
| 179 function () { new constr(sab, 128*elementSize, 192); }, | |
| 180 RangeError); | |
| 181 | |
| 182 if (elementSize !== 1) { | |
| 183 assertThrows(function() { new constr(sab, 128*elementSize - 1, 10); }, | |
| 184 RangeError); | |
| 185 var unalignedArrayBuffer = new SharedArrayBuffer(10*elementSize + 1); | |
| 186 var goodArray = new constr(unalignedArrayBuffer, 0, 10); | |
| 187 assertSame(10, goodArray.length); | |
| 188 assertSame(10*elementSize, goodArray.byteLength); | |
| 189 assertThrows(function() { new constr(unalignedArrayBuffer)}, RangeError); | |
| 190 assertThrows(function() { new constr(unalignedArrayBuffer, 5*elementSize)}, | |
| 191 RangeError); | |
| 192 } | |
| 193 | |
| 194 var abLen0 = new SharedArrayBuffer(0); | |
| 195 var aOverAbLen0 = new constr(abLen0); | |
| 196 assertSame(abLen0, aOverAbLen0.buffer); | |
| 197 assertSame(elementSize, aOverAbLen0.BYTES_PER_ELEMENT); | |
| 198 assertSame(0, aOverAbLen0.length); | |
| 199 assertSame(0, aOverAbLen0.byteLength); | |
| 200 assertSame(0, aOverAbLen0.byteOffset); | |
| 201 | |
| 202 var a = new constr(sab, 64*elementSize, 128); | |
| 203 assertEquals("[object " + constr.name + "]", | |
| 204 Object.prototype.toString.call(a)); | |
| 205 var desc = Object.getOwnPropertyDescriptor( | |
| 206 constr.prototype, Symbol.toStringTag); | |
| 207 assertTrue(desc.configurable); | |
| 208 assertFalse(desc.enumerable); | |
| 209 assertFalse(!!desc.writable); | |
| 210 assertFalse(!!desc.set); | |
| 211 assertEquals("function", typeof desc.get); | |
| 212 } | |
| 213 | |
| 214 TestTypedArray(Uint8Array, 1, 0xFF); | |
| 215 TestTypedArray(Int8Array, 1, -0x7F); | |
| 216 TestTypedArray(Uint16Array, 2, 0xFFFF); | |
| 217 TestTypedArray(Int16Array, 2, -0x7FFF); | |
| 218 TestTypedArray(Uint32Array, 4, 0xFFFFFFFF); | |
| 219 TestTypedArray(Int32Array, 4, -0x7FFFFFFF); | |
| 220 TestTypedArray(Float32Array, 4, 0.5); | |
| 221 TestTypedArray(Float64Array, 8, 0.5); | |
| 222 TestTypedArray(Uint8ClampedArray, 1, 0xFF); | |
| 223 | |
| 224 | |
| 225 function SubarrayTestCase(constructor, item, expectedResultLen, | |
| 226 expectedStartIndex, initialLen, start, end) { | |
| 227 var a = MakeSharedTypedArray(constructor, initialLen); | |
| 228 var s = a.subarray(start, end); | |
| 229 assertSame(constructor, s.constructor); | |
| 230 assertSame(expectedResultLen, s.length); | |
| 231 if (s.length > 0) { | |
| 232 s[0] = item; | |
| 233 assertSame(item, a[expectedStartIndex]); | |
| 234 } | |
| 235 } | |
| 236 | |
| 237 function TestSubArray(constructor, item) { | |
| 238 SubarrayTestCase(constructor, item, 512, 512, 1024, 512, 1024); | |
| 239 SubarrayTestCase(constructor, item, 512, 512, 1024, 512); | |
| 240 | |
| 241 SubarrayTestCase(constructor, item, 0, undefined, 0, 1, 20); | |
| 242 SubarrayTestCase(constructor, item, 100, 0, 100, 0, 100); | |
| 243 SubarrayTestCase(constructor, item, 100, 0, 100, 0, 1000); | |
| 244 SubarrayTestCase(constructor, item, 0, undefined, 100, 5, 1); | |
| 245 | |
| 246 SubarrayTestCase(constructor, item, 1, 89, 100, -11, -10); | |
| 247 SubarrayTestCase(constructor, item, 9, 90, 100, -10, 99); | |
| 248 SubarrayTestCase(constructor, item, 0, undefined, 100, -10, 80); | |
| 249 SubarrayTestCase(constructor, item, 10,80, 100, 80, -10); | |
| 250 | |
| 251 SubarrayTestCase(constructor, item, 10,90, 100, 90, "100"); | |
| 252 SubarrayTestCase(constructor, item, 10,90, 100, "90", "100"); | |
| 253 | |
| 254 SubarrayTestCase(constructor, item, 0, undefined, 100, 90, "abc"); | |
| 255 SubarrayTestCase(constructor, item, 10,0, 100, "abc", 10); | |
| 256 | |
| 257 SubarrayTestCase(constructor, item, 10,0, 100, 0.96, 10.96); | |
| 258 SubarrayTestCase(constructor, item, 10,0, 100, 0.96, 10.01); | |
| 259 SubarrayTestCase(constructor, item, 10,0, 100, 0.01, 10.01); | |
| 260 SubarrayTestCase(constructor, item, 10,0, 100, 0.01, 10.96); | |
| 261 | |
| 262 | |
| 263 SubarrayTestCase(constructor, item, 10,90, 100, 90); | |
| 264 SubarrayTestCase(constructor, item, 10,90, 100, -10); | |
| 265 } | |
| 266 | |
| 267 TestSubArray(Uint8Array, 0xFF); | |
| 268 TestSubArray(Int8Array, -0x7F); | |
| 269 TestSubArray(Uint16Array, 0xFFFF); | |
| 270 TestSubArray(Int16Array, -0x7FFF); | |
| 271 TestSubArray(Uint32Array, 0xFFFFFFFF); | |
| 272 TestSubArray(Int32Array, -0x7FFFFFFF); | |
| 273 TestSubArray(Float32Array, 0.5); | |
| 274 TestSubArray(Float64Array, 0.5); | |
| 275 TestSubArray(Uint8ClampedArray, 0xFF); | |
| 276 | |
| 277 function TestTypedArrayOutOfRange(constructor, value, result) { | |
| 278 var a = MakeSharedTypedArray(constructor, 1); | |
| 279 a[0] = value; | |
| 280 assertSame(result, a[0]); | |
| 281 } | |
| 282 | |
| 283 TestTypedArrayOutOfRange(Uint8Array, 0x1FA, 0xFA); | |
| 284 TestTypedArrayOutOfRange(Uint8Array, -1, 0xFF); | |
| 285 | |
| 286 TestTypedArrayOutOfRange(Int8Array, 0x1FA, 0x7A - 0x80); | |
| 287 | |
| 288 TestTypedArrayOutOfRange(Uint16Array, 0x1FFFA, 0xFFFA); | |
| 289 TestTypedArrayOutOfRange(Uint16Array, -1, 0xFFFF); | |
| 290 TestTypedArrayOutOfRange(Int16Array, 0x1FFFA, 0x7FFA - 0x8000); | |
| 291 | |
| 292 TestTypedArrayOutOfRange(Uint32Array, 0x1FFFFFFFA, 0xFFFFFFFA); | |
| 293 TestTypedArrayOutOfRange(Uint32Array, -1, 0xFFFFFFFF); | |
| 294 TestTypedArrayOutOfRange(Int32Array, 0x1FFFFFFFA, 0x7FFFFFFA - 0x80000000); | |
| 295 | |
| 296 TestTypedArrayOutOfRange(Uint8ClampedArray, 0x1FA, 0xFF); | |
| 297 TestTypedArrayOutOfRange(Uint8ClampedArray, -1, 0); | |
| 298 | |
| 299 var typedArrayConstructors = [ | |
| 300 Uint8Array, | |
| 301 Int8Array, | |
| 302 Uint16Array, | |
| 303 Int16Array, | |
| 304 Uint32Array, | |
| 305 Int32Array, | |
| 306 Uint8ClampedArray, | |
| 307 Float32Array, | |
| 308 Float64Array]; | |
| 309 | |
| 310 function TestPropertyTypeChecks(constructor) { | |
| 311 function CheckProperty(name) { | |
| 312 var d = Object.getOwnPropertyDescriptor(constructor.prototype, name); | |
| 313 var o = {}; | |
| 314 assertThrows(function() {d.get.call(o);}, TypeError); | |
| 315 for (var i = 0; i < typedArrayConstructors.length; i++) { | |
| 316 var ctor = typedArrayConstructors[i]; | |
| 317 var a = MakeSharedTypedArray(ctor, 10); | |
| 318 if (ctor === constructor) { | |
| 319 d.get.call(a); // shouldn't throw | |
| 320 } else { | |
| 321 assertThrows(function() {d.get.call(a);}, TypeError); | |
| 322 } | |
| 323 } | |
| 324 } | |
| 325 | |
| 326 CheckProperty("buffer"); | |
| 327 CheckProperty("byteOffset"); | |
| 328 CheckProperty("byteLength"); | |
| 329 CheckProperty("length"); | |
| 330 } | |
| 331 | |
| 332 for(i = 0; i < typedArrayConstructors.length; i++) { | |
| 333 TestPropertyTypeChecks(typedArrayConstructors[i]); | |
| 334 } | |
| 335 | |
| 336 function TestTypedArraySet() { | |
| 337 // Test array.set in different combinations. | |
| 338 | |
| 339 function assertArrayPrefix(expected, array) { | |
| 340 for (var i = 0; i < expected.length; ++i) { | |
| 341 assertEquals(expected[i], array[i]); | |
| 342 } | |
| 343 } | |
| 344 | |
| 345 // SharedTypedArrays don't allow initialization via array-like | |
| 346 function initializeFromArray(constructor, array) { | |
| 347 var buffer = MakeSharedTypedArray(constructor, array.length); | |
| 348 for (var i = 0; i < array.length; ++i) { | |
| 349 buffer[i] = array[i]; | |
| 350 } | |
| 351 return buffer; | |
| 352 } | |
| 353 | |
| 354 var a11 = initializeFromArray(Int16Array, [1, 2, 3, 4, 0, -1]) | |
| 355 var a12 = MakeSharedTypedArray(Uint16Array, 15); | |
| 356 a12.set(a11, 3) | |
| 357 assertArrayPrefix([0, 0, 0, 1, 2, 3, 4, 0, 0xffff, 0, 0], a12) | |
| 358 assertThrows(function(){ a11.set(a12) }) | |
| 359 | |
| 360 var a21 = [1, undefined, 10, NaN, 0, -1, {valueOf: function() {return 3}}] | |
| 361 var a22 = MakeSharedTypedArray(Int32Array, 12) | |
| 362 a22.set(a21, 2) | |
| 363 assertArrayPrefix([0, 0, 1, 0, 10, 0, 0, -1, 3, 0], a22) | |
| 364 | |
| 365 var a31 = initializeFromArray(Float32Array, [2, 4, 6, 8, 11, NaN, 1/0, -3]) | |
| 366 var a32 = a31.subarray(2, 6) | |
| 367 a31.set(a32, 4) | |
| 368 assertArrayPrefix([2, 4, 6, 8, 6, 8, 11, NaN], a31) | |
| 369 assertArrayPrefix([6, 8, 6, 8], a32) | |
| 370 | |
| 371 var a4 = initializeFromArray(Uint8ClampedArray, [3,2,5,6]) | |
| 372 a4.set(a4) | |
| 373 assertArrayPrefix([3, 2, 5, 6], a4) | |
| 374 | |
| 375 // Cases with overlapping backing store but different element sizes. | |
| 376 var b = new SharedArrayBuffer(4) | |
| 377 var a5 = new Int16Array(b) | |
| 378 var a50 = new Int8Array(b) | |
| 379 var a51 = new Int8Array(b, 0, 2) | |
| 380 var a52 = new Int8Array(b, 1, 2) | |
| 381 var a53 = new Int8Array(b, 2, 2) | |
| 382 | |
| 383 a5.set([0x5050, 0x0a0a]) | |
| 384 assertArrayPrefix([0x50, 0x50, 0x0a, 0x0a], a50) | |
| 385 assertArrayPrefix([0x50, 0x50], a51) | |
| 386 assertArrayPrefix([0x50, 0x0a], a52) | |
| 387 assertArrayPrefix([0x0a, 0x0a], a53) | |
| 388 | |
| 389 a50.set([0x50, 0x50, 0x0a, 0x0a]) | |
| 390 a51.set(a5) | |
| 391 assertArrayPrefix([0x50, 0x0a, 0x0a, 0x0a], a50) | |
| 392 | |
| 393 a50.set([0x50, 0x50, 0x0a, 0x0a]) | |
| 394 a52.set(a5) | |
| 395 assertArrayPrefix([0x50, 0x50, 0x0a, 0x0a], a50) | |
| 396 | |
| 397 a50.set([0x50, 0x50, 0x0a, 0x0a]) | |
| 398 a53.set(a5) | |
| 399 assertArrayPrefix([0x50, 0x50, 0x50, 0x0a], a50) | |
| 400 | |
| 401 a50.set([0x50, 0x51, 0x0a, 0x0b]) | |
| 402 a5.set(a51) | |
| 403 assertArrayPrefix([0x0050, 0x0051], a5) | |
| 404 | |
| 405 a50.set([0x50, 0x51, 0x0a, 0x0b]) | |
| 406 a5.set(a52) | |
| 407 assertArrayPrefix([0x0051, 0x000a], a5) | |
| 408 | |
| 409 a50.set([0x50, 0x51, 0x0a, 0x0b]) | |
| 410 a5.set(a53) | |
| 411 assertArrayPrefix([0x000a, 0x000b], a5) | |
| 412 | |
| 413 // Mixed types of same size. | |
| 414 var a61 = initializeFromArray(Float32Array, [1.2, 12.3]) | |
| 415 var a62 = MakeSharedTypedArray(Int32Array, 2) | |
| 416 a62.set(a61) | |
| 417 assertArrayPrefix([1, 12], a62) | |
| 418 a61.set(a62) | |
| 419 assertArrayPrefix([1, 12], a61) | |
| 420 | |
| 421 // Invalid source | |
| 422 var a = MakeSharedTypedArray(Uint16Array, 50); | |
| 423 var expected = []; | |
| 424 for (i = 0; i < 50; i++) { | |
| 425 a[i] = i; | |
| 426 expected.push(i); | |
| 427 } | |
| 428 a.set({}); | |
| 429 assertArrayPrefix(expected, a); | |
| 430 assertThrows(function() { a.set.call({}) }, TypeError); | |
| 431 assertThrows(function() { a.set.call([]) }, TypeError); | |
| 432 | |
| 433 assertThrows(function() { a.set(0); }, TypeError); | |
| 434 assertThrows(function() { a.set(0, 1); }, TypeError); | |
| 435 } | |
| 436 | |
| 437 TestTypedArraySet(); | |
| 438 | |
| 439 function TestTypedArraysWithIllegalIndices() { | |
| 440 var a = MakeSharedTypedArray(Int32Array, 100); | |
| 441 | |
| 442 a[-10] = 10; | |
| 443 assertEquals(undefined, a[-10]); | |
| 444 a["-10"] = 10; | |
| 445 assertEquals(undefined, a["-10"]); | |
| 446 | |
| 447 var s = " -10"; | |
| 448 a[s] = 10; | |
| 449 assertEquals(10, a[s]); | |
| 450 var s1 = " -10 "; | |
| 451 a[s] = 10; | |
| 452 assertEquals(10, a[s]); | |
| 453 | |
| 454 a["-1e2"] = 10; | |
| 455 assertEquals(10, a["-1e2"]); | |
| 456 assertEquals(undefined, a[-1e2]); | |
| 457 | |
| 458 a["-0"] = 256; | |
| 459 var s2 = " -0"; | |
| 460 a[s2] = 255; | |
| 461 assertEquals(undefined, a["-0"]); | |
| 462 assertEquals(255, a[s2]); | |
| 463 assertEquals(0, a[-0]); | |
| 464 | |
| 465 /* Chromium bug: 424619 | |
| 466 * a[-Infinity] = 50; | |
| 467 * assertEquals(undefined, a[-Infinity]); | |
| 468 */ | |
| 469 a[1.5] = 10; | |
| 470 assertEquals(undefined, a[1.5]); | |
| 471 var nan = Math.sqrt(-1); | |
| 472 a[nan] = 5; | |
| 473 assertEquals(undefined, a[nan]); | |
| 474 | |
| 475 var x = 0; | |
| 476 var y = -0; | |
| 477 assertEquals(Infinity, 1/x); | |
| 478 assertEquals(-Infinity, 1/y); | |
| 479 a[x] = 5; | |
| 480 a[y] = 27; | |
| 481 assertEquals(27, a[x]); | |
| 482 assertEquals(27, a[y]); | |
| 483 } | |
| 484 | |
| 485 TestTypedArraysWithIllegalIndices(); | |
| 486 | |
| 487 function TestTypedArraysWithIllegalIndicesStrict() { | |
| 488 'use strict'; | |
| 489 var a = MakeSharedTypedArray(Int32Array, 100); | |
| 490 | |
| 491 a[-10] = 10; | |
| 492 assertEquals(undefined, a[-10]); | |
| 493 a["-10"] = 10; | |
| 494 assertEquals(undefined, a["-10"]); | |
| 495 | |
| 496 var s = " -10"; | |
| 497 a[s] = 10; | |
| 498 assertEquals(10, a[s]); | |
| 499 var s1 = " -10 "; | |
| 500 a[s] = 10; | |
| 501 assertEquals(10, a[s]); | |
| 502 | |
| 503 a["-1e2"] = 10; | |
| 504 assertEquals(10, a["-1e2"]); | |
| 505 assertEquals(undefined, a[-1e2]); | |
| 506 | |
| 507 a["-0"] = 256; | |
| 508 var s2 = " -0"; | |
| 509 a[s2] = 255; | |
| 510 assertEquals(undefined, a["-0"]); | |
| 511 assertEquals(255, a[s2]); | |
| 512 assertEquals(0, a[-0]); | |
| 513 | |
| 514 /* Chromium bug: 424619 | |
| 515 * a[-Infinity] = 50; | |
| 516 * assertEquals(undefined, a[-Infinity]); | |
| 517 */ | |
| 518 a[1.5] = 10; | |
| 519 assertEquals(undefined, a[1.5]); | |
| 520 var nan = Math.sqrt(-1); | |
| 521 a[nan] = 5; | |
| 522 assertEquals(undefined, a[nan]); | |
| 523 | |
| 524 var x = 0; | |
| 525 var y = -0; | |
| 526 assertEquals(Infinity, 1/x); | |
| 527 assertEquals(-Infinity, 1/y); | |
| 528 a[x] = 5; | |
| 529 a[y] = 27; | |
| 530 assertEquals(27, a[x]); | |
| 531 assertEquals(27, a[y]); | |
| 532 } | |
| 533 | |
| 534 TestTypedArraysWithIllegalIndicesStrict(); | |
| 535 | |
| 536 // General tests for properties | |
| 537 | |
| 538 // Test property attribute [[Enumerable]] | |
| 539 function TestEnumerable(func, obj) { | |
| 540 function props(x) { | |
| 541 var array = []; | |
| 542 for (var p in x) array.push(p); | |
| 543 return array.sort(); | |
| 544 } | |
| 545 assertArrayEquals([], props(func)); | |
| 546 assertArrayEquals([], props(func.prototype)); | |
| 547 if (obj) | |
| 548 assertArrayEquals([], props(obj)); | |
| 549 } | |
| 550 TestEnumerable(ArrayBuffer, new SharedArrayBuffer()); | |
| 551 for(i = 0; i < typedArrayConstructors.length; i++) { | |
| 552 TestEnumerable(typedArrayConstructors[i]); | |
| 553 } | |
| 554 | |
| 555 // Test arbitrary properties on ArrayBuffer | |
| 556 function TestArbitrary(m) { | |
| 557 function TestProperty(map, property, value) { | |
| 558 map[property] = value; | |
| 559 assertEquals(value, map[property]); | |
| 560 } | |
| 561 for (var i = 0; i < 20; i++) { | |
| 562 TestProperty(m, 'key' + i, 'val' + i); | |
| 563 TestProperty(m, 'foo' + i, 'bar' + i); | |
| 564 } | |
| 565 } | |
| 566 TestArbitrary(new SharedArrayBuffer(256)); | |
| 567 for(i = 0; i < typedArrayConstructors.length; i++) { | |
| 568 TestArbitrary(MakeSharedTypedArray(typedArrayConstructors[i], 10)); | |
| 569 } | |
| 570 | |
| 571 // Test direct constructor call | |
| 572 assertThrows(function() { SharedArrayBuffer(); }, TypeError); | |
| 573 for(i = 0; i < typedArrayConstructors.length; i++) { | |
| 574 assertThrows(function(i) { typedArrayConstructors[i](); }.bind(this, i), | |
| 575 TypeError); | |
| 576 } | |
| OLD | NEW |