From 32e7af9ba9db3abf5f064ea21da8b1336cdf934f Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 5 Apr 2017 11:51:52 -0700 Subject: [PATCH] add back Number.isNaN shim for IE --- index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 47d9450..b62b110 100644 --- a/index.js +++ b/index.js @@ -253,7 +253,7 @@ function fromObject (obj) { if (obj) { if (isArrayBufferView(obj) || 'length' in obj) { - if (typeof obj.length !== 'number' || Number.isNaN(obj.length)) { + if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { return createBuffer(0) } return fromArrayLike(obj) @@ -630,7 +630,7 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { byteOffset = -0x80000000 } byteOffset = +byteOffset // Coerce to Number. - if (Number.isNaN(byteOffset)) { + if (numberIsNaN(byteOffset)) { // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer byteOffset = dir ? 0 : (buffer.length - 1) } @@ -761,7 +761,7 @@ function hexWrite (buf, string, offset, length) { } for (var i = 0; i < length; ++i) { var parsed = parseInt(string.substr(i * 2, 2), 16) - if (Number.isNaN(parsed)) return i + if (numberIsNaN(parsed)) return i buf[offset + i] = parsed } return i @@ -1700,3 +1700,7 @@ function blitBuffer (src, dst, offset, length) { function isArrayBufferView (obj) { return (typeof ArrayBuffer.isView === 'function') && ArrayBuffer.isView(obj) } + +function numberIsNaN (obj) { + return obj !== obj // eslint-disable-line no-self-compare +} -- 2.34.1