Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Re-land fix for unload/beforeunload events #499

Merged
merged 1 commit into from
Sep 5, 2014

Conversation

jmesserly
Copy link
Contributor

The implementation code change compared to last time is fixes a stack overflow in the BeforeUnloadEvent polyfill, which the new test is hitting. This affected Safari which doesn't have a native BeforeUnloadEvent yet.

The test has several fixes for IE 10/11. IE had two different problems: e.target is window vs document in others, and the unload event won't fire in an iframe unless we setTimeout(0) before adding the handler.

This fixes https://github.com/Polymer/platform/issues/83

@kegluneq @arv mind taking another look?

@@ -465,7 +476,8 @@
function Event(type, options) {
if (type instanceof OriginalEvent) {
var impl = type;
if (!OriginalBeforeUnloadEvent && impl.type === 'beforeunload') {
if (!OriginalBeforeUnloadEvent && impl.type === 'beforeunload' &&
!(this instanceof BeforeUnloadEvent)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

BeforeUnloadEvent calls super here:
https://github.com/Polymer/ShadowDOM/blob/master/src/wrappers/events.js#L641

so we need to check that to prevent a stack overflow

Copy link
Contributor

Choose a reason for hiding this comment

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

This could use a comment:

// In browsers that do not correctly support BeforeUnloadEvent we get to the generic
// Event wrapper but we still want to ensure we create a BeforeUnloadEvent. Since
// BeforeUnloadEvent calls super we need to prevent reentrancty

I wonder if removing the super call would lead to cleaner code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call on the comment.

I wonder if removing the super call would lead to cleaner code?

yeah, that's a really good point. It looks like the only line we'd need instead of the super call is setWrapper(impl, this);

@jmesserly
Copy link
Contributor Author

btw, the branch name is wrong, but the issue linked in the commit is correct. :)

@@ -465,7 +476,12 @@
function Event(type, options) {
if (type instanceof OriginalEvent) {
var impl = type;
if (!OriginalBeforeUnloadEvent && impl.type === 'beforeunload') {
// In browsers that do not correctly support BeforeUnloadEvent we get to
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ended up going with the comment and kept the super call in BeforeUnloadEvent ctor, since it looked like it was going to cause too much duplication to avoid the super constructor call

@jmesserly
Copy link
Contributor Author

PTAL ... also, it seems like rebase+push lost the old comments ... sorry about that. Github used to say "comments discussing an outdated diff" but I don't see that anymore. I was using rebase to keep a clean commit history but maybe is not worth it.

@jmesserly jmesserly mentioned this pull request Sep 5, 2014
jmesserly pushed a commit that referenced this pull request Sep 5, 2014
Re-land fix for unload/beforeunload events
@jmesserly jmesserly merged commit 565b978 into master Sep 5, 2014
@jmesserly jmesserly deleted the polymer_issue_421_take2 branch September 5, 2014 19:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants