From b41826c332f96939894621f2baeb782b677a1d34 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 2 Jun 2014 09:28:45 -0700 Subject: [PATCH] Fixed `cloneBuffer` in PhantomJS. --- lodash.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lodash.js b/lodash.js index 3672b15fe..8ce21c526 100644 --- a/lodash.js +++ b/lodash.js @@ -2538,16 +2538,21 @@ return bufferSlice.call(buffer, 0); } if (!bufferSlice) { - cloneBuffer = !(ArrayBuffer && Float64Array && Uint8Array) ? identity : function(buffer) { + // PhantomJS has `ArrayBuffer` and `Uint8Array` but not `Float64Array` + cloneBuffer = !(ArrayBuffer && Uint8Array) ? identity : function(buffer) { var byteLength = buffer.byteLength, - floatLength = floor(byteLength / 8), + floatLength = Float64Array ? floor(byteLength / 8) : 0, offset = floatLength * 8, - result = new ArrayBuffer(byteLength), - resultView = new Float64Array(result, 0, floatLength); + result = new ArrayBuffer(byteLength); - resultView.set(new Float64Array(buffer, 0, floatLength)); - resultView = new Uint8Array(result, offset); - resultView.set(new Uint8Array(buffer, offset)); + if (floatLength) { + var view = new Float64Array(result, 0, floatLength); + view.set(new Float64Array(buffer, 0, floatLength)); + } + if (byteLength != offset) { + view = new Uint8Array(result, offset); + view.set(new Uint8Array(buffer, offset)); + } return result; }; }