Fix typo in the ArrayBuffer#slice mock for node.

This commit is contained in:
John-David Dalton
2014-07-21 23:10:40 -07:00
parent 13669313d4
commit 653aab2358
2 changed files with 50 additions and 46 deletions

View File

@@ -113,38 +113,39 @@
document.createDocumentFragment = function() {};
setProperty(window, '_ArrayBuffer', window.ArrayBuffer);
if (window.ArrayBuffer && window.Uint8Array && !new ArrayBuffer(0).slice) {
if (window.ArrayBuffer && window.Uint8Array) {
ArrayBuffer = (function(_ArrayBuffer) {
function ArrayBuffer(byteLength) {
var buffer = new _ArrayBuffer(byteLength);
if (!byteLength) {
setProperty(buffer, 'slice', buffer.slice ? null : bufferSlice);
}
return buffer;
}
function bufferSlice() {
var newBuffer = new _ArrayBuffer(this.byteLength),
view = new Uint8Array(newBuffer);
view.set(new Uint8Array(this));
return newBuffer;
}
function constant(value) {
return function() {
return value;
};
}
function ArrayBuffer(byteLength) {
var buffer = new _ArrayBuffer(byteLength);
buffer.slice = function() {
var newBuffer = new _ArrayBuffer(this.byteLength),
view = new Uint8Array(newBuffer);
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);
setProperty(bufferSlice, 'toString', sliceToString);
return ArrayBuffer;
}(_ArrayBuffer));
}
setProperty(window, '_Float64Array', window.Float64Array);
if (window._ArrayBuffer == window.ArrayBuffer && window._Float64Array) {
Float64Array = function() {};
} else {
if (!window._Float64Array) {
Float64Array = window.Uint8Array;
}
setProperty(window, 'WinRTError', Error);