Fix test fails in Safari 5.

This commit is contained in:
John-David Dalton
2014-07-22 09:42:34 -07:00
parent 14a99471f4
commit 49a88e75e6
2 changed files with 16 additions and 5 deletions

View File

@@ -660,7 +660,6 @@
bufferSlice = isNative(bufferSlice = ArrayBuffer && new ArrayBuffer(0).slice) && bufferSlice,
ceil = Math.ceil,
clearTimeout = context.clearTimeout,
Float64Array = isNative(Float64Array = context.Float64Array) && Float64Array,
floor = Math.floor,
getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
hasOwnProperty = objectProto.hasOwnProperty,
@@ -672,6 +671,18 @@
Uint8Array = isNative(Uint8Array = context.Uint8Array) && Uint8Array,
unshift = arrayProto.unshift;
/** Used to clone array buffers */
var Float64Array = (function() {
// Safari 5 errors when using an array buffer to initialize a typed array
// where the array buffer's `byteLength` is not a multiple of the typed
// array's `BYTES_PER_ELEMENT`
try {
var func = isNative(func = context.Float64Array) && func,
result = new func(new ArrayBuffer(10), 0, 1) && func;
} catch(e) { }
return result;
}());
/** Used to set metadata on functions */
var defineProperty = (function() {
// IE 8 only accepts DOM elements

View File

@@ -657,7 +657,7 @@
if (ArrayBuffer) {
try {
var buffer = new ArrayBuffer(12);
var buffer = new ArrayBuffer(10);
actual = lodashBizarro.clone(buffer);
} catch(e) {
actual = null;
@@ -670,13 +670,13 @@
}
if (ArrayBuffer && Uint8Array) {
try {
var array = new Uint8Array(new ArrayBuffer(12));
var array = new Uint8Array(new ArrayBuffer(10));
actual = lodashBizarro.cloneDeep(array);
} catch(e) {
actual = null;
}
deepEqual(actual, array, message('_.cloneDeep', 'Float64Array'));
notStrictEqual(actual.buffer, array.buffer, message('_.cloneDeep', 'Float64Array'));
notStrictEqual(actual && actual.buffer, array.buffer, message('_.cloneDeep', 'Float64Array'));
notStrictEqual(actual, array, message('_.cloneDeep', 'Float64Array'));
}
else {
@@ -1553,7 +1553,7 @@
});
test('`_.' + methodName + '` should clone array buffers', 2, function() {
var buffer = ArrayBuffer && new ArrayBuffer(12);
var buffer = ArrayBuffer && new ArrayBuffer(10);
if (buffer) {
var actual = func(buffer);
strictEqual(actual.byteLength, buffer.byteLength);