Skip to content

Commit

Permalink
[Fix] node 0.8: an object arg to a TA only throws a RangeError when…
Browse files Browse the repository at this point in the history
… it is an ArrayBuffer of an incompatible byte length
  • Loading branch information
ljharb committed Mar 2, 2023
1 parent 133732e commit d5108f6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = $byteLength || $abSlice
try {
return (new $Float32Array(obj)).buffer === obj && !isTypedArray(obj);
} catch (e) {
return false;
return typeof obj === 'object' && e.name === 'RangeError';
}
}
: function isArrayBuffer(obj) { // eslint-disable-line no-unused-vars
Expand Down
4 changes: 3 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ test('isArrayBuffer', function (t) {

t.test('actual ArrayBuffer instances', { skip: typeof ArrayBuffer === 'undefined' }, function (st) {
var ab = new ArrayBuffer();

st.equal(isArrayBuffer(ab), true, inspect(ab) + ' is an ArrayBuffer');

var ab42 = new ArrayBuffer(42);
st.equal(isArrayBuffer(ab42), true, inspect(ab42) + ' is an ArrayBuffer');

st.end();
});

Expand Down

0 comments on commit d5108f6

Please sign in to comment.