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

assert: fix CallTracker calls wraps the function causes the original … #42909

Merged
merged 5 commits into from
May 6, 2022

Conversation

y1d7ng
Copy link
Contributor

@y1d7ng y1d7ng commented Apr 29, 2022

CallTracker calls wraps the function causes the original length to be lost. But many scenarios depend on the length of the function.

function func(a, b, c = 2) {}
const tracker = new assert.CallTracker();
const callsfunc = tracker.calls(func);

func.length is 2, but callsfunc.length is 0.

Fixes: #40484

@nodejs-github-bot nodejs-github-bot added assert Issues and PRs related to the assert subsystem. needs-ci PRs that need a full CI run. labels Apr 29, 2022
@aduh95
Copy link
Contributor

aduh95 commented Apr 29, 2022

Should we overwrite the name property as well?

@y1d7ng
Copy link
Contributor Author

y1d7ng commented Apr 29, 2022

Should we overwrite the name property as well?

should use the original function name or the decorative name, eg calls xxx, to overwrite.

@aduh95
Copy link
Contributor

aduh95 commented Apr 29, 2022

I think using the exact original name makes more sense, but no strong opinion.

@targos
Copy link
Member

targos commented Apr 29, 2022

Am I missing something or the implementation would be much simpler (and less prone to errors like this PR fixes) as a Proxy ?

@y1d7ng
Copy link
Contributor Author

y1d7ng commented Apr 29, 2022

@aduh95 @targos Thanks very much for review, I chose to use the proxy solution and have pushed new change.

@y1d7ng y1d7ng requested a review from aduh95 April 29, 2022 16:28
@y1d7ng y1d7ng requested a review from aduh95 April 29, 2022 17:11
lib/internal/assert/calltracker.js Outdated Show resolved Hide resolved
lib/internal/assert/calltracker.js Outdated Show resolved Hide resolved
@y1d7ng y1d7ng requested a review from aduh95 April 29, 2022 19:02
@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Apr 29, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 29, 2022
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

lib/internal/assert/calltracker.js Outdated Show resolved Hide resolved
lib/internal/assert/calltracker.js Outdated Show resolved Hide resolved
@aduh95 aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. label May 3, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 3, 2022
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@y1d7ng
Copy link
Contributor Author

y1d7ng commented May 6, 2022

Hi @aduh95, can this be merged?

@aduh95 aduh95 added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels May 6, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label May 6, 2022
@nodejs-github-bot nodejs-github-bot merged commit 187b99b into nodejs:master May 6, 2022
@nodejs-github-bot
Copy link
Collaborator

Landed in 187b99b

RafaelGSS pushed a commit that referenced this pull request May 10, 2022
PR-URL: #42909
Fixes: #40484
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
@RafaelGSS RafaelGSS mentioned this pull request May 10, 2022
@y1d7ng y1d7ng deleted the fix-calltracker branch May 10, 2022 16:50
juanarbol pushed a commit that referenced this pull request May 31, 2022
PR-URL: #42909
Fixes: #40484
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
danielleadams pushed a commit that referenced this pull request Jun 27, 2022
PR-URL: #42909
Fixes: #40484
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
targos pushed a commit that referenced this pull request Jul 12, 2022
PR-URL: #42909
Fixes: #40484
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
targos pushed a commit that referenced this pull request Jul 31, 2022
PR-URL: #42909
Fixes: #40484
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
guangwong pushed a commit to noslate-project/node that referenced this pull request Oct 10, 2022
PR-URL: nodejs/node#42909
Fixes: nodejs/node#40484
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assert Issues and PRs related to the assert subsystem. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CallTracker wrapper function to have original function length
4 participants