[BUGFIX] Only freeze empty array/dict with weakmap #361
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.
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) whereObject.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.The change here is untested, however I will add upstream tests in Ember for the relevant cases.
See:
The approach here is pretty naive. Some other more complex approaches I considered were:
env
. This, however, would mean the empty evaluated and compiles positional and named arguments instances could not be eagerly created.HAS_NATIVE_WEAKMAP
value from Glimmer'sglimmer-runtime
package and use that instead of Ember's implementation. This would remove some small duplication, but it feels a bit weird to haveHAS_NATIVE_WEAKMAP
as a glimmer export.Happy to make edits in one of those directions.