diff --git a/src/core/core.config.js b/src/core/core.config.js index 255699bdf52..18fe50a1e19 100644 --- a/src/core/core.config.js +++ b/src/core/core.config.js @@ -281,6 +281,9 @@ export default class Config { }); const array = Array.from(scopes); + if (array.length === 0) { + array.push(Object.create(null)); + } if (keysCached.has(keyLists)) { cache.set(keyLists, array); } diff --git a/test/specs/core.controller.tests.js b/test/specs/core.controller.tests.js index ac0479b202b..5072537e975 100644 --- a/test/specs/core.controller.tests.js +++ b/test/specs/core.controller.tests.js @@ -1707,6 +1707,23 @@ describe('Chart', function() { 'before-0', 'after-0' ]); }); + + it('should not crash when accessing options of a blank inline plugin', function() { + var chart = window.acquireChart({ + type: 'line', + data: {datasets: [{}]}, + plugins: [{}], + }); + + function iterateOptions() { + for (const plugin of chart._plugins._init) { + // triggering bug https://github.com/chartjs/Chart.js/issues/9368 + expect(Object.getPrototypeOf(plugin.options)).toBeNull(); + } + } + + expect(iterateOptions).not.toThrow(); + }); }); describe('metasets', function() {