mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 16:17:50 +00:00
Add bizarro tests for shimmed ArrayBuffer#slice.
This commit is contained in:
@@ -108,14 +108,28 @@
|
||||
setProperty(document, '_createDocumentFragment', document.createDocumentFragment);
|
||||
document.createDocumentFragment = function() {};
|
||||
|
||||
setProperty(window, '_Float64Array', window.Float64Array);
|
||||
if (!window._Float64Array) {
|
||||
setProperty(window, 'Float64Array', window.Uint8Array);
|
||||
setProperty(window, '_ArrayBuffer', window.ArrayBuffer);
|
||||
if (window.ArrayBuffer && window.Uint8Array && !new ArrayBuffer(0).slice) {
|
||||
setProperty(window, 'ArrayBuffer', function(byteLength) {
|
||||
var buffer = new _ArrayBuffer(byteLength);
|
||||
buffer.slice = !byteLength ? Array.prototype.slice : function() {
|
||||
var newBuffer = new _ArrayBuffer(byteLength),
|
||||
view = new Uint8Array(newBuffer);
|
||||
|
||||
view.set(new Uint8Array(this));
|
||||
return newBuffer;
|
||||
};
|
||||
return buffer;
|
||||
});
|
||||
}
|
||||
setProperty(window, '_Float64Array', window.Float64Array);
|
||||
setProperty(window, 'Float64Array', window.Float64Array ? function() {} : window.Uint8Array);
|
||||
|
||||
setProperty(window, 'WinRTError', Error);
|
||||
|
||||
setProperty(window, 'exports', window);
|
||||
setProperty(window, 'global', window);
|
||||
setProperty(window, 'module', {});
|
||||
setProperty(window, 'WinRTError', Error);
|
||||
}
|
||||
|
||||
function removeBizarroMethods() {
|
||||
@@ -159,19 +173,23 @@
|
||||
} else {
|
||||
delete String.prototype.contains;
|
||||
}
|
||||
if (!window._Float64Array) {
|
||||
setProperty(window, 'Float64Array', undefined);
|
||||
}
|
||||
setProperty(Function.prototype, 'toString', Function.prototype._toString);
|
||||
setProperty(Object.prototype, 'hasOwnProperty', Object.prototype._hasOwnProperty);
|
||||
|
||||
document.createDocumentFragment = document._createDocumentFragment;
|
||||
setProperty(document, '_createDocumentFragment', undefined);
|
||||
|
||||
setProperty(window, 'ArrayBuffer', window._ArrayBuffer);
|
||||
setProperty(window, '_ArrayBuffer', undefined);
|
||||
|
||||
setProperty(window, 'Float64Array', window._Float64Array);
|
||||
setProperty(window, '_Float64Array', undefined);
|
||||
|
||||
setProperty(window, 'WinRTError', undefined);
|
||||
|
||||
setProperty(window, 'exports', undefined);
|
||||
setProperty(window, 'global', undefined);
|
||||
setProperty(window, 'module', undefined);
|
||||
setProperty(window, 'WinRTError', undefined);
|
||||
|
||||
delete Array._isArray;
|
||||
delete Date._now;
|
||||
|
||||
46
test/test.js
46
test/test.js
@@ -339,16 +339,6 @@
|
||||
return result;
|
||||
});
|
||||
|
||||
// fake DOM
|
||||
setProperty(root, 'window', {});
|
||||
setProperty(root.window, 'document', {});
|
||||
setProperty(root.window.document, 'createDocumentFragment', function() {
|
||||
return { 'nodeType': 11 };
|
||||
});
|
||||
|
||||
// fake `WinRTError`
|
||||
setProperty(root, 'WinRTError', Error);
|
||||
|
||||
// add extensions
|
||||
Function.prototype._method = _.noop;
|
||||
|
||||
@@ -385,10 +375,33 @@
|
||||
var _contains = String.prototype.contains;
|
||||
setProperty(String.prototype, 'contains', _contains ? _.noop : Boolean);
|
||||
|
||||
var _Float64Array = root.Float64Array;
|
||||
if (!_Float64Array) {
|
||||
setProperty(root, 'Float64Array', root.Uint8Array);
|
||||
var _ArrayBuffer = root.ArrayBuffer;
|
||||
if (root.Uint8Array && _ArrayBuffer && !new _ArrayBuffer(0).slice) {
|
||||
setProperty(window, 'ArrayBuffer', function(byteLength) {
|
||||
var buffer = new _ArrayBuffer(byteLength);
|
||||
buffer.slice = !byteLength ? slice : function() {
|
||||
var newBuffer = new _ArrayBuffer(byteLength),
|
||||
view = new Uint8Array(newBuffer);
|
||||
|
||||
view.set(new Uint8Array(this));
|
||||
return newBuffer;
|
||||
};
|
||||
return buffer;
|
||||
});
|
||||
}
|
||||
var _Float64Array = root.Float64Array;
|
||||
setProperty(root, 'Float64Array', _Float64Array ? _.noop : root.Uint8Array);
|
||||
|
||||
// fake `WinRTError`
|
||||
setProperty(root, 'WinRTError', Error);
|
||||
|
||||
// fake DOM
|
||||
setProperty(root, 'window', {});
|
||||
setProperty(root.window, 'document', {});
|
||||
setProperty(root.window.document, 'createDocumentFragment', function() {
|
||||
return { 'nodeType': 11 };
|
||||
});
|
||||
|
||||
// clear cache so Lo-Dash can be reloaded
|
||||
emptyObject(require.cache);
|
||||
|
||||
@@ -416,7 +429,12 @@
|
||||
} else {
|
||||
delete String.prototype.contains;
|
||||
}
|
||||
if (!_Float64Array) {
|
||||
if (_ArrayBuffer) {
|
||||
setProperty(root, 'ArrayBuffer', _ArrayBuffer);
|
||||
}
|
||||
if (_Float64Array) {
|
||||
setProperty(root, 'Float64Array', _Float64Array);
|
||||
} else {
|
||||
delete root.Float64Array;
|
||||
}
|
||||
delete root.window;
|
||||
|
||||
Reference in New Issue
Block a user