Skip to content
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

Backport: Introduce flag for length access after push/unshift #402

Merged
merged 2 commits into from
Jan 31, 2023

Conversation

chriskrycho
Copy link
Collaborator

Backport of #397 for a 3.1.1 release. There are some (known) bugs with lazy engines and ember-auto-import which make pulling in a v2 addon difficult in some cases. This should unblock that.

@chriskrycho chriskrycho added the bug Something isn't working label Jan 31, 2023
… bug

Simply doing a `.push()` or `.unshift()` call after creating the Array
during construction of a component is enough to trigger the issue. This
will be red in CI; the follow-on commit will fix it.

(cherry picked from commit bd984e6)
For these methods, `Array` itself immediately gets the `.length` to
return after invoking them. Thus, if we are reading `.length`, it may
be a normal user-triggered read, or it may be a read triggered by Array
itself. In the latter case, it is because we have just done `.push()`
or `.unshift()`; in that case it is safe *not* to treat reading
`.length` as a *read* operation, since calling `.push()` or
`.unshift()` cannot otherwise be part of a "read" operation safely, and
if done during an *existing* read (e.g. if the user has already checked
`.length` *prior* to this), that will still trigger the assertion.

Accordingly, set the new flag to `true` when calling `.push()` or
`.unshift()`, and then clear it during the immediately-following
`.length` check.

(cherry picked from commit 7621b04)
@chriskrycho chriskrycho merged commit 08f773c into v3.1.x Jan 31, 2023
@chriskrycho chriskrycho deleted the backport-bugfix branch January 31, 2023 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant