mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Add _allKeys descriptor for Object.keys behavior (#8553)
This commit is contained in:
parent
cc8e513d0f
commit
78d3d30d56
@ -316,7 +316,7 @@ export default class Config {
|
||||
* @param {object[]} scopes
|
||||
* @param {object} [context]
|
||||
* @param {string[]} [prefixes]
|
||||
* @param {{scriptable: boolean, indexable: boolean}} [descriptorDefaults]
|
||||
* @param {{scriptable: boolean, indexable: boolean, allKeys?: boolean}} [descriptorDefaults]
|
||||
*/
|
||||
createResolver(scopes, context, prefixes = [''], descriptorDefaults) {
|
||||
const {resolver} = getResolver(this._resolverCache, scopes, prefixes);
|
||||
|
||||
@ -166,5 +166,5 @@ function createDescriptors(chart, plugins, options, all) {
|
||||
function pluginOpts(config, plugin, opts, context) {
|
||||
const keys = config.pluginScopeKeys(plugin);
|
||||
const scopes = config.getOptionScopes(opts, keys);
|
||||
return config.createResolver(scopes, context, [''], {scriptable: false, indexable: false});
|
||||
return config.createResolver(scopes, context, [''], {scriptable: false, indexable: false, allKeys: true});
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ export function _createResolver(scopes, prefixes = [''], rootScopes = scopes, fa
|
||||
* @param {object} proxy - The Proxy returned by `_createResolver`
|
||||
* @param {object} context - Context object for scriptable/indexable options
|
||||
* @param {object} [subProxy] - The proxy provided for scriptable options
|
||||
* @param {{scriptable: boolean, indexable: boolean}} [descriptorDefaults] - Defaults for descriptors
|
||||
* @param {{scriptable: boolean, indexable: boolean, allKeys?: boolean}} [descriptorDefaults] - Defaults for descriptors
|
||||
* @private
|
||||
*/
|
||||
export function _attachContext(proxy, context, subProxy, descriptorDefaults) {
|
||||
@ -123,7 +123,9 @@ export function _attachContext(proxy, context, subProxy, descriptorDefaults) {
|
||||
* Also used by Object.hasOwnProperty.
|
||||
*/
|
||||
getOwnPropertyDescriptor(target, prop) {
|
||||
return Reflect.getOwnPropertyDescriptor(proxy, prop);
|
||||
return target._descriptors.allKeys
|
||||
? Reflect.has(proxy, prop) ? {enumerable: true, configurable: true} : undefined
|
||||
: Reflect.getOwnPropertyDescriptor(proxy, prop);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -162,8 +164,9 @@ export function _attachContext(proxy, context, subProxy, descriptorDefaults) {
|
||||
* @private
|
||||
*/
|
||||
export function _descriptors(proxy, defaults = {scriptable: true, indexable: true}) {
|
||||
const {_scriptable = defaults.scriptable, _indexable = defaults.indexable} = proxy;
|
||||
const {_scriptable = defaults.scriptable, _indexable = defaults.indexable, _allKeys = defaults.allKeys} = proxy;
|
||||
return {
|
||||
allKeys: _allKeys,
|
||||
scriptable: _scriptable,
|
||||
indexable: _indexable,
|
||||
isScriptable: isFunction(_scriptable) ? _scriptable : () => _scriptable,
|
||||
|
||||
@ -274,7 +274,8 @@ describe('Chart.plugins', function() {
|
||||
chart.notifyPlugins('hook');
|
||||
|
||||
expect(plugin.hook).toHaveBeenCalled();
|
||||
expect(plugin.hook.calls.first().args[2]).toEqualOptions({a: 42});
|
||||
expect(Object.keys(plugin.hook.calls.first().args[2])).toEqual(['a']);
|
||||
expect(plugin.hook.calls.first().args[2]).toEqual(jasmine.objectContaining({a: 42}));
|
||||
|
||||
Chart.unregister(plugin);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user