|
237 | 237 | }
|
238 | 238 | }
|
239 | 239 |
|
| 240 | + |
| 241 | + function isLoadLikeEvent(event) { |
| 242 | + switch (event.type) { |
| 243 | + // http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#events-and-the-window-object |
| 244 | + case 'load': |
| 245 | + // http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#unloading-documents |
| 246 | + case 'beforeunload': |
| 247 | + case 'unload': |
| 248 | + return true; |
| 249 | + } |
| 250 | + return false; |
| 251 | + } |
| 252 | + |
240 | 253 | function dispatchEvent(event, originalWrapperTarget) {
|
241 | 254 | if (currentlyDispatchingEvents.get(event))
|
242 | 255 | throw new Error('InvalidStateError');
|
|
254 | 267 | // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#the-end
|
255 | 268 | var overrideTarget;
|
256 | 269 | var win;
|
257 |
| - var type = event.type; |
258 | 270 |
|
259 | 271 | // Should really be not cancelable too but since Firefox has a bug there
|
260 | 272 | // we skip that check.
|
261 | 273 | // https://bugzilla.mozilla.org/show_bug.cgi?id=999456
|
262 |
| - if (type === 'load' && !event.bubbles) { |
| 274 | + if (isLoadLikeEvent(event) && !event.bubbles) { |
263 | 275 | var doc = originalWrapperTarget;
|
264 | 276 | if (doc instanceof wrappers.Document && (win = doc.defaultView)) {
|
265 | 277 | overrideTarget = doc;
|
|
274 | 286 | } else {
|
275 | 287 | eventPath = getEventPath(originalWrapperTarget, event);
|
276 | 288 |
|
277 |
| - if (event.type !== 'load') { |
| 289 | + if (!isLoadLikeEvent(event)) { |
278 | 290 | var doc = eventPath[eventPath.length - 1];
|
279 | 291 | if (doc instanceof wrappers.Document)
|
280 | 292 | win = doc.defaultView;
|
|
380 | 392 | var type = event.type;
|
381 | 393 |
|
382 | 394 | var anyRemoved = false;
|
383 |
| - // targetTable.set(event, target); |
384 | 395 | targetTable.set(event, target);
|
385 | 396 | currentTargetTable.set(event, currentTarget);
|
386 | 397 |
|
|
465 | 476 | function Event(type, options) {
|
466 | 477 | if (type instanceof OriginalEvent) {
|
467 | 478 | var impl = type;
|
468 |
| - if (!OriginalBeforeUnloadEvent && impl.type === 'beforeunload') { |
| 479 | + // In browsers that do not correctly support BeforeUnloadEvent we get to |
| 480 | + // the generic Event wrapper but we still want to ensure we create a |
| 481 | + // BeforeUnloadEvent. Since BeforeUnloadEvent calls super, we need to |
| 482 | + // prevent reentrancty. |
| 483 | + if (!OriginalBeforeUnloadEvent && impl.type === 'beforeunload' && |
| 484 | + !(this instanceof BeforeUnloadEvent)) { |
469 | 485 | return new BeforeUnloadEvent(impl);
|
470 | 486 | }
|
471 | 487 | setWrapper(impl, this);
|
|
0 commit comments