-
-
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
Helpers mutating hash
may error if no hash was provided.
#14189
Comments
@chancancode - Need your thoughts on this... |
I'm not feeling super sympathetic on this one. Mutating your arguments is usually a bad idea. It's unfortunate that we can't easily provide consistent behavior: either always give you a frozen hash (whether or not it's empty), or always give you a copy that is yours to abuse. Either of those choices sound expensive in terms of allocations. |
@ef4 - Perhaps we could freeze/seal all params and hash when in debug only? That would provide a fairly common footing but still avoid the extra cost in production... |
Yeah. I think I agree with @ef4. The debugSeal idea seems good if it's not very slow? |
FWIW the problem in ember-page-title has been resolved already: ember-cli/ember-page-title#41 |
One optimization that the Glimmer engine does is to avoid creating objects when it does not need to. An example of this can be seen when evaluating helper and/or component invocations where there is no hash arguments. Such as this:
In order to avoid creating a wasted hash argument here, Glimmer will use a custom
EVALUATED_EMPTY_NAMED_ARGS
which always returns a shared constant namedEMPTY_DICT
. In order to prevent that shared constant from being mutated, the engine usesObject.freeze(EMPTY_DICT)
.All of these assumptions/steps are completely reasonable. Unfortunately, where this falls down is when a helper (such as ember-page-title) mutate that provided hash argument. If you do this, the following error is triggered:
JSBin Demo Here
We need to decide if we must "fix" this by providing a custom hash object to each helper invocation (less than ideal because we would much prefer to benefit from doing less work).
The text was updated successfully, but these errors were encountered: