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

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

Issue 13064003: First steps towards implementing ArrayBuffer &co in V8 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added forgotten tests Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/typedarray.js ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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);
41
42 TestByteLength("abc", 0);
43
44 TestByteLength(0, 0);
45
46 assertThrows(function() {
47 var ab1 = new __ArrayBuffer(0xFFFFFFFFFFFF)
48 }, RangeError);
49
50 var ab = new __ArrayBuffer();
51 assertSame(0, ab.byteLength);
52 }
53
54 TestArrayBufferCreation();
55
56 function TestByteLengthNotWritable() {
57 var ab = new __ArrayBuffer(1024);
58 assertSame(1024, ab.byteLength);
59
60 assertThrows(function() { "use strict"; ab.byteLength = 42; }, TypeError);
61 }
62
63 TestByteLengthNotWritable();
64
65 function TestSlice(expectedResultLen, initialLen, start, end) {
66 var ab = new __ArrayBuffer(initialLen);
67 var slice = ab.slice(start, end);
68 assertSame(expectedResultLen, slice.byteLength);
69 }
70
71 function TestArrayBufferSlice() {
72 var ab = new __ArrayBuffer(1024);
73 var ab1 = ab.slice(512, 1024);
74 assertSame(512, ab1.byteLength);
75
76 TestSlice(512, 1024, 512, 1024);
77 TestSlice(512, 1024, 512);
78
79 TestSlice(0, 0, 1, 20);
80 TestSlice(100, 100, 0, 100);
81 TestSlice(100, 100, 0, 1000);
82 TestSlice(0, 100, 5, 1);
83
84 TestSlice(1, 100, -11, -10);
85 TestSlice(9, 100, -10, 99);
86 TestSlice(0, 100, -10, 80);
87 TestSlice(10, 100, 80, -10);
88
89 TestSlice(10, 100, 90, "100");
90 TestSlice(10, 100, "90", "100");
91
92 TestSlice(0, 100, 90, "abc");
93 TestSlice(10, 100, "abc", 10);
94
95 TestSlice(10, 100, 0.96, 10.96);
96 TestSlice(10, 100, 0.96, 10.01);
97 TestSlice(10, 100, 0.01, 10.01);
98 TestSlice(10, 100, 0.01, 10.96);
99
100
101 TestSlice(10, 100, 90);
102 TestSlice(10, 100, -10);
103 }
104
105 TestArrayBufferSlice();
106
107 // Test property attribute [[Enumerable]]
108 function TestEnumerable(func) {
109 function props(x) {
110 var array = [];
111 for (var p in x) array.push(p);
112 return array.sort();
113 }
114 assertArrayEquals([], props(func));
115 assertArrayEquals([], props(func.prototype));
116 assertArrayEquals([], props(new func()));
117 }
118 TestEnumerable(__ArrayBuffer);
119
120
121 // Test arbitrary properties on ArrayBuffer
122 function TestArbitrary(m) {
123 function TestProperty(map, property, value) {
124 map[property] = value;
125 assertEquals(value, map[property]);
126 }
127 for (var i = 0; i < 20; i++) {
128 TestProperty(m, i, 'val' + i);
129 TestProperty(m, 'foo' + i, 'bar' + i);
130 }
131 }
132 TestArbitrary(new __ArrayBuffer(256));
133
134
135 // Test direct constructor call
136 assertTrue(__ArrayBuffer() instanceof __ArrayBuffer);
OLDNEW
« no previous file with comments | « src/typedarray.js ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698