/
githubmirror
/
node
Обзор
Документация
Войти
/
githubmirror
/
node
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
lib/internal/per_context/messageport.js
39 строк
995 B
Anna Henningsen
worker: add ports property to MessageEvents
04 мар 2021, 01:23
Не верифицирован
04 мар 2021, 01:23
007a85c
Код
Авторство
О чём код?
'use strict'; const { SymbolFor, } = primordials; class MessageEvent { constructor(data, target, type, ports) { this.data = data; this.target = target; this.type = type; this.ports = ports ?? []; } } const kHybridDispatch = SymbolFor('nodejs.internal.kHybridDispatch'); const kCurrentlyReceivingPorts = SymbolFor('nodejs.internal.kCurrentlyReceivingPorts'); exports.emitMessage = function(data, ports, type) { if (typeof this[kHybridDispatch] === 'function') { this[kCurrentlyReceivingPorts] = ports; try { this[kHybridDispatch](data, type, undefined); } finally { this[kCurrentlyReceivingPorts] = undefined; } return; } const event = new MessageEvent(data, this, type, ports); 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); } };