Commit ee13cd3e authored by Milad Farazmand's avatar Milad Farazmand Committed by Commit Bot

[foozzie] Use Uint16Array to detect endianness

Converting from Uint32Array to Uint8Array will have"0"
set as the first byte on BE machines:
[0,0,AB,CD]
Using Uint16Array will produce the correct result:
[AB,CD]

Change-Id: I9069f14c60a088a52af6d287c88be4ad437ee04d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2064528Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Commit-Queue: Milad Farazmand <miladfar@ca.ibm.com>
Cr-Commit-Position: refs/heads/master@{#66357}
parent 43accc8b
...@@ -68,7 +68,7 @@ function testArrayType(arrayType, pattern) { ...@@ -68,7 +68,7 @@ function testArrayType(arrayType, pattern) {
testSameOptimized(pattern, create); testSameOptimized(pattern, create);
} }
var isBigEndian = new Uint8Array(new Uint32Array([0xABCD]).buffer)[0] === 0xAB; var isBigEndian = new Uint8Array(new Uint16Array([0xABCD]).buffer)[0] === 0xAB;
testArrayType(Float32Array, [1065353216]); testArrayType(Float32Array, [1065353216]);
if (isBigEndian){ if (isBigEndian){
testArrayType(Float64Array, [1072693248, 0]); testArrayType(Float64Array, [1072693248, 0]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment