Correct ArrayBuffer bizarro shims.

This commit is contained in:
John-David Dalton
2014-07-20 09:49:25 -07:00
parent 4f4a7409f6
commit 94486302f5
2 changed files with 39 additions and 21 deletions

View File

@@ -113,17 +113,27 @@
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);
setProperty(window, 'ArrayBuffer', (function() {
function ArrayBuffer(byteLength) {
var buffer = new _ArrayBuffer(byteLength);
buffer.slice = function() {
var newBuffer = new _ArrayBuffer(byteLength),
view = new Uint8Array(newBuffer);
view.set(new Uint8Array(this));
return newBuffer;
};
return buffer;
});
view.set(new Uint8Array(this));
return newBuffer;
};
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 ? function() {} : window.Uint8Array);

View File

@@ -387,19 +387,27 @@
var _ArrayBuffer = ArrayBuffer;
if (Uint8Array && new ArrayBuffer(0).slice) {
setProperty(root, 'ArrayBuffer', function(byteLength) {
var buffer = new _ArrayBuffer(byteLength);
buffer.slice = !byteLength ? slice : function() {
var newBuffer = new _ArrayBuffer(byteLength),
view = new Uint8Array(newBuffer);
setProperty(root, 'ArrayBuffer', (function() {
function ArrayBuffer(byteLength) {
var buffer = new _ArrayBuffer(byteLength);
buffer.slice = function() {
var newBuffer = new _ArrayBuffer(byteLength),
view = new Uint8Array(newBuffer);
view.set(new Uint8Array(this));
return newBuffer;
};
return buffer;
});
view.set(new Uint8Array(this));
return newBuffer;
};
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;
setProperty(root, 'Float64Array', _Float64Array ? _.noop : root.Uint8Array);