OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 // Flags: --harmony-sharedarraybuffer | 5 // Flags: --harmony-sharedarraybuffer |
6 | 6 |
7 function Module(stdlib, foreign, heap, offset) { | 7 function Module(stdlib, foreign, heap, offset) { |
8 "use asm"; | 8 "use asm"; |
9 var MEM8 = new stdlib.Int8Array(heap, offset); | 9 var MEM8 = new stdlib.Int8Array(heap, offset); |
10 var MEM16 = new stdlib.Int16Array(heap, offset); | 10 var MEM16 = new stdlib.Int16Array(heap, offset); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 }; | 61 }; |
62 } | 62 } |
63 | 63 |
64 function clearArray() { | 64 function clearArray() { |
65 var ui8 = new Uint8Array(sab); | 65 var ui8 = new Uint8Array(sab); |
66 for (var i = 0; i < sab.byteLength; ++i) { | 66 for (var i = 0; i < sab.byteLength; ++i) { |
67 ui8[i] = 0; | 67 ui8[i] = 0; |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 function testElementType(taConstr, f, oobValue, offset) { | 71 function testElementType(taConstr, f, offset) { |
72 clearArray(); | 72 clearArray(); |
73 | 73 |
74 var ta = new taConstr(sab, offset); | 74 var ta = new taConstr(sab, offset); |
75 var name = Object.prototype.toString.call(ta); | 75 var name = Object.prototype.toString.call(ta); |
76 assertEquals(10, f(0, 10), name); | 76 assertEquals(10, f(0, 10), name); |
77 assertEquals(10, ta[0]); | 77 assertEquals(10, ta[0]); |
78 // out of bounds | 78 // out of bounds |
79 assertEquals(oobValue, f(-1, 0), name); | 79 assertThrows(function() { f(-1, 0); }); |
80 assertEquals(oobValue, f(ta.length, 0), name); | 80 assertThrows(function() { f(ta.length, 0); }); |
81 } | 81 } |
82 | 82 |
83 function testElement(m, offset) { | 83 function testElement(m, offset) { |
84 testElementType(Int8Array, m.storei8, 0, offset); | 84 testElementType(Int8Array, m.storei8, offset); |
85 testElementType(Int16Array, m.storei16, 0, offset); | 85 testElementType(Int16Array, m.storei16, offset); |
86 testElementType(Int32Array, m.storei32, 0, offset); | 86 testElementType(Int32Array, m.storei32, offset); |
87 testElementType(Uint8Array, m.storeu8, 0, offset); | 87 testElementType(Uint8Array, m.storeu8, offset); |
88 testElementType(Uint16Array, m.storeu16, 0, offset); | 88 testElementType(Uint16Array, m.storeu16, offset); |
89 testElementType(Uint32Array, m.storeu32, 0, offset); | 89 testElementType(Uint32Array, m.storeu32, offset); |
90 } | 90 } |
91 | 91 |
92 var offset = 0; | 92 var offset = 0; |
93 var sab = new SharedArrayBuffer(16); | 93 var sab = new SharedArrayBuffer(16); |
94 var m1 = Module(this, {}, sab, offset); | 94 var m1 = Module(this, {}, sab, offset); |
95 testElement(m1, offset); | 95 testElement(m1, offset); |
96 | 96 |
97 offset = 32; | 97 offset = 32; |
98 sab = new SharedArrayBuffer(64); | 98 sab = new SharedArrayBuffer(64); |
99 var m2 = Module(this, {}, sab, offset); | 99 var m2 = Module(this, {}, sab, offset); |
100 testElement(m2, offset); | 100 testElement(m2, offset); |
OLD | NEW |