diff --git a/lodash.js b/lodash.js index a69dbe4d7..d3b20fd56 100644 --- a/lodash.js +++ b/lodash.js @@ -1426,7 +1426,8 @@ if (Ctor instanceof Ctor) { Ctor = ctorByClass[className]; } - return new Ctor(cloneBuffer(value.buffer), value.byteOffset, value.length); + var buffer = value.buffer; + return new Ctor(isDeep ? cloneBuffer(buffer) : buffer, value.byteOffset, value.length); case numberClass: case stringClass: diff --git a/test/test.js b/test/test.js index b2322b058..f3d1fe436 100644 --- a/test/test.js +++ b/test/test.js @@ -616,7 +616,7 @@ if (root.Uint8Array) { try { var array = new Uint8Array(new ArrayBuffer(8)); - actual = lodashBizarro.clone(array); + actual = lodashBizarro.cloneDeep(array); } catch(e) { actual = null; } @@ -1475,8 +1475,7 @@ _.each(['clone', 'cloneDeep'], function(methodName) { var func = _[methodName], - isDeep = methodName == 'cloneDeep', - klass = new Klass; + isDeep = methodName == 'cloneDeep'; _.forOwn(objects, function(object, key) { test('`_.' + methodName + '` should clone ' + key, 2, function() { @@ -1520,14 +1519,14 @@ test('`_.' + methodName + '` should clone ' + type + ' arrays', 10, function() { var Ctor = root[type]; if (Ctor) { - var array = new Ctor(new ArrayBuffer(24)); - _.times(2, function(index) { - var actual = index ? func(array, 8, 1) : func(array); + var buffer = new ArrayBuffer(24), + array = index ? new Ctor(buffer, 8, 1) : new Ctor(buffer), + actual = func(array); deepEqual(actual, array); notStrictEqual(actual, array); - notStrictEqual(actual.buffer, array.buffer); + strictEqual(actual.buffer === array.buffer, !isDeep); strictEqual(actual.byteOffset, array.byteOffset); strictEqual(actual.length, array.length); }); @@ -1558,7 +1557,8 @@ }); test('`_.' + methodName + '` should provide the correct `callback` arguments', 1, function() { - var argsList = []; + var argsList = [], + klass = new Klass; func(klass, function() { argsList.push(slice.call(arguments));