Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 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-typed-arrays | |
| 29 | |
| 30 function TestByteLength(param, expectedByteLength) { | |
| 31 var ab = new __ArrayBuffer(param); | |
| 32 assertSame(expectedByteLength, ab.byteLength); | |
| 33 } | |
| 34 | |
| 35 function TestArrayBufferCreation() { | |
| 36 TestByteLength(1, 1); | |
| 37 TestByteLength(256, 256); | |
| 38 TestByteLength(-10, 0); | |
| 39 TestByteLength(2.567, 2); | |
| 40 TestByteLength(-2.567, 0); | |
|
rossberg
2013/03/27 17:33:14
Can we afford to include a TestByteLength(l, l) wi
Dmitry Lomov (no reviews)
2013/03/27 18:45:00
Hmm, I changed what we throw from OutOfMemory (unc
rossberg
2013/03/28 09:45:15
Sorry, I don't like it. RangeError is for domain v
| |
| 41 | |
| 42 TestByteLength("abc", 0); | |
| 43 | |
| 44 var ab = new __ArrayBuffer(); | |
| 45 assertSame(0, ab.byteLength); | |
| 46 } | |
| 47 | |
| 48 TestArrayBufferCreation(); | |
| 49 | |
| 50 function TestByteLengthNotWritable() { | |
| 51 var ab = new __ArrayBuffer(1024); | |
| 52 assertSame(1024, ab.byteLength); | |
| 53 | |
| 54 assertThrows(function() { "use strict"; ab.byteLength = 42; }, TypeError); | |
| 55 } | |
| 56 | |
| 57 TestByteLengthNotWritable(); | |
| 58 | |
| 59 function CheckSlice(expectedResultLen, initialLen, start, end) { | |
|
rossberg
2013/03/27 17:33:14
Nit: TestSlice, for consistency.
Dmitry Lomov (no reviews)
2013/03/27 18:45:00
Done.
| |
| 60 var ab = new __ArrayBuffer(initialLen); | |
| 61 var slice = ab.slice(start, end); | |
| 62 assertSame(expectedResultLen, slice.byteLength); | |
| 63 } | |
| 64 | |
| 65 function TestArrayBufferSlice() { | |
| 66 var ab = new __ArrayBuffer(1024); | |
| 67 var ab1 = ab.slice(512, 1024); | |
| 68 assertSame(512, ab1.byteLength); | |
| 69 | |
| 70 CheckSlice(512, 1024, 512, 1024); | |
| 71 CheckSlice(512, 1024, 512); | |
| 72 | |
| 73 CheckSlice(0, 0, 1, 20); | |
| 74 CheckSlice(100, 100, 0, 100); | |
| 75 CheckSlice(100, 100, 0, 1000); | |
| 76 CheckSlice(0, 100, 5, 1); | |
| 77 | |
| 78 CheckSlice(1, 100, -11, -10); | |
| 79 CheckSlice(9, 100, -10, 99); | |
| 80 CheckSlice(0, 100, -10, 80); | |
| 81 CheckSlice(10, 100, 80, -10); | |
| 82 | |
| 83 CheckSlice(10, 100, 90); | |
| 84 CheckSlice(10, 100, -10); | |
| 85 } | |
| 86 | |
| 87 TestArrayBufferSlice(); | |
|
rossberg
2013/03/27 17:33:14
Maybe add a sanity check for calling slice with we
Dmitry Lomov (no reviews)
2013/03/27 18:45:00
Done.
rossberg
2013/03/28 09:45:15
I especially thought of calls with arguments of bo
| |
| 88 | |
| 89 // Test property attribute [[Enumerable]] | |
| 90 function TestEnumerable(func) { | |
| 91 function props(x) { | |
| 92 var array = []; | |
| 93 for (var p in x) array.push(p); | |
| 94 return array.sort(); | |
| 95 } | |
| 96 assertArrayEquals([], props(func)); | |
| 97 assertArrayEquals([], props(func.prototype)); | |
| 98 assertArrayEquals([], props(new func())); | |
| 99 } | |
| 100 TestEnumerable(__ArrayBuffer); | |
| 101 | |
| 102 | |
| 103 // Test arbitrary properties on ArrayBuffer | |
| 104 function TestArbitrary(m) { | |
| 105 function TestProperty(map, property, value) { | |
| 106 map[property] = value; | |
| 107 assertEquals(value, map[property]); | |
| 108 } | |
| 109 for (var i = 0; i < 20; i++) { | |
| 110 TestProperty(m, i, 'val' + i); | |
| 111 TestProperty(m, 'foo' + i, 'bar' + i); | |
| 112 } | |
| 113 } | |
| 114 TestArbitrary(new __ArrayBuffer(256)); | |
| 115 | |
| 116 | |
| 117 // Test direct constructor call | |
| 118 assertTrue(__ArrayBuffer() instanceof __ArrayBuffer); | |
| OLD | NEW |