Skip to content

Commit 5abd452

Browse files
committed
src: return a number from process.constrainedMemory() constantly
`0` is already a special value returned from `uv_get_constrained_memory` representing unknown or no constraint. Make `process.constrainedMemory()` constantly return a number instead to avoid polymorphic return type.
1 parent 1f19316 commit 5abd452

3 files changed

Lines changed: 9 additions & 13 deletions

File tree

doc/api/process.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,15 +1114,19 @@ over the IPC channel using `process.send()`.
11141114
added:
11151115
- v19.6.0
11161116
- v18.15.0
1117+
changes:
1118+
- version: REPLACEME
1119+
pr-url: https://github.com/nodejs/node/pull/XX
1120+
description: Aligned return value with `uv_get_constrained_memory`.
11171121
-->
11181122

11191123
> Stability: 1 - Experimental
11201124
1121-
* {number|undefined}
1125+
* {number}
11221126

11231127
Gets the amount of memory available to the process (in bytes) based on
11241128
limits imposed by the OS. If there is no such constraint, or the constraint
1125-
is unknown, `undefined` is returned.
1129+
is unknown, `0` is returned.
11261130

11271131
See [`uv_get_constrained_memory`][uv_get_constrained_memory] for more
11281132
information.

src/node_process_methods.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,7 @@ static void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
211211

212212
static void GetConstrainedMemory(const FunctionCallbackInfo<Value>& args) {
213213
uint64_t value = uv_get_constrained_memory();
214-
if (value != 0) {
215-
args.GetReturnValue().Set(static_cast<double>(value));
216-
}
214+
args.GetReturnValue().Set(static_cast<double>(value));
217215
}
218216

219217
void RawDebug(const FunctionCallbackInfo<Value>& args) {
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
'use strict';
22
require('../common');
33
const assert = require('assert');
4-
const { Worker } = require('worker_threads');
4+
55
const constrainedMemory = process.constrainedMemory();
6-
if (constrainedMemory !== undefined) {
7-
assert(constrainedMemory > 0);
8-
}
9-
if (!process.env.isWorker) {
10-
process.env.isWorker = true;
11-
new Worker(__filename);
12-
}
6+
assert.strictEqual(typeof constrainedMemory, 'number');

0 commit comments

Comments
 (0)