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); 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);

View File

@@ -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);