Skip to content

Change in 21.1: sinon.stub() throws with --disable-proto=throw #2695

@kevinoid

Description

@kevinoid

Describe the bug

Calling sinon.stub() from Node.js running with --disable-proto=throw causes Error to be thrown.

To Reproduce

  1. Run node --disable-proto=throw -e "require('sinon').stub()" in a project with sinon 21.1 installed.

  2. Observe the output similar to the following:

    /path/to/node_modules/sinon/lib/sinon/util/core/walk.js:29
            if (seen[k] !== true) {
                    ^
    
    Error: Accessing Object.prototype.__proto__ has been disallowed with --disable-proto=throw
        at /path/to/node_modules/sinon/lib/sinon/util/core/walk.js:29:17
        at Array.forEach (<anonymous>)
        at walkInternal (/path/to/node_modules/sinon/lib/sinon/util/core/walk.js:28:5)
        at walkInternal (/path/to/node_modules/sinon/lib/sinon/util/core/walk.js:41:9)
        at walkInternal (/path/to/node_modules/sinon/lib/sinon/util/core/walk.js:41:9)
        at walk (/path/to/node_modules/sinon/lib/sinon/util/core/walk.js:57:12)
        at collectOwnMethods (/path/to/node_modules/sinon/lib/sinon/collect-own-methods.js:39:5)
        at addReturnedMethodsToCollection (/path/to/node_modules/sinon/lib/sinon/sandbox.js:196:21)
        at Sandbox.stub (/path/to/node_modules/sinon/lib/sinon/sandbox.js:229:9)
        at [eval]:1:18 {
      code: 'ERR_PROTO_ACCESS'
    }
    

Expected behavior
The process would produce no output and exit with code 0, as it does with sinon 21.0.3 and earlier.

Context (please complete the following information):

  • Sinon version : 21.1.1
  • Runtime: Node 25

Additional context

I realize running with --disable-proto=throw may not be a supported scenario, and I understand if you choose not to fix this issue. However, I have found it useful for my own projects to flag use of __proto__ and thought it may be worth considering, given that it worked previously.

Thanks for considering,
Kevin

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions