FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

stream: remove isPromise utility function by aduh95 · Pull Request #35925 · nodejs/node · GitHub

/ node Public

stream: remove isPromise utility function - #35925

Closed
aduh95 wants to merge 2 commits into
nodejs:masterfrom
aduh95:stream-remove-isPromise
Closed

stream: remove isPromise utility function#35925
aduh95 wants to merge 2 commits into
nodejs:masterfrom
aduh95:stream-remove-isPromise

Conversation

aduh95 commented Nov 2, 2020
edited
Loading

Copy link
Copy Markdown
Contributor

The function was not checking if the parameter was actually a Promise
instance, but if it has a then method. Removing the utility function
in favor of a clearer typeof check, handling the case when the
thenable throws if then method is accessed more than once.

The difference between a thenable and a Promise may be important when using third party library (the parameter is provided by the user) and/or when Promise.prototype.then value is changed from userland.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/streams

ronag left a comment
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm not sure this is an improvement? The behavior is the same?

aduh95 commented Nov 2, 2020

Copy link
Copy Markdown
Contributor Author

Yes the behavior is the same. Another way would be to change the name of the function isPromise -> isThenable.

Copy link
Copy Markdown
Member

Actually the current implementation (and the one in this PR) is wrong if someone passes a thenable where then is a getter that throws the second time then is accessed.

It's not a big bug but promise test suites check for it.

The correct implementation would be to do it in "two steps":

  • First do const then = ret?.then
  • Then check if(typeof then === "function")
  • Then do then.call(ret, ...)

See here for an example

ronag added a commit to nodejs/undici that referenced this pull request Nov 2, 2020
The function was not checking if the parameter was actually a Promise
instance, but if it has a `then` method. Removing the utility function
in favor of a clearer `typeof` check, handling the case when the
thenable throws if then method is accessed more than once.
aduh95 force-pushed the stream-remove-isPromise branch from 35e4d0a to f18db47 Compare November 2, 2020 16:21
aduh95 requested a review from ronag November 2, 2020 16:21

aduh95 commented Nov 2, 2020

Copy link
Copy Markdown
Contributor Author

I've implemented the solution suggested by @benjamingr, PTAL.

benjamingr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please consider adding a test.

If you prefer not to - I'll add one sometime after this lands :]

aduh95 commented Nov 3, 2020

Copy link
Copy Markdown
Contributor Author

Test added! It does fail on master and not with this PR, PTAL.

@ronag Have your concerns been addressed?

aduh95 commented Nov 8, 2020

Copy link
Copy Markdown
Contributor Author

@ronag are you still blocking this or can your objection be dismissed?

aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. label Nov 8, 2020
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 8, 2020

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Copy Markdown
Collaborator

mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

lgtm

mcollina added the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 9, 2020
github-actions Bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 9, 2020

github-actions Bot commented Nov 9, 2020

Copy link
Copy Markdown
Contributor

Landed in adae822...ad98cf0

github-actions Bot closed this Nov 9, 2020
nodejs-github-bot pushed a commit that referenced this pull request Nov 9, 2020
The function was not checking if the parameter was actually a Promise
instance, but if it has a `then` method. Removing the utility function
in favor of a clearer `typeof` check, handling the case when the
thenable throws if then method is accessed more than once.

PR-URL: #35925
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
aduh95 deleted the stream-remove-isPromise branch November 9, 2020 08:32
danielleadams pushed a commit that referenced this pull request Nov 9, 2020
The function was not checking if the parameter was actually a Promise
instance, but if it has a `then` method. Removing the utility function
in favor of a clearer `typeof` check, handling the case when the
thenable throws if then method is accessed more than once.

PR-URL: #35925
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
danielleadams mentioned this pull request Nov 9, 2020
targos pushed a commit that referenced this pull request May 1, 2021
The function was not checking if the parameter was actually a Promise
instance, but if it has a `then` method. Removing the utility function
in favor of a clearer `typeof` check, handling the case when the
thenable throws if then method is accessed more than once.

PR-URL: #35925
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
danielleadams mentioned this pull request May 3, 2021
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL