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

Cannot stub Array.prototype.sort #1796

Closed
artyhedgehog opened this issue May 17, 2018 · 7 comments
Closed

Cannot stub Array.prototype.sort #1796

artyhedgehog opened this issue May 17, 2018 · 7 comments

Comments

@artyhedgehog
Copy link

artyhedgehog commented May 17, 2018

Describe the bug
Applying stub to Array.prototype.sort results in RangeError: Maximum call stack size exceeded.

To Reproduce
Run test like this:

const sinon = require('sinon');

describe('Cannot stub Array.prototype.sort', () => {
  it('should not fall with call stack size exceeded error', () => {
    // Even making it always call through would not help:
    const stub = sinon.stub(Array.prototype, 'sort').callThrough();
    [1, 2, 3].sort();
    stub.restore();
  });
});

Expected behavior
Test should pass.

Actual behavior
Falls with error:

     RangeError: Maximum call stack size exceeded
      at Function.invoke (node_modules/sinon/lib/sinon/spy.js:1:1)
      at Array.proxy (node_modules/sinon/lib/sinon/spy.js:78:54)
      at Array.functionStub (node_modules/sinon/lib/sinon/stub.js:101:36)
      at Function.invoke (node_modules/sinon/lib/sinon/spy.js:209:51)
      at Array.proxy (node_modules/sinon/lib/sinon/spy.js:78:54)
      at Array.functionStub (node_modules/sinon/lib/sinon/stub.js:101:36)
      at Function.invoke (node_modules/sinon/lib/sinon/spy.js:209:51)
      at Array.proxy (node_modules/sinon/lib/sinon/spy.js:78:54)
      ...

Context:

  • Library version: 5.0.7
  • Environment: nodejs v8.11.1
  • Command: /usr/bin/node ./node_modules/mocha/bin/_mocha sinon.spec.js | head -n20
  • Other libraries you are using: mocha@5.1.1

Additional context
Looks similar to: #1521

@fatso83
Copy link
Contributor

fatso83 commented May 29, 2018

I am sure the fix to this is very similar to #1521. If you grep the source for '.sort()' you should find it quickly. A PR is most welcome ;-)

@stale
Copy link

stale bot commented Aug 5, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@fatso83
Copy link
Contributor

fatso83 commented Aug 6, 2018

I think Phred fixed this in in #1826. Could you verify?

@fatso83
Copy link
Contributor

fatso83 commented Aug 6, 2018

Verified. Still present :(

@mroderick
Copy link
Member

@fatso83 this was fixed in c2c7814, which hasn't been released yet. I've created #1876 to show that this issue has been fixed.

mroderick added a commit that referenced this issue Aug 9, 2018
@mroderick
Copy link
Member

This was fixed in #1826, a test to verify it was added in #1876

@mroderick
Copy link
Member

The fix for this has been published to NPM in sinon@6.1.5

franck-romano pushed a commit to franck-romano/sinon that referenced this issue Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants