diff --git a/support/types.js b/support/types.js index 6a9899d..b1fedf2 100644 --- a/support/types.js +++ b/support/types.js @@ -115,7 +115,10 @@ function isUint8Array(value) { } else { return ( ObjectToString(value) === '[object Uint8Array]' || - isBuffer(value) + // If it's a Buffer instance _and_ has a `.buffer` property, + // this is an ArrayBuffer based buffer; thus it's an Uint8Array + // (Old Node.js had a custom non-Uint8Array implementation) + isBuffer(value) && value.buffer !== undefined ); } } diff --git a/test/node/types.js b/test/node/types.js index 31be41f..848c7a1 100644 --- a/test/node/types.js +++ b/test/node/types.js @@ -175,6 +175,9 @@ if (isBuggyFirefox) { console.log('skipping fake typed array tests because they do not work in FF') } +// Old Node.js had a fully custom Buffer implementation, newer are based on ArrayBuffer +// This is important for the ArrayBuffer and typed array tests +var isBufferBasedOnArrayBuffer = Buffer.alloc(1).buffer !== undefined; { var primitive = function primitive() { return true; }; var arrayBuffer = function arrayBuffer() { return new ArrayBuffer(1); }; @@ -394,7 +397,7 @@ if (isBuggyFirefox) { var expected = { isArrayBufferView: [ - buffer, + isBufferBasedOnArrayBuffer ? buffer : undefined, dataView, stealthyDataView, uint8Array, @@ -421,7 +424,7 @@ if (isBuggyFirefox) { stealthyBigUint64Array ], isTypedArray: [ - buffer, + isBufferBasedOnArrayBuffer ? buffer : undefined, uint8Array, stealthyUint8Array, uint8ClampedArray, @@ -446,7 +449,7 @@ if (isBuggyFirefox) { stealthyBigUint64Array ], isUint8Array: [ - buffer, + isBufferBasedOnArrayBuffer ? buffer : undefined, uint8Array, stealthyUint8Array ],