Skip to content

Selector: Use shallow document comparisons to avoid IE/Edge crashes #4471

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

Merged
merged 2 commits into from
Sep 24, 2019

Conversation

mgol
Copy link
Member

@mgol mgol commented Aug 26, 2019

Summary

IE/Edge sometimes crash when comparing documents between frames using the strict
equality operator (=== & !==). Funnily enough, shallow comparisons
(== & !=) work without crashing.

Fixes gh-4441

While I cannot be 100% certain this PR will solve the issue, I modified the code locally, wrapping the place where the browser crashes in a try-catch where I assigned both compared documents to global variables. I then compared them using all 4 operators manually in the console and the strict one were always crashing. I reproduced the same behavior in IE 11 & Edge 18.

I can't really write a test for it as the crashes are not consistent - the only consistent thing was that if it crashed once on a particular comparison, it keeps crashing on strict-comparing those two documents.

This fixes a failure in traversing tests but the code is in Selector so I'm marking the component as such.

Checklist

src/selector.js Outdated
// IE/Edge sometimes throw a "Permission denied" error when strict-comparing
// two documents; shallow comparisons work.
// eslint-disable-next-line eqeqeq
if ( ( context ? context.ownerDocument || context : preferredDoc ) != document ) {
Copy link
Member Author

@mgol mgol Aug 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is the only place where I've seen IE/Edge test failures. I thought, though, that it may be worth changing all document comparisons to make sure we're not missing some potential errors.

I could also create an internal utility function to compare documents & put the comment there. That would most likely increase the size, though (currently this PR is at -5 bytes).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A version with an utility function would be +15 bytes instead of -5: mgol@53d0840.

@mgol
Copy link
Member Author

mgol commented Aug 26, 2019

I'll submit a Sizzle PR after we have consensus here.

if ( doc === document || doc.nodeType !== 9 ) {
// Support: IE 11+, Edge 17 - 18+
// IE/Edge sometimes throw a "Permission denied" error when strict-comparing
// two documents; shallow comparisons work.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to go for this solution, do you think we should avoid this duplicate comment in some way?

@mgol
Copy link
Member Author

mgol commented Aug 27, 2019

What's funny is that I can reproduce the issue easily (not 100% of times but pretty often) in IE 11 & Edge 18 & I assume by TestSwarm failures that it's reproducible in Edge 17 as well - but I cannot reproduce it in IE 9 or 10. Seems they regressed?

…crashes

IE/Edge sometimes crash when comparing documents between frames using the strict
equality operator (`===` & `!==`). Funnily enough, shallow comparisons
(`==` & `!=`) work without crashing.

Fixes jquerygh-4441
@mgol mgol force-pushed the ie-edge-traversing-crash branch from aa710a0 to 6b1c6a7 Compare August 30, 2019 23:51
Copy link
Member

@timmywil timmywil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So weird, but hey, if it works.

@timmywil
Copy link
Member

I still approve.

@mgol mgol removed the Needs review label Sep 24, 2019
@mgol mgol changed the title Selector: Use shallow equality to compare documents to avoid IE/Edge crashes Selector: Use shallow document comparisons to avoid IE/Edge crashes Sep 24, 2019
@mgol mgol merged commit aa6344b into jquery:master Sep 24, 2019
@mgol mgol deleted the ie-edge-traversing-crash branch September 24, 2019 22:41
mgol added a commit to mgol/jquery that referenced this pull request Sep 24, 2019
IE/Edge sometimes crash when comparing documents between frames using the strict
equality operator (`===` & `!==`). Funnily enough, shallow comparisons
(`==` & `!=`) work without crashing.

The change to shallow comparisons in `src/selector.js` was done in jquerygh-4471 but
relevant changes in `src/selector/uniqueSort.js` were missed.

Fixes jquerygh-4441
Closes jquerygh-4471
mgol added a commit to mgol/sizzle that referenced this pull request Sep 26, 2019
IE/Edge sometimes crash when comparing documents between frames using the strict
equality operator (`===` & `!==`). Funnily enough, shallow comparisons
(`==` & `!=`) work without crashing.

Fixes jquery/jquery#4441
Closes jquery/jquery#4471
mgol added a commit to mgol/sizzle that referenced this pull request Sep 30, 2019
IE/Edge sometimes crash when comparing documents between frames using the strict
equality operator (`===` & `!==`). Funnily enough, shallow comparisons
(`==` & `!=`) work without crashing.

Fixes jquery/jquery#4441
Closes jquery/jquery#4471
mgol added a commit to mgol/sizzle that referenced this pull request Oct 1, 2019
IE/Edge sometimes crash when comparing documents between frames using the strict
equality operator (`===` & `!==`). Funnily enough, shallow comparisons
(`==` & `!=`) work without crashing.

Fixes jquery/jquery#4441
Closes jquery/jquery#4471
mgol added a commit to jquery/sizzle that referenced this pull request Oct 1, 2019
IE/Edge sometimes crash when comparing documents between frames using the strict
equality operator (`===` & `!==`). Funnily enough, shallow comparisons
(`==` & `!=`) work without crashing.

Fixes jquery/jquery#4441
Closes gh-459
Ref jquery/jquery#4471
mgol added a commit to mgol/jquery that referenced this pull request Oct 9, 2019
IE/Edge sometimes crash when comparing documents between frames using the strict
equality operator (`===` & `!==`). Funnily enough, shallow comparisons
(`==` & `!=`) work without crashing.

The change to shallow comparisons in `src/selector.js` was done in jquerygh-4471 but
relevant changes in `src/selector/uniqueSort.js` were missed.

Fixes jquerygh-4441
Closes jquerygh-4471
mgol added a commit to mgol/jquery that referenced this pull request Oct 14, 2019
IE/Edge sometimes crash when comparing documents between frames using the strict
equality operator (`===` & `!==`). Funnily enough, shallow comparisons
(`==` & `!=`) work without crashing.

The change to shallow comparisons in `src/selector.js` was done in jquerygh-4471 but
relevant changes in `src/selector/uniqueSort.js` were missed.

Fixes jquerygh-4441
Closes jquerygh-4471
mgol added a commit to mgol/jquery that referenced this pull request Oct 14, 2019
IE/Edge sometimes crash when comparing documents between frames using the strict
equality operator (`===` & `!==`). Funnily enough, shallow comparisons
(`==` & `!=`) work without crashing.

The change to shallow comparisons in `src/selector.js` was done in jquerygh-4471 but
relevant changes in `src/selector/uniqueSort.js` were missed. Those changes
have landed in Sizzle in jquery/sizzle#459.

Fixes jquerygh-4441
Closes jquerygh-4471
Ref jquery/sizzle#459
mgol added a commit that referenced this pull request Oct 21, 2019
IE/Edge sometimes crash when comparing documents between frames using the strict
equality operator (`===` & `!==`). Funnily enough, shallow comparisons
(`==` & `!=`) work without crashing.

The change to shallow comparisons in `src/selector.js` was done in gh-4471 but
relevant changes in `src/selector/uniqueSort.js` were missed. Those changes
have landed in Sizzle in jquery/sizzle#459.

Fixes gh-4441
Closes gh-4512
Ref gh-4471
Ref jquery/sizzle#459
@lock lock bot locked as resolved and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

IE & Edge crash with "Permission denied" on the contents() for <frame /> test
2 participants