mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
Correct ArrayBuffer bizarro shims.
This commit is contained in:
@@ -113,17 +113,27 @@
|
|||||||
|
|
||||||
setProperty(window, '_ArrayBuffer', window.ArrayBuffer);
|
setProperty(window, '_ArrayBuffer', window.ArrayBuffer);
|
||||||
if (window.ArrayBuffer && window.Uint8Array && !new ArrayBuffer(0).slice) {
|
if (window.ArrayBuffer && window.Uint8Array && !new ArrayBuffer(0).slice) {
|
||||||
setProperty(window, 'ArrayBuffer', function(byteLength) {
|
setProperty(window, 'ArrayBuffer', (function() {
|
||||||
var buffer = new _ArrayBuffer(byteLength);
|
function ArrayBuffer(byteLength) {
|
||||||
buffer.slice = !byteLength ? Array.prototype.slice : function() {
|
var buffer = new _ArrayBuffer(byteLength);
|
||||||
var newBuffer = new _ArrayBuffer(byteLength),
|
buffer.slice = function() {
|
||||||
view = new Uint8Array(newBuffer);
|
var newBuffer = new _ArrayBuffer(byteLength),
|
||||||
|
view = new Uint8Array(newBuffer);
|
||||||
|
|
||||||
view.set(new Uint8Array(this));
|
view.set(new Uint8Array(this));
|
||||||
return newBuffer;
|
return newBuffer;
|
||||||
};
|
};
|
||||||
return buffer;
|
setProperty(buffer.slice, 'toString', sliceToString);
|
||||||
});
|
return buffer;
|
||||||
|
}
|
||||||
|
var reToString = /toString/g,
|
||||||
|
nativeString = Function.prototype.toString.call(toString),
|
||||||
|
bufferToString = _.constant(nativeString.replace(reToString, 'ArrayBuffer')),
|
||||||
|
sliceToString = _.constant(nativeString.replace(reToString, 'slice'));
|
||||||
|
|
||||||
|
setProperty(ArrayBuffer, 'toString', bufferToString);
|
||||||
|
return ArrayBuffer;
|
||||||
|
}()));
|
||||||
}
|
}
|
||||||
setProperty(window, '_Float64Array', window.Float64Array);
|
setProperty(window, '_Float64Array', window.Float64Array);
|
||||||
setProperty(window, 'Float64Array', window.Float64Array ? function() {} : window.Uint8Array);
|
setProperty(window, 'Float64Array', window.Float64Array ? function() {} : window.Uint8Array);
|
||||||
|
|||||||
30
test/test.js
30
test/test.js
@@ -387,19 +387,27 @@
|
|||||||
|
|
||||||
var _ArrayBuffer = ArrayBuffer;
|
var _ArrayBuffer = ArrayBuffer;
|
||||||
if (Uint8Array && new ArrayBuffer(0).slice) {
|
if (Uint8Array && new ArrayBuffer(0).slice) {
|
||||||
setProperty(root, 'ArrayBuffer', function(byteLength) {
|
setProperty(root, 'ArrayBuffer', (function() {
|
||||||
var buffer = new _ArrayBuffer(byteLength);
|
function ArrayBuffer(byteLength) {
|
||||||
buffer.slice = !byteLength ? slice : function() {
|
var buffer = new _ArrayBuffer(byteLength);
|
||||||
var newBuffer = new _ArrayBuffer(byteLength),
|
buffer.slice = function() {
|
||||||
view = new Uint8Array(newBuffer);
|
var newBuffer = new _ArrayBuffer(byteLength),
|
||||||
|
view = new Uint8Array(newBuffer);
|
||||||
|
|
||||||
view.set(new Uint8Array(this));
|
view.set(new Uint8Array(this));
|
||||||
return newBuffer;
|
return newBuffer;
|
||||||
};
|
};
|
||||||
return buffer;
|
setProperty(buffer.slice, 'toString', sliceToString);
|
||||||
});
|
return buffer;
|
||||||
|
}
|
||||||
|
var reToString = /toString/g,
|
||||||
|
nativeString = _fnToString.call(toString),
|
||||||
|
bufferToString = _.constant(nativeString.replace(reToString, 'ArrayBuffer')),
|
||||||
|
sliceToString = _.constant(nativeString.replace(reToString, 'slice'));
|
||||||
|
|
||||||
setPropertu(ArrayBuffer, 'toString', _.constant(String(toString).replace(/toString/g, 'ArrayBuffer')));
|
setProperty(ArrayBuffer, 'toString', bufferToString);
|
||||||
|
return ArrayBuffer;
|
||||||
|
}()));
|
||||||
}
|
}
|
||||||
var _Float64Array = root.Float64Array;
|
var _Float64Array = root.Float64Array;
|
||||||
setProperty(root, 'Float64Array', _Float64Array ? _.noop : root.Uint8Array);
|
setProperty(root, 'Float64Array', _Float64Array ? _.noop : root.Uint8Array);
|
||||||
|
|||||||
Reference in New Issue
Block a user