Skip to content

Commit

Permalink
chore(): use Array.isArray instead of ie6+ workarounds (#7718)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 authored Feb 20, 2022
1 parent 88b425c commit 2d922e1
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@
_isSelectionKeyPressed: function(e) {
var selectionKeyPressed = false;

if (Object.prototype.toString.call(this.selectionKey) === '[object Array]') {
if (Array.isArray(this.selectionKey)) {
selectionKeyPressed = !!this.selectionKey.find(function(key) { return e[key] === true; });
}
else {
Expand Down
3 changes: 1 addition & 2 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@
}

function normalizeValue(attr, value, parentAttributes, fontSize) {
var isArray = Object.prototype.toString.call(value) === '[object Array]',
parsed;
var isArray = Array.isArray(value), parsed;

if ((attr === 'fill' || attr === 'stroke') && value === 'none') {
value = '';
Expand Down
6 changes: 2 additions & 4 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,11 +908,9 @@
if (object[prop] === prototype[prop]) {
delete object[prop];
}
var isArray = Object.prototype.toString.call(object[prop]) === '[object Array]' &&
Object.prototype.toString.call(prototype[prop]) === '[object Array]';

// basically a check for [] === []
if (isArray && object[prop].length === 0 && prototype[prop].length === 0) {
if (Array.isArray(object[prop]) && Array.isArray(prototype[prop])
&& object[prop].length === 0 && prototype[prop].length === 0) {
delete object[prop];
}
});
Expand Down
5 changes: 1 addition & 4 deletions src/shapes/path.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
max = fabric.util.array.max,
extend = fabric.util.object.extend,
clone = fabric.util.object.clone,
_toString = Object.prototype.toString,
toFixed = fabric.util.toFixed;

if (fabric.Path) {
Expand Down Expand Up @@ -61,10 +60,8 @@
* @param {Object} [options] Options object
*/
_setPath: function (path, options) {
var fromArray = _toString.call(path) === '[object Array]';

this.path = fabric.util.makePathSimpler(
fromArray ? path : fabric.util.parsePath(path)
Array.isArray(path) ? path : fabric.util.parsePath(path)
);

fabric.Polyline.prototype._setPositionDimensions.call(this, options || {});
Expand Down
2 changes: 1 addition & 1 deletion src/util/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@
* @return {Array} properties Properties names to include
*/
populateWithProperties: function(source, destination, properties) {
if (properties && Object.prototype.toString.call(properties) === '[object Array]') {
if (properties && Array.isArray(properties)) {
for (var i = 0, len = properties.length; i < len; i++) {
if (properties[i] in source) {
destination[properties[i]] = source[properties[i]];
Expand Down
2 changes: 1 addition & 1 deletion test/unit/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
var group = new fabric.Group([rect1, rect2]);

assert.ok(typeof group.getObjects === 'function');
assert.ok(Object.prototype.toString.call(group.getObjects()) == '[object Array]', 'should be an array');
assert.ok(Array.isArray(group.getObjects()), 'should be an array');
assert.equal(group.getObjects().length, 2, 'should have 2 items');
assert.deepEqual(group.getObjects(), [rect1, rect2], 'should return deepEqual objects as those passed to constructor');
});
Expand Down

0 comments on commit 2d922e1

Please sign in to comment.