Skip to content

Commit

Permalink
Avoid needless hasOwnProperty check in deepFreeze.
Browse files Browse the repository at this point in the history
The "own" in getOwnPropertyNames ensures that all the names would pass the
hasOwnProperty test.

#3300 (comment)

Regarding this comment by @jamesreggio, I would much rather patch
apollo-utilities than revert the use of Object.create(null), since empty
prototype-free objects never accidentally appear to have properties
inherited from Object.prototype (a correctness concern), and lookups of
missing properties are faster since there's no prototype chain. Far from
being deficient, Object.create(null) objects are what empty objects should
always have been in JavaScript.
  • Loading branch information
benjamn committed Jun 5, 2018
1 parent 04b1e06 commit fb5d021
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/apollo-utilities/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
`{ prop2: 'value2', prop1: 'value1' }`.
[PR #2869](https://github.com/apollographql/apollo-client/pull/2869)

- Avoid needless `hasOwnProperty` check in `deepFreeze`.
[PR #3545](https://github.com/apollographql/apollo-client/pull/3545)

### 1.0.13

- Make `maybeDeepFreeze` a little more defensive, by always using
Expand Down
3 changes: 0 additions & 3 deletions packages/apollo-utilities/src/util/maybeDeepFreeze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import { isDevelopment, isTest } from './environment';
function deepFreeze(o: any) {
Object.freeze(o);

const hasOwn = Object.prototype.hasOwnProperty;

Object.getOwnPropertyNames(o).forEach(function(prop) {
if (
hasOwn.call(o, prop) &&
o[prop] !== null &&
(typeof o[prop] === 'object' || typeof o[prop] === 'function') &&
!Object.isFrozen(o[prop])
Expand Down

0 comments on commit fb5d021

Please sign in to comment.