forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmessageport.js
More file actions
31 lines (27 loc) · 726 Bytes
/
messageport.js
File metadata and controls
31 lines (27 loc) · 726 Bytes
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
30
31
'use strict';
const {
SymbolFor,
} = primordials;
class MessageEvent {
constructor(data, target, type) {
this.data = data;
this.target = target;
this.type = type;
}
}
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);
}
};