GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: increase coverage for worker_threads · nodejs/node@70ccec2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-worker-onmessage-not-a-function.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/parallel/test-worker-onmessage-not-a-function.js‎

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// When MessagePort.onmessage is set to a value that is not a function, the
2+
// setter should call .unref() and .stop(), clearing a previous onmessage
3+
// listener from holding the event loop open. This test confirms that
4+
// functionality.
5+
6+
// Flags: --experimental-worker
7+
'use strict';
8+
const common = require('../common');
9+
const { Worker, parentPort } = require('worker_threads');
10+
11+
// Do not use isMainThread so that this test itself can be run inside a Worker.
12+
if (!process.env.HAS_STARTED_WORKER) {
13+
process.env.HAS_STARTED_WORKER = 1;
14+
const w = new Worker(__filename);
15+
w.postMessage(2);
16+
} else {
17+
// .onmessage uses a setter. Set .onmessage to a function that ultimately
18+
// should not be called. This will call .ref() and .start() which will keep
19+
// the event loop open (and prevent this from exiting) if the subsequent
20+
// assignment of a value to .onmessage doesn't call .unref() and .stop().
21+
parentPort.onmessage = common.mustNotCall();
22+
// Setting `onmessage` to a value that is not a function should clear the
23+
// previous value and also should allow the event loop to exit. (In other
24+
// words, this test should exit rather than run indefinitely.)
25+
parentPort.onmessage = 'fhqwhgads';
26+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.