-
Notifications
You must be signed in to change notification settings - Fork 6
/
dispatch.js
29 lines (25 loc) · 1.09 KB
/
dispatch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const assert = require('assert')
const Event = require('./living/generated/Event')
const EventTarget = require('./living/generated/EventTarget')
const webidl = require('./living/generated/utils')
const noop = require('nop')
const { callback } = require('comeuppance')
// Getting started here. Existing API for `event-target-shim` works, but doesn't
// allow me to reset a user's handler if one exists. Wouldn't it be nice if
// `event-target-shim` returned an existing error handler if one exists?
async function dispatchEvent (transaction, eventTargetImpl, eventImpl) {
assert(arguments.length == 3)
webidl.tryWrapperForImpl(eventImpl)
if (transaction != null) {
transaction._state = 'active'
}
await callback(callback => eventTargetImpl._dispatch(eventImpl, false, true, true, callback))
if (transaction != null && transaction._state == 'active') {
transaction._state = 'inactive'
}
if (eventImpl._legacyOutputDidListenersThrowFlag) {
console.log('LEGACY OUTPUT DID LISTENERS THROW')
throw new Error
}
}
exports.dispatchEvent = dispatchEvent