Skip to content
Open
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
8 changes: 6 additions & 2 deletions lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ function setPriority(pid, priority) {

const ctx = {};

if (_setPriority(pid, priority, ctx) !== 0)
// V8 does not report -0 as an int32, so coerce it to 0 before it reaches
// the binding.
if (_setPriority(pid | 0, priority | 0, ctx) !== 0)
throw new ERR_SYSTEM_ERROR(ctx);
}

Expand All @@ -275,7 +277,9 @@ function getPriority(pid) {
validateInt32(pid, 'pid');

const ctx = {};
const priority = _getPriority(pid, ctx);
// V8 does not report -0 as an int32, so coerce it to 0 before it reaches
// the binding.
const priority = _getPriority(pid | 0, ctx);

if (priority === undefined)
throw new ERR_SYSTEM_ERROR(ctx);
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-os-negative-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

require('../common');

const assert = require('assert');
const os = require('os');

// -0 passes the int32 validation, so it must be accepted like 0 instead of
// aborting the process in the binding.
assert.strictEqual(os.getPriority(-0), os.getPriority(0));

os.setPriority(-0, os.getPriority());

// Setting the priority to 0 may need more privileges than the process has,
// which is reported as a system error rather than an abort.
for (const args of [[0, -0], [-0, -0], [-0]]) {
try {
os.setPriority(...args);
} catch (err) {
assert.strictEqual(err.code, 'ERR_SYSTEM_ERROR');
assert.strictEqual(err.info.code, 'EACCES');
}
}
Loading