OLD | NEW |
1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 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 function is_little_endian() { |
| 6 var buffer = new ArrayBuffer(4); |
| 7 HEAP32 = new Int32Array(buffer); |
| 8 HEAPU8 = new Uint8Array(buffer); |
| 9 HEAP32[0] = 255; |
| 10 if (HEAPU8[0] === 255 && HEAPU8[3] === 0) |
| 11 return true; |
| 12 else |
| 13 return false; |
| 14 } |
| 15 |
5 (function () { | 16 (function () { |
6 var buffer = new ArrayBuffer(8); | 17 var buffer = new ArrayBuffer(8); |
7 var i32 = new Int32Array(buffer); | 18 var i32 = new Int32Array(buffer); |
8 var f64 = new Float64Array(buffer); | 19 var f64 = new Float64Array(buffer); |
9 | 20 |
10 function foo() { | 21 function foo() { |
11 f64[0] = 1; | 22 f64[0] = 1; |
12 var x = f64[0]; | 23 var x = f64[0]; |
13 return i32[0]; | 24 if (is_little_endian()) |
| 25 return i32[0]; |
| 26 else |
| 27 return i32[1]; |
14 } | 28 } |
15 assertEquals(0, foo()); | 29 assertEquals(0, foo()); |
16 })(); | 30 })(); |
17 | 31 |
18 (function () { | 32 (function () { |
19 var buffer = new ArrayBuffer(8); | 33 var buffer = new ArrayBuffer(8); |
20 var i16 = new Int16Array(buffer); | 34 var i16 = new Int16Array(buffer); |
21 var i32 = new Int32Array(buffer); | 35 var i32 = new Int32Array(buffer); |
22 | 36 |
23 function foo() { | 37 function foo() { |
24 i32[0] = 0x10001; | 38 i32[0] = 0x20001; |
25 var x = i32[0]; | 39 var x = i32[0]; |
26 return i16[0]; | 40 if (is_little_endian()) |
| 41 return i16[0]; |
| 42 else |
| 43 return i16[1]; |
27 } | 44 } |
28 assertEquals(1, foo()); | 45 assertEquals(1, foo()); |
29 })(); | 46 })(); |
OLD | NEW |