-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[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.
This is nice! Do you have any idea if there's a performance penalty? |
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.
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
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 ensures that
params
andhash
are both ran throughObject.freeze
in 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.