From d0eac3638167e7ab137158e052f0c493747b1103 Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Fri, 23 Jul 2021 23:40:03 -0400 Subject: [PATCH] Ensure getPrototypeOf will not crash on plugin options with no scopes (#9431) * Ensure getPrototypeOf will not crash on plugin options with no scopes * Code review improvements --- src/core/core.config.js | 3 +++ test/specs/core.controller.tests.js | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) 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() {