| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -179,9 +179,13 @@ if (isMainThread) { | |||
| 179 | 179 | ## `worker.receiveMessageOnPort(port)` | |
| 180 | 180 | <!-- YAML | |
| 181 | 181 | added: v12.3.0 | |
| 182 | + changes: | ||
| 183 | + - version: REPLACEME | ||
| 184 | + pr-url: https://github.com/nodejs/node/pull/37535 | ||
| 185 | + description: The port argument can also refer to a `BroadcastChannel` now. | ||
| 182 | 186 | --> | |
| 183 | 187 | ||
| 184 | - * `port` {MessagePort} | ||
| 188 | + * `port` {MessagePort|BroadcastChannel} | ||
| 185 | 189 | ||
| 186 | 190 | * Returns: {Object|undefined} | |
| 187 | 191 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -333,7 +333,7 @@ function createWorkerStdio() { | |||
| 333 | 333 | } | |
| 334 | 334 | ||
| 335 | 335 | function receiveMessageOnPort(port) { | |
| 336 | - const message = receiveMessageOnPort_(port); | ||
| 336 | + const message = receiveMessageOnPort_(port?.[kHandle] ?? port); | ||
| 337 | 337 | if (message === noMessageSymbol) return undefined; | |
| 338 | 338 | return { message }; | |
| 339 | 339 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ const common = require('../common'); | |||
| 4 | 4 | const { | |
| 5 | 5 | BroadcastChannel, | |
| 6 | 6 | Worker, | |
| 7 | + receiveMessageOnPort | ||
| 7 | 8 | } = require('worker_threads'); | |
| 8 | 9 | const assert = require('assert'); | |
| 9 | 10 | ||
@@ -140,3 +141,13 @@ assert.throws(() => new BroadcastChannel(), { | |||
| 140 | 141 | message: /BroadcastChannel is closed/ | |
| 141 | 142 | }); | |
| 142 | 143 | } | |
| 144 | + | ||
| 145 | + { | ||
| 146 | + const bc1 = new BroadcastChannel('channel4'); | ||
| 147 | + const bc2 = new BroadcastChannel('channel4'); | ||
| 148 | + bc1.postMessage('some data'); | ||
| 149 | + assert.strictEqual(receiveMessageOnPort(bc2).message, 'some data'); | ||
| 150 | + assert.strictEqual(receiveMessageOnPort(bc2), undefined); | ||
| 151 | + bc1.close(); | ||
| 152 | + bc2.close(); | ||
| 153 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments