Move Uint32Array.fill polyfill to utils

This commit is contained in:
Dávid Szabó 2016-09-23 13:28:12 +02:00 committed by Julian Descottes
parent 3a2d837f5a
commit 0ec8036670
2 changed files with 23 additions and 7 deletions

View File

@ -58,13 +58,7 @@
} else {
pixels = _emptyPixelGridCache[key] = new Uint32Array(width * height);
var transparentColorInt = pskl.utils.colorToInt(Constants.TRANSPARENT_COLOR);
if (!pixels.fill) { // PhantomJS ='(
for (var i = 0; i < width * height; i++) {
pixels[i] = transparentColorInt;
}
} else {
pixels.fill(transparentColorInt);
}
pixels.fill(transparentColorInt);
}
return new Uint32Array(pixels);

View File

@ -38,6 +38,28 @@ if (!Function.prototype.bind) {
};
}
/**
* Polyfill for typedarrays' fill method for PhantomJS
*/
if (!Uint32Array.prototype.fill) {
Uint32Array.prototype.fill = function (value, start, end) {
start = typeof start === 'undefined' ? 0 : start;
end = typeof end === 'undefined' ? this.length : end;
if (start < 0) {
start = this.length + start;
}
if (end < 0) {
end = this.length + end;
}
for (var i = start; i < end; i++) {
this[i] = value;
}
};
}
/**
* @provide pskl.utils
*