Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

fix(server): enforce 'use strict' everywhere #2124

Merged
merged 1 commit into from
Sep 19, 2017
Merged

Conversation

philbooth
Copy link
Contributor

Train 96 contains a few things that I expect to improve the performance of auth server routes. In order to maximise the improvement, and because non-strict code prohibits some V8 optimisations, I decided to add 'use strict' directives everywhere and enforce their presence in .eslintrc.

As an added bonus, I found two bona fide issues in the code by enabling strict mode. Neither causes any problems in production (one was in test code, the other was harmless but logically insane), but it's a pertinent reminder of why strict mode is to be preferred. I'll call them out explicitly inline.

And sorry, I've ended up creating one of those PRs that I always moan about. I'll make a point of complaining about my own behaviour in next week's retro.

@mozilla/fxa-devs r?

@@ -40,7 +42,6 @@ module.exports = (log, config) => {
KEYS.forEach(name => {
this[name] = keys[name] && keys[name].toString('hex')
})
this.algorithm = 'sha256'
Copy link
Contributor Author

@philbooth philbooth Sep 19, 2017

Choose a reason for hiding this comment

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

This throws in strict mode. algorithm is a defined property with a getter that returns 'sha256', but no setter. This line was clobbering it. Presumably we prefer the getter to the raw property (for precisely this reason), hence I deleted this line.

@@ -467,7 +469,7 @@ module.exports = config => {
headers,
options
)
.then(function (response) {
.then(response => {
// Update to the new verified tokens
this.sessionToken = response.sessionToken
this.keyFetchToken = response.keyFetchToken
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This callback was unbound so we were actually creating two new global variables called sessionToken and keyFetchToken here. Introducing strict mode changed that behaviour to throw and I've fixed the problem using fat arrow.

@philbooth philbooth changed the title fix(server): enforece 'use strict' everywhere fix(server): enforce 'use strict' everywhere Sep 19, 2017
Copy link
Contributor

@vbudhram vbudhram left a comment

Choose a reason for hiding this comment

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

@vbudhram vbudhram merged commit df6cd60 into master Sep 19, 2017
@philbooth philbooth deleted the phil/use-strict branch September 19, 2017 13:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants