allow decoration of reply with non functions#3519
Merged
hueniverse merged 1 commit intohapijs:masterfrom Jul 17, 2017
Merged
Conversation
AdriVanHoudt
reviewed
Jun 8, 2017
| const method = methods[i]; | ||
| const decoration = this._decorations[method]; | ||
| reply[method] = (domain ? domain.bind(decoration) : decoration); | ||
| reply[method] = domain && typeof decoration === 'function' ? domain.bind(decoration) : decoration; |
Contributor
There was a problem hiding this comment.
I would add () around domain && typeof decoration === 'function' to make it clearer
LGTM otherwise
|
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
After 16.2.0, it's not possible to decorate the reply object with something different to a function. This is due to the work originated on #3448 where all reply methods are being bound to the request domain.
After that @hueniverse made a change to make sure that decorator methods are also bound to the domain, but it expects that any decoration added to the reply is also a function.
We were able to fix our issue by checking first that the decoration is in fact a function, and only bound it if that's the case.
I'm not sure if this is really a fix and if it's expected to be able to decorate the reply with something different to a function. I see that you always name the decoration as "method", but on the docs you mention the method argument for the decorate function can be
which makes me think that adding anything that's not a function is expected.
If the accepted behavior is to only allow functions to decorate the reply, then I'd be happy to contribute by adding an assertion on
decorateto expect only functions and updating the docs to make that clear.