fix: throw a clear error when throwArg index equals the argument count#2743
Open
spokodev wants to merge 1 commit into
Open
fix: throw a clear error when throwArg index equals the argument count#2743spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
spyCall.throwArg(pos) guarded with pos > this.args.length, so calling it with pos equal to the number of recorded arguments slipped past the guard and reached throw this.args[pos], throwing undefined instead of the intended TypeError. A thrown undefined cannot be inspected as an Error and is reported by test frameworks as no exception thrown. Use >= to match ensureArgs in behavior.js and the sibling callArg helpers, which already reject an out-of-range index with a clear error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
spyCall.throwArg(pos)(and the aggregatespy.throwArg(pos)) make a recorded call throw one of its own arguments. The bounds guard is off by one, so callingthrowArg(pos)withposequal to the number of recorded arguments throwsundefinedinstead of the intendedTypeError.Valid indices are
0 .. args.length - 1. The guardpos > this.args.lengthletspos === args.lengththrough tothrow this.args[pos], wherethis.args[pos]isundefined. The thrownundefinedcannot be inspected as an Error, and test frameworks report it as "no exception was thrown", which hides the real off-by-one.The sibling helpers (
callArg,callArgOn, and the rest) and the stub-timethrowsArg(viaensureArgsinbehavior.js, which uses>=) already reject an out-of-range index with a clear error. PR #1848 established that these argument-index helpers should throw a clearTypeErrorrather than yieldundefined.Fix
Change the guard in
src/sinon/proxy-call.jsfrom>to>=, matchingensureArgs:Added a
call.throwArgblock totest/src/proxy-call-test.js: it throws the argument at a valid index, and throws a clearTypeErrorwhen the index equals or exceeds the argument count. The equal-to-count case fails before this change; the fulltest/srcsuite (1497) stays green.