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

Commit

Permalink
Merge branch 'event-multiple-dispatch' of git://github.com/arv/Shadow…
Browse files Browse the repository at this point in the history
…DOM into arv-event-multiple-dispatch

Conflicts:
	test/js/events.js
  • Loading branch information
dfreedm committed Oct 10, 2013
2 parents 07c8f4d + abfa4bf commit 3a994df
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/wrappers/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,12 @@
},
dispatchEvent: function(event) {
var target = getTargetToListenAt(this);
return target.dispatchEvent_(unwrap(event));
var nativeEvent = unwrap(event);
// Allow dispatching the same event again. This is safe because if user
// code calls this during an existing dispatch of the same event the
// native dispatchEvent throws (that is required by the spec).
handledEventsTable.set(nativeEvent, false);
return target.dispatchEvent_(nativeEvent);
}
};

Expand All @@ -660,7 +665,6 @@
forwardMethodsToWrapper(constructors, methodNames);
}


var originalElementFromPoint = document.elementFromPoint;

function elementFromPoint(self, document, x, y) {
Expand Down
38 changes: 38 additions & 0 deletions test/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,44 @@ test('retarget order (multiple shadow roots)', function() {
text.dispatchEvent(new Event('x'));
});

test('dispatch same event object twice', function() {
var e = new Event('x', {bubbles: true});
var doc = wrap(document);

var count = 0;
function handler(e) {
count++;
};

doc.addEventListener('x', handler);

document.dispatchEvent(e);
assert.equal(count, 1);
document.dispatchEvent(e);
assert.equal(count, 2);
document.dispatchEvent(e);
assert.equal(count, 3);

doc.removeEventListener('x', handler);
});

test('Ensure nested dispatch is not allowed', function() {
var e = new Event('x', {bubbles: true});
var doc = wrap(document);

var count = 0;

doc.addEventListener('x', function f(e) {
count++;
assert.throws(function() {
doc.dispatchEvent(e);
});
});

doc.dispatchEvent(e);
assert.equal(count, 1);
});

test('manual relatedTarget', function() {
var ce = new CustomEvent('x');
ce.relatedTarget = 42;
Expand Down

0 comments on commit 3a994df

Please sign in to comment.