-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worker: make MessagePort inherit from EventTarget
Use `NodeEventTarget` to provide a mixed `EventEmitter`/`EventTarget` API interface. PR-URL: #34057 Refs: https://twitter.com/addaleax/status/1276289101671608320 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
- Loading branch information
Showing
9 changed files
with
126 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,31 @@ | ||
'use strict'; | ||
const { | ||
SymbolFor, | ||
} = primordials; | ||
|
||
class MessageEvent { | ||
constructor(data, target) { | ||
constructor(data, target, type) { | ||
this.data = data; | ||
this.target = target; | ||
this.type = type; | ||
} | ||
} | ||
|
||
exports.emitMessage = function(data) { | ||
if (typeof this.onmessage === 'function') | ||
this.onmessage(new MessageEvent(data, this)); | ||
const kHybridDispatch = SymbolFor('nodejs.internal.kHybridDispatch'); | ||
|
||
exports.emitMessage = function(data, type) { | ||
if (typeof this[kHybridDispatch] === 'function') { | ||
this[kHybridDispatch](data, type, undefined); | ||
return; | ||
} | ||
|
||
const event = new MessageEvent(data, this, type); | ||
if (type === 'message') { | ||
if (typeof this.onmessage === 'function') | ||
this.onmessage(event); | ||
} else { | ||
// eslint-disable-next-line no-lonely-if | ||
if (typeof this.onmessageerror === 'function') | ||
this.onmessageerror(event); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters