diff --git a/doc/api/process.md b/doc/api/process.md index b0cbebcc148de8..ba0891a66a9652 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -1114,15 +1114,19 @@ over the IPC channel using `process.send()`. added: - v19.6.0 - v18.15.0 +changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/52039 + description: Aligned return value with `uv_get_constrained_memory`. --> > Stability: 1 - Experimental -* {number|undefined} +* {number} Gets the amount of memory available to the process (in bytes) based on limits imposed by the OS. If there is no such constraint, or the constraint -is unknown, `undefined` is returned. +is unknown, `0` is returned. See [`uv_get_constrained_memory`][uv_get_constrained_memory] for more information. diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index b7e68dc1d5d074..5266aae51f677b 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -211,9 +211,7 @@ static void MemoryUsage(const FunctionCallbackInfo& args) { static void GetConstrainedMemory(const FunctionCallbackInfo& args) { uint64_t value = uv_get_constrained_memory(); - if (value != 0) { - args.GetReturnValue().Set(static_cast(value)); - } + args.GetReturnValue().Set(static_cast(value)); } static void GetAvailableMemory(const FunctionCallbackInfo& args) { diff --git a/test/parallel/test-process-constrained-memory.js b/test/parallel/test-process-constrained-memory.js index 2bd94a6749e56b..03f99b166f72ca 100644 --- a/test/parallel/test-process-constrained-memory.js +++ b/test/parallel/test-process-constrained-memory.js @@ -1,12 +1,6 @@ 'use strict'; require('../common'); const assert = require('assert'); -const { Worker } = require('worker_threads'); + const constrainedMemory = process.constrainedMemory(); -if (constrainedMemory !== undefined) { - assert(constrainedMemory > 0); -} -if (!process.env.isWorker) { - process.env.isWorker = true; - new Worker(__filename); -} +assert.strictEqual(typeof constrainedMemory, 'number');