Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ if (isMainThread) {
process.chdir = workerThreadSetup.unavailable('process.chdir()');
process.umask = wrapped.umask;
process.cwd = rawMethods.cwd;

process._debugEnd = rawMethods._debugEnd;
}

// Set up methods on the process object for all threads
Expand Down
2 changes: 1 addition & 1 deletion src/node_process_methods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,12 @@ static void InitializeProcessMethods(Local<Object> target,
// define various internal methods
if (env->owns_process_state()) {
env->SetMethod(target, "_debugProcess", DebugProcess);
env->SetMethod(target, "_debugEnd", DebugEnd);
env->SetMethod(target, "abort", Abort);
env->SetMethod(target, "causeSegfault", CauseSegfault);
env->SetMethod(target, "chdir", Chdir);
}

env->SetMethod(target, "_debugEnd", DebugEnd);
env->SetMethod(
target, "_startProfilerIdleNotifier", StartProfilerIdleNotifier);
env->SetMethod(target, "_stopProfilerIdleNotifier", StopProfilerIdleNotifier);
Expand Down
60 changes: 60 additions & 0 deletions test/parallel/test-worker-inspector-open.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict';

const common = require('../common');
const assert = require('assert');

common.skipIfInspectorDisabled();

const net = require('net');
const { Worker, isMainThread, parentPort } = require('worker_threads');
const inspector = require('inspector');
const url = require('url');

// This test ensures that inspector.open(), inspector.close(), inspector.url()
// work inside Worker.
function ping(port, callback) {
net.connect(port)
.on('connect', function() { close(this); })
.on('error', function(err) { close(this, err); });

function close(self, err) {
self.end();
self.on('close', () => callback(err));
}
}

function runMainThread() {
const worker = new Worker(__filename);

worker.on('message', common.mustCall(({ ws }) => {
ping(url.parse(ws).port, common.mustCall((err) => {
assert.ifError(err);
worker.postMessage({ done: true });
}));
}));
}

function runChildWorkerThread() {
inspector.open(0);
assert(inspector.url());
inspector.close();
assert(!inspector.url());

inspector.open(0);

parentPort.on('message', common.mustCall(({ done }) => {
if (done) {
parentPort.close();
}
}));

parentPort.postMessage({
ws: inspector.url()
});
}

if (isMainThread) {
runMainThread();
} else {
runChildWorkerThread();
}
1 change: 0 additions & 1 deletion test/parallel/test-worker-unsupported-things.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ if (!process.env.HAS_STARTED_WORKER) {
assert.strictEqual('_stopProfilerIdleNotifier' in process, false);
assert.strictEqual('_debugProcess' in process, false);
assert.strictEqual('_debugPause' in process, false);
assert.strictEqual('_debugEnd' in process, false);

parentPort.postMessage(true);
}