Skip to content

Commit

Permalink
fix: actaully reset 'injectedKeys' (#2456)
Browse files Browse the repository at this point in the history
* refactor: Remove single-use variable

* fix: actaully reset 'injectedKeys'

Re-assigning the local variable `injectedKeys` would not change `sandbox.injectedKeys`, thus `restoreContext` doesn't fully restore the context.

See:

https://lgtm.com/projects/g/sinonjs/sinon/snapshot/9e09e7d79bac5808ca98fac4f7419a20be4fc43d/files/lib/sinon/sandbox.js?sort=name&dir=ASC&mode=heatmap#x9f770d565ef51b7d:1

* Update lib/sinon/sandbox.js

Co-authored-by: Phred Lane <[email protected]>

---------

Co-authored-by: Phred Lane <[email protected]>
  • Loading branch information
mroderick and fearphage authored Aug 9, 2023
1 parent 8186280 commit 305fb6c
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/sinon/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,15 @@ function Sandbox() {
};

sandbox.restoreContext = function restoreContext() {
let injectedKeys = sandbox.injectedKeys;
const injectInto = sandbox.injectInto;

if (!injectedKeys) {
if (!sandbox.injectedKeys) {
return;
}

forEach(injectedKeys, function (injectedKey) {
delete injectInto[injectedKey];
forEach(sandbox.injectedKeys, function (injectedKey) {
delete sandbox.injectInto[injectedKey];
});

injectedKeys = [];
sandbox.injectedKeys.length = 0;
};

function getFakeRestorer(object, property) {
Expand Down

0 comments on commit 305fb6c

Please sign in to comment.