From a15b708eb01128b75b7e03ec52aaa6079573d097 Mon Sep 17 00:00:00 2001 From: Roy Wright Date: Tue, 6 Mar 2018 00:07:58 +0900 Subject: [PATCH] Fix test failures on linuxOne and AIX Currently, the test only considers little endian. So, this patch adds a endian check function(IsLittleEndian()) and then use it instead of hardcoded value. Fixes: https://github.com/nodejs/node-addon-api/issues/230 PR-URL: https://github.com/nodejs/node-addon-api/pull/232 Reviewed-By: Michael Dawson Reviewed-By: Anna Henningsen --- test/dataview/dataview_read_write.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/dataview/dataview_read_write.js b/test/dataview/dataview_read_write.js index 3763673..83d58cc 100644 --- a/test/dataview/dataview_read_write.js +++ b/test/dataview/dataview_read_write.js @@ -19,12 +19,18 @@ function test(binding) { eval(`binding.dataview_read_write.set${type}(dataview, offset, value)`); } + function isLittleEndian() { + const buffer = new ArrayBuffer(2); + new DataView(buffer).setInt16(0, 256, true /* littleEndian */); + return new Int16Array(buffer)[0] === 256; + } + function jsReadDataView(dataview, type, offset, value) { - return eval(`dataview.get${type}(offset, true)`); + return eval(`dataview.get${type}(offset, isLittleEndian())`); } function jsWriteDataView(dataview, type, offset, value) { - eval(`dataview.set${type}(offset, value, true)`); + eval(`dataview.set${type}(offset, value, isLittleEndian())`); } function testReadData(dataview, type, offset, value) {