Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/core/core.datasetController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
74 changes: 74 additions & 0 deletions test/specs/core.datasetController.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,80 @@ 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]);
var chart = acquireChart({
type: 'line',
data: {
datasets: [{
data: data
}]
}
});

chart.data.datasets[0].data = Object.freeze([5, 4, 3, 2, 1, 0]);
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 = [0, 1, 2, 3, 4, 5];
Object.seal(data);
var chart = acquireChart({
type: 'line',
data: {
datasets: [{
data: data
}]
}
});

var data2 = [5, 4, 3, 2, 1, 0];
Object.seal(data2)
chart.data.datasets[0].data = data2;
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 = [0, 1, 2, 3, 4, 5];
Object.preventExtensions(data);
var chart = acquireChart({
type: 'line',
data: {
datasets: [{
data: data
}]
}
});

var data2 = [5, 4, 3, 2, 1, 0];
Object.preventExtensions(data2)
chart.data.datasets[0].data = data2;
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({
Expand Down