Skip to content

Commit

Permalink
Ensure getPrototypeOf will not crash on plugin options with no scopes (
Browse files Browse the repository at this point in the history
…#9431)

* Ensure getPrototypeOf will not crash on plugin options with no scopes

* Code review improvements
  • Loading branch information
etimberg committed Jul 24, 2021
1 parent 0d0481d commit d0eac36
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/core.config.js
Expand Up @@ -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);
}
Expand Down
17 changes: 17 additions & 0 deletions test/specs/core.controller.tests.js
Expand Up @@ -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() {
Expand Down

0 comments on commit d0eac36

Please sign in to comment.