[BUGFIX beta] Ensure params and hash are frozen in debug builds.#14244
Merged
[BUGFIX beta] Ensure params and hash are frozen in debug builds.#14244
Conversation
This is stripped in production builds, but is useful to help ensure that a given object is not mutated.
Member
|
This is nice! Do you have any idea if there's a performance penalty? |
Member
Author
|
Yes, adding I'm also open to reverting if it turns out that this makes even debug builds too slow, but I generally think that will be unlikely... |
This ensures that `params` and `hash` are both ran through `Object.freeze` in debug builds, but tries to leave the codepaths as simple as possible so that when the `runInDebug`'s are removed the production code can be optimized the same way as prior to this change.
mixonic
added a commit
to mixonic/glimmer
that referenced
this pull request
Dec 17, 2016
When arrays and objects are frozen in JavaScript, it is impossible to attach meta-data (like Ember's own `meta`) to them without using a WeakMap. Ember does adopt the WeakMap strategy in browsers that support it, however there are still supported environments (IE9, IE10) where `Object.freeze` is supported but WeakMap is not. But not freezing these empty arrays and object if WeakMap is missing, legacy meta-data strategies are permitted on those instances. See: * emberjs/ember.js#14264 * emberjs/ember.js#14244
chancancode
pushed a commit
to glimmerjs/glimmer-vm
that referenced
this pull request
Jan 10, 2017
When arrays and objects are frozen in JavaScript, it is impossible to attach meta-data (like Ember's own `meta`) to them without using a WeakMap. Ember does adopt the WeakMap strategy in browsers that support it, however there are still supported environments (IE9, IE10) where `Object.freeze` is supported but WeakMap is not. But not freezing these empty arrays and object if WeakMap is missing, legacy meta-data strategies are permitted on those instances. See: * emberjs/ember.js#14264 * emberjs/ember.js#14244 (cherry picked from commit 6954ade)
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
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.
This ensures that
paramsandhashare both ran throughObject.freezein debug builds, but tries to leave the codepaths as simple as possible so that when therunInDebug's are removed the production code can be optimized the same way as prior to this change.Closes #14189.