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

lib: check number of arguments in EventTarget's function #45668

Conversation

deokjinkim
Copy link
Contributor

For now, addEventListener() only checks number of arguments.
removeEventListener() and dispatchEvent() also need checking number of arguments.

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. readline Issues and PRs related to the built-in readline module. labels Nov 29, 2022
@mscdex
Copy link
Contributor

mscdex commented Nov 29, 2022

I don't think it's necessary to be this strict (validating arguments.length). These functions already validate the argument values themselves.

@deokjinkim
Copy link
Contributor Author

I don't think it's necessary to be this strict. These functions already validate the argument values themselves.

As you can see in code change(lib/readline.js), I think wrong usage(ex. 1 argument is passed to removeEventListener) is allowed for removeEventListener for now. wdyt?

@mscdex
Copy link
Contributor

mscdex commented Nov 29, 2022

The readline change needs a test to verify the cleanup function is working correctly if there isn't already one.

Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Can you check if there's a WPT test for this?

test/parallel/test-eventtarget.js Outdated Show resolved Hide resolved
@aduh95
Copy link
Contributor

aduh95 commented Nov 29, 2022

I don't think it's necessary to be this strict (validating arguments.length). These functions already validate the argument values themselves.

I disagree, I think it is necessary so our implementation is compliant with the WebIDL spec, and aligns with the other runtimes.

lib/readline.js Outdated
@@ -145,7 +145,7 @@ Interface.prototype.question = function question(query, options, cb) {
};
options.signal.addEventListener('abort', onAbort, { once: true });
const cleanup = () => {
options.signal.removeEventListener(onAbort);
options.signal.removeEventListener('abort', onAbort);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you send another PR for this fix so it can be backported more easily?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created another PR(#45676) to resolve this issue. PTAL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aduh95 Can I create PR for backport of #45676? If yes, is v18.x-staging branch proper?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That shouldn’t be necessary, commits that land on main are automatically back ported to current and active LTS release lines after the appropriate “maturation period”, backport PRs are necessary only if the commit doesn’t apply cleanly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for kind explanation. It's very helpful for me 👍

@deokjinkim
Copy link
Contributor Author

LGTM. Can you check if there's a WPT test for this?

I couldn't find the same test in dom/event of WPT(https://github.com/web-platform-tests/wpt/tree/master/dom/events). BTW, chrome samples have similar tests.
ref1. https://googlechrome.github.io/samples/event-listeners-mandatory-arguments/
ref2. https://github.com/GoogleChrome/samples/blob/gh-pages/event-listeners-mandatory-arguments/demo.js

For now, addEventListener() only checks number of arguments.
removeEventListener() and dispatchEvent() also need checking
number of arguments.
@deokjinkim deokjinkim force-pushed the 221129_check_number_parameter_eventtarget branch from 604b3c8 to cc631b2 Compare December 1, 2022 15:37
test/parallel/test-eventtarget.js Outdated Show resolved Hide resolved
test/parallel/test-eventtarget.js Outdated Show resolved Hide resolved
test/parallel/test-eventtarget.js Outdated Show resolved Hide resolved
test/parallel/test-eventtarget.js Outdated Show resolved Hide resolved
test/parallel/test-eventtarget.js Outdated Show resolved Hide resolved
@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. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. eventtarget Issues and PRs related to the EventTarget implementation. and removed readline Issues and PRs related to the built-in readline module. labels Dec 1, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 1, 2022
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@daeyeon daeyeon added the commit-queue Add this label to land a pull request using GitHub Actions. label Dec 9, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Dec 9, 2022
@nodejs-github-bot nodejs-github-bot merged commit c776324 into nodejs:main Dec 9, 2022
@nodejs-github-bot
Copy link
Collaborator

Landed in c776324

ErickWendel pushed a commit to ErickWendel/node that referenced this pull request Dec 12, 2022
For now, addEventListener() only checks number of arguments.
removeEventListener() and dispatchEvent() also need checking
number of arguments.

PR-URL: nodejs#45668
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
targos pushed a commit that referenced this pull request Dec 12, 2022
For now, addEventListener() only checks number of arguments.
removeEventListener() and dispatchEvent() also need checking
number of arguments.

PR-URL: #45668
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
targos pushed a commit that referenced this pull request Dec 13, 2022
For now, addEventListener() only checks number of arguments.
removeEventListener() and dispatchEvent() also need checking
number of arguments.

PR-URL: #45668
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
danielleadams pushed a commit that referenced this pull request Dec 30, 2022
For now, addEventListener() only checks number of arguments.
removeEventListener() and dispatchEvent() also need checking
number of arguments.

PR-URL: #45668
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
danielleadams pushed a commit that referenced this pull request Dec 30, 2022
For now, addEventListener() only checks number of arguments.
removeEventListener() and dispatchEvent() also need checking
number of arguments.

PR-URL: #45668
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
danielleadams pushed a commit that referenced this pull request Jan 3, 2023
For now, addEventListener() only checks number of arguments.
removeEventListener() and dispatchEvent() also need checking
number of arguments.

PR-URL: #45668
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
danielleadams pushed a commit that referenced this pull request Jan 4, 2023
For now, addEventListener() only checks number of arguments.
removeEventListener() and dispatchEvent() also need checking
number of arguments.

PR-URL: #45668
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
danielleadams pushed a commit that referenced this pull request Jan 5, 2023
For now, addEventListener() only checks number of arguments.
removeEventListener() and dispatchEvent() also need checking
number of arguments.

PR-URL: #45668
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. eventtarget Issues and PRs related to the EventTarget implementation. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants