Add "then" to strings which may be used elsewhere #159
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.
The massive adoption of Promises (and introduction of
async
/await
based on them) in JavaScript made many programs potentially vulnerable to "accidental Promises".In short, a program might take user input and produce an object as such:
...when the object above is given to a Promise (by returning it from
then
, callingPromise.resolve
, passing it intores
orrej
when constructing anew Promise
, or awaiting/returning it from anasync
function), everything will seem fine unless the input is exactly"then"
. Once it's then, a Promise will assume that the object is another Promise, and in trying to assimilate this accidental Promise the function will be called. After that, one of three things will happen depending on what theAnyFunction
does with its input:For more in-depth information, please refer to the appropriate sections in the articles I've written regarding this issue: