Skip to content

Commit c8b885d

Browse files
authored
Prevent proxying CanvasGradient in Node platform (#9861)
1 parent 6c63f7a commit c8b885d

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/helpers/helpers.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ export function _descriptors(proxy, defaults = {scriptable: true, indexable: tru
178178
}
179179

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

183184
function _cached(target, prop, resolve) {
184185
if (Object.prototype.hasOwnProperty.call(target, prop)) {
@@ -218,7 +219,7 @@ function _resolveScriptable(prop, value, target, receiver) {
218219
_stack.add(prop);
219220
value = value(_context, _subProxy || receiver);
220221
_stack.delete(prop);
221-
if (isObject(value)) {
222+
if (needsSubResolver(prop, value)) {
222223
// When scriptable option returns an object, create a resolver on that.
223224
value = createSubResolver(_proxy._scopes, _proxy, prop, value);
224225
}

test/specs/helpers.config.tests.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,29 @@ describe('Chart.helpers.config', function() {
752752
expect(fn()).toEqual('ok');
753753
});
754754

755+
it('should not create proxy for objects with custom constructor', function() {
756+
class MyClass {
757+
constructor() {
758+
this.string = 'test string';
759+
}
760+
method(arg) {
761+
return arg === undefined ? 'ok' : 'fail';
762+
}
763+
}
764+
765+
const defaults = {
766+
test: new MyClass()
767+
};
768+
769+
const resolver = _createResolver([{}, defaults]);
770+
const opts = _attachContext(resolver, {index: 1});
771+
const fn = opts.test.method;
772+
expect(typeof fn).toBe('function');
773+
expect(fn()).toEqual('ok');
774+
expect(opts.test.string).toEqual('test string');
775+
expect(opts.test.constructor).toEqual(MyClass);
776+
});
777+
755778
it('should properly set value to object in array of objects', function() {
756779
const defaults = {};
757780
const options = {

0 commit comments

Comments
 (0)