Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent proxying CanvasGradient in Node platform #9861

Merged
merged 1 commit into from Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/helpers/helpers.config.js
Expand Up @@ -178,7 +178,8 @@ export function _descriptors(proxy, defaults = {scriptable: true, indexable: tru
}

const readKey = (prefix, name) => prefix ? prefix + _capitalize(name) : name;
const needsSubResolver = (prop, value) => isObject(value) && prop !== 'adapters';
const needsSubResolver = (prop, value) => isObject(value) && prop !== 'adapters' &&
(Object.getPrototypeOf(value) === null || value.constructor === Object);

function _cached(target, prop, resolve) {
if (Object.prototype.hasOwnProperty.call(target, prop)) {
Expand Down Expand Up @@ -218,7 +219,7 @@ function _resolveScriptable(prop, value, target, receiver) {
_stack.add(prop);
value = value(_context, _subProxy || receiver);
_stack.delete(prop);
if (isObject(value)) {
if (needsSubResolver(prop, value)) {
// When scriptable option returns an object, create a resolver on that.
value = createSubResolver(_proxy._scopes, _proxy, prop, value);
}
Expand Down
23 changes: 23 additions & 0 deletions test/specs/helpers.config.tests.js
Expand Up @@ -752,6 +752,29 @@ describe('Chart.helpers.config', function() {
expect(fn()).toEqual('ok');
});

it('should not create proxy for objects with custom constructor', function() {
class MyClass {
constructor() {
this.string = 'test string';
}
method(arg) {
return arg === undefined ? 'ok' : 'fail';
}
}

const defaults = {
test: new MyClass()
};

const resolver = _createResolver([{}, defaults]);
const opts = _attachContext(resolver, {index: 1});
const fn = opts.test.method;
expect(typeof fn).toBe('function');
expect(fn()).toEqual('ok');
expect(opts.test.string).toEqual('test string');
expect(opts.test.constructor).toEqual(MyClass);
});

it('should properly set value to object in array of objects', function() {
const defaults = {};
const options = {
Expand Down