mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-14 04:06:49 +01:00
Handle inextensible dataset.data array (#6060)
This commit is contained in:
committed by
Simon Brunel
parent
2f874fde62
commit
ef507e11bd
@@ -225,7 +225,9 @@ helpers.extend(DatasetController.prototype, {
|
||||
unlistenArrayEvents(me._data, me);
|
||||
}
|
||||
|
||||
listenArrayEvents(data, me);
|
||||
if (data && Object.isExtensible(data)) {
|
||||
listenArrayEvents(data, me);
|
||||
}
|
||||
me._data = data;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,86 @@ describe('Chart.DatasetController', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('inextensible data', function() {
|
||||
it('should handle a frozen data object', function() {
|
||||
function createChart() {
|
||||
var data = Object.freeze([0, 1, 2, 3, 4, 5]);
|
||||
expect(Object.isExtensible(data)).toBeFalsy();
|
||||
|
||||
var chart = acquireChart({
|
||||
type: 'line',
|
||||
data: {
|
||||
datasets: [{
|
||||
data: data
|
||||
}]
|
||||
}
|
||||
});
|
||||
|
||||
var dataset = chart.data.datasets[0];
|
||||
dataset.data = Object.freeze([5, 4, 3, 2, 1, 0]);
|
||||
expect(Object.isExtensible(dataset.data)).toBeFalsy();
|
||||
chart.update();
|
||||
|
||||
// Tests that the unlisten path also works for frozen objects
|
||||
chart.destroy();
|
||||
}
|
||||
|
||||
expect(createChart).not.toThrow();
|
||||
});
|
||||
|
||||
it('should handle a sealed data object', function() {
|
||||
function createChart() {
|
||||
var data = Object.seal([0, 1, 2, 3, 4, 5]);
|
||||
expect(Object.isExtensible(data)).toBeFalsy();
|
||||
|
||||
var chart = acquireChart({
|
||||
type: 'line',
|
||||
data: {
|
||||
datasets: [{
|
||||
data: data
|
||||
}]
|
||||
}
|
||||
});
|
||||
|
||||
var dataset = chart.data.datasets[0];
|
||||
dataset.data = Object.seal([5, 4, 3, 2, 1, 0]);
|
||||
expect(Object.isExtensible(dataset.data)).toBeFalsy();
|
||||
chart.update();
|
||||
|
||||
// Tests that the unlisten path also works for frozen objects
|
||||
chart.destroy();
|
||||
}
|
||||
|
||||
expect(createChart).not.toThrow();
|
||||
});
|
||||
|
||||
it('should handle an unextendable data object', function() {
|
||||
function createChart() {
|
||||
var data = Object.preventExtensions([0, 1, 2, 3, 4, 5]);
|
||||
expect(Object.isExtensible(data)).toBeFalsy();
|
||||
|
||||
var chart = acquireChart({
|
||||
type: 'line',
|
||||
data: {
|
||||
datasets: [{
|
||||
data: data
|
||||
}]
|
||||
}
|
||||
});
|
||||
|
||||
var dataset = chart.data.datasets[0];
|
||||
dataset.data = Object.preventExtensions([5, 4, 3, 2, 1, 0]);
|
||||
expect(Object.isExtensible(dataset.data)).toBeFalsy();
|
||||
chart.update();
|
||||
|
||||
// Tests that the unlisten path also works for frozen objects
|
||||
chart.destroy();
|
||||
}
|
||||
|
||||
expect(createChart).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
it('should synchronize metadata when data are inserted or removed', function() {
|
||||
var data = [0, 1, 2, 3, 4, 5];
|
||||
var chart = acquireChart({
|
||||
|
||||
Reference in New Issue
Block a user