| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 }; | 55 }; |
| 56 } | 56 } |
| 57 | 57 |
| 58 function clearArray() { | 58 function clearArray() { |
| 59 var ui8 = new Uint8Array(sab); | 59 var ui8 = new Uint8Array(sab); |
| 60 for (var i = 0; i < sab.byteLength; ++i) { | 60 for (var i = 0; i < sab.byteLength; ++i) { |
| 61 ui8[i] = 0; | 61 ui8[i] = 0; |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 function testElementType(taConstr, f, oobValue, offset) { | 65 function testElementType(taConstr, f, offset) { |
| 66 clearArray(); | 66 clearArray(); |
| 67 | 67 |
| 68 var ta = new taConstr(sab, offset); | 68 var ta = new taConstr(sab, offset); |
| 69 var name = Object.prototype.toString.call(ta); | 69 var name = Object.prototype.toString.call(ta); |
| 70 ta[0] = 10; | 70 ta[0] = 10; |
| 71 assertEquals(10, f(0), name); | 71 assertEquals(10, f(0), name); |
| 72 assertEquals(0, f(1), name); | 72 assertEquals(0, f(1), name); |
| 73 // out of bounds | 73 // out of bounds |
| 74 assertEquals(oobValue, f(-1), name); | 74 assertThrows(function() { f(-1); }); |
| 75 assertEquals(oobValue, f(ta.length), name); | 75 assertThrows(function() { f(ta.length); }); |
| 76 } | 76 } |
| 77 | 77 |
| 78 function testElement(m, offset) { | 78 function testElement(m, offset) { |
| 79 testElementType(Int8Array, m.loadi8, 0, offset); | 79 testElementType(Int8Array, m.loadi8, offset); |
| 80 testElementType(Int16Array, m.loadi16, 0, offset); | 80 testElementType(Int16Array, m.loadi16, offset); |
| 81 testElementType(Int32Array, m.loadi32, 0, offset); | 81 testElementType(Int32Array, m.loadi32, offset); |
| 82 testElementType(Uint8Array, m.loadu8, 0, offset); | 82 testElementType(Uint8Array, m.loadu8, offset); |
| 83 testElementType(Uint16Array, m.loadu16, 0, offset); | 83 testElementType(Uint16Array, m.loadu16, offset); |
| 84 testElementType(Uint32Array, m.loadu32, 0, offset); | 84 testElementType(Uint32Array, m.loadu32, offset); |
| 85 } | 85 } |
| 86 | 86 |
| 87 var offset = 0; | 87 var offset = 0; |
| 88 var sab = new SharedArrayBuffer(16); | 88 var sab = new SharedArrayBuffer(16); |
| 89 var m1 = Module(this, {}, sab, offset); | 89 var m1 = Module(this, {}, sab, offset); |
| 90 testElement(m1, offset); | 90 testElement(m1, offset); |
| 91 | 91 |
| 92 offset = 32; | 92 offset = 32; |
| 93 sab = new SharedArrayBuffer(64); | 93 sab = new SharedArrayBuffer(64); |
| 94 var m2 = Module(this, {}, sab, offset); | 94 var m2 = Module(this, {}, sab, offset); |
| 95 testElement(m2, offset); | 95 testElement(m2, offset); |
| OLD | NEW |