From 2f9ba719d4dc0c1ac7b4fee35af7aa2afb29eaa8 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 30 May 2014 15:24:36 -0400 Subject: [PATCH] Add clone tests for array buffers. --- lodash.js | 2 +- test/test.js | 30 ++++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lodash.js b/lodash.js index d4c977e5a..4b31aba50 100644 --- a/lodash.js +++ b/lodash.js @@ -1221,7 +1221,7 @@ } switch (className) { case arrayBufferClass: - return value.slice(); + return value.slice(0); case boolClass: case dateClass: diff --git a/test/test.js b/test/test.js index 37255bdbf..b5c000660 100644 --- a/test/test.js +++ b/test/test.js @@ -19,6 +19,7 @@ var phantom = root.phantom, amd = root.define && define.amd, argv = root.process && process.argv, + ArrayBuffer = root.ArrayBuffer, document = !phantom && root.document, body = root.document && root.document.body, create = Object.create, @@ -1284,16 +1285,33 @@ _.each(typedArrays, function(type) { test('`_.' + methodName + '` should clone ' + type + ' arrays', 2, function() { - var Ctor = root[type] || Array, - buffer = Ctor == Array ? 4 : new ArrayBuffer(4), - array = new Ctor(buffer), - actual = func(array); + var Ctor = root[type]; + if (Ctor) { + var array = new Ctor(new ArrayBuffer(4)), + actual = func(array); - deepEqual(actual, array); - notStrictEqual(actual, array); + deepEqual(actual, array); + notStrictEqual(actual, array); + } + else { + skipTest(2); + } }); }); + test('`_.' + methodName + '` should clone array buffers', 2, function() { + if (ArrayBuffer) { + var buffer = new ArrayBuffer(4), + actual = func(buffer); + + strictEqual(actual.byteLength, buffer.byteLength); + notStrictEqual(actual, buffer); + } + else { + skipTest(2); + } + }); + test('`_.' + methodName + '` should clone problem JScript properties (test in IE < 9)', 2, function() { var actual = func(shadowedObject); deepEqual(actual, shadowedObject);