From: Jukka Kurkela Date: Tue, 18 Dec 2018 13:49:39 +0000 (+0200) Subject: Add support for typed arrays (#5905) X-Git-Tag: v2.8.0-rc.1~82 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8ce3d2018244657f18f7bae2fd2fcf1fe825e8f;p=thirdparty%2FChart.js.git Add support for typed arrays (#5905) --- diff --git a/src/helpers/helpers.core.js b/src/helpers/helpers.core.js index c2bd13272..4464eb7ba 100644 --- a/src/helpers/helpers.core.js +++ b/src/helpers/helpers.core.js @@ -32,13 +32,20 @@ var helpers = { }, /** - * Returns true if `value` is an array, else returns false. + * Returns true if `value` is an array (including typed arrays), else returns false. * @param {*} value - The value to test. * @returns {Boolean} * @function */ - isArray: Array.isArray ? Array.isArray : function(value) { - return Object.prototype.toString.call(value) === '[object Array]'; + isArray: function(value) { + if (Array.isArray && Array.isArray(value)) { + return true; + } + var type = Object.prototype.toString.call(value); + if (type.substr(0, 7) === '[object' && type.substr(-6) === 'Array]') { + return true; + } + return false; }, /** diff --git a/test/.eslintrc.yml b/test/.eslintrc.yml index 5fa01f891..fc54c25fa 100644 --- a/test/.eslintrc.yml +++ b/test/.eslintrc.yml @@ -1,4 +1,8 @@ +parserOptions: + ecmaVersion: 5 # don't rely on default, since its changed by env: es6 + env: + es6: true # also changes default ecmaVersion to 6 jasmine: true globals: diff --git a/test/specs/helpers.core.tests.js b/test/specs/helpers.core.tests.js index e3993de63..cdda01b96 100644 --- a/test/specs/helpers.core.tests.js +++ b/test/specs/helpers.core.tests.js @@ -21,6 +21,15 @@ describe('Chart.helpers.core', function() { expect(helpers.isArray([42])).toBeTruthy(); expect(helpers.isArray(new Array())).toBeTruthy(); expect(helpers.isArray(Array.prototype)).toBeTruthy(); + expect(helpers.isArray(new Int8Array(2))).toBeTruthy(); + expect(helpers.isArray(new Uint8Array())).toBeTruthy(); + expect(helpers.isArray(new Uint8ClampedArray([128, 244]))).toBeTruthy(); + expect(helpers.isArray(new Int16Array())).toBeTruthy(); + expect(helpers.isArray(new Uint16Array())).toBeTruthy(); + expect(helpers.isArray(new Int32Array())).toBeTruthy(); + expect(helpers.isArray(new Uint32Array())).toBeTruthy(); + expect(helpers.isArray(new Float32Array([1.2]))).toBeTruthy(); + expect(helpers.isArray(new Float64Array([]))).toBeTruthy(); }); it('should return false if value is not an array', function() { expect(helpers.isArray()).toBeFalsy();