diff --git a/lib/chai/utils/addProperty.js b/lib/chai/utils/addProperty.js index 1358ad9..6e535db 100644 --- a/lib/chai/utils/addProperty.js +++ b/lib/chai/utils/addProperty.js @@ -6,6 +6,7 @@ var chai = require('../../chai'); var flag = require('./flag'); +var isProxyEnabled = require('./isProxyEnabled'); var transferFlags = require('./transferFlags'); /** @@ -39,10 +40,12 @@ module.exports = function addProperty(ctx, name, getter) { Object.defineProperty(ctx, name, { get: function propertyGetter() { - var keep_ssfi = flag(this, 'keep_ssfi'); - var old_ssfi = flag(this, 'ssfi'); - if (!keep_ssfi && old_ssfi) - flag(this, 'ssfi', propertyGetter); + if (!isProxyEnabled()) { + var keep_ssfi = flag(this, 'keep_ssfi'); + var old_ssfi = flag(this, 'ssfi'); + if (!keep_ssfi && old_ssfi) + flag(this, 'ssfi', propertyGetter); + } var result = getter.call(this); if (result !== undefined) diff --git a/lib/chai/utils/overwriteProperty.js b/lib/chai/utils/overwriteProperty.js index 1f8a28b..0ffb268 100644 --- a/lib/chai/utils/overwriteProperty.js +++ b/lib/chai/utils/overwriteProperty.js @@ -6,6 +6,7 @@ var chai = require('../../chai'); var flag = require('./flag'); +var isProxyEnabled = require('./isProxyEnabled'); var transferFlags = require('./transferFlags'); /** @@ -51,10 +52,12 @@ module.exports = function overwriteProperty(ctx, name, getter) { Object.defineProperty(ctx, name, { get: function overwritingPropertyGetter() { - var keep_ssfi = flag(this, 'keep_ssfi'); - var old_ssfi = flag(this, 'ssfi'); - if (!keep_ssfi && old_ssfi) - flag(this, 'ssfi', overwritingPropertyGetter); + if (!isProxyEnabled()) { + var keep_ssfi = flag(this, 'keep_ssfi'); + var old_ssfi = flag(this, 'ssfi'); + if (!keep_ssfi && old_ssfi) + flag(this, 'ssfi', overwritingPropertyGetter); + } flag(this, 'keep_ssfi', true); var result = getter(_super).call(this); diff --git a/lib/chai/utils/proxify.js b/lib/chai/utils/proxify.js index ed73e66..a9ba811 100644 --- a/lib/chai/utils/proxify.js +++ b/lib/chai/utils/proxify.js @@ -1,4 +1,5 @@ var config = require('../config'); +var flag = require('./flag'); var getProperties = require('./getProperties'); var isProxyEnabled = require('./isProxyEnabled'); @@ -27,6 +28,8 @@ var isProxyEnabled = require('./isProxyEnabled'); * @name proxify */ +var builtins = ['__flags', '__methods', '_obj', 'assert']; + module.exports = function proxify(obj, nonChainableMethodName) { if (!isProxyEnabled()) return obj; @@ -48,7 +51,7 @@ module.exports = function proxify(obj, nonChainableMethodName) { var orderedProperties = getProperties(target).filter(function(property) { return !Object.prototype.hasOwnProperty(property) && - ['__flags', '__methods', '_obj', 'assert'].indexOf(property) === -1; + builtins.indexOf(property) === -1; }).sort(function(a, b) { return stringDistance(property, a) - stringDistance(property, b); }); @@ -64,6 +67,10 @@ module.exports = function proxify(obj, nonChainableMethodName) { } } + if (builtins.indexOf(property) === -1) { + flag(target, 'ssfi', proxyGetter); + } + return Reflect.get(target, property); } }); diff --git a/test/configuration.js b/test/configuration.js index f83d366..77d2053 100644 --- a/test/configuration.js +++ b/test/configuration.js @@ -99,6 +99,10 @@ describe('configuration', function () { it('should include Chai frames in stack trace', function () { expect(caughtErr.stack).to.contain('propertyGetter'); + + if (typeof Proxy !== 'undefined' && typeof Reflect !== 'undefined') { + expect(caughtErr.stack).to.contain('proxyGetter'); + } }); it('should include user frames in stack trace', function () { @@ -121,6 +125,10 @@ describe('configuration', function () { it('should include Chai frames in stack trace', function () { expect(caughtErr.stack).to.contain('overwritingPropertyGetter'); + + if (typeof Proxy !== 'undefined' && typeof Reflect !== 'undefined') { + expect(caughtErr.stack).to.contain('proxyGetter'); + } }); it('should include user frames in stack trace', function () { @@ -233,6 +241,10 @@ describe('configuration', function () { it('should not include Chai frames in stack trace', function () { expect(caughtErr.stack).to.not.contain('propertyGetter'); + + if (typeof Proxy !== 'undefined' && typeof Reflect !== 'undefined') { + expect(caughtErr.stack).to.not.contain('proxyGetter'); + } }); it('should include user frames in stack trace', function () { @@ -255,6 +267,10 @@ describe('configuration', function () { it('should not include Chai frames in stack trace', function () { expect(caughtErr.stack).to.not.contain('overwritingPropertyGetter'); + + if (typeof Proxy !== 'undefined' && typeof Reflect !== 'undefined') { + expect(caughtErr.stack).to.not.contain('proxyGetter'); + } }); it('should include user frames in stack trace', function () {