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.

PR-URL: https://github.com/nodejs/node/pull/52039
Reviewed-By: theanarkh <theratliter@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
This commit is contained in:
Chengzhong Wu authored and Chengzhong Wu committed 2024-03-15 00:27:33 +08:00
1 parent 20525f14b9
commit 0eb2b727f6
3 files changed
+9 -13

No files matched your search

+6 -2
View File
@@ -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.
+1 -3
View File
@@ -211,9 +211,7 @@ static void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
static void GetConstrainedMemory(const FunctionCallbackInfo<Value>& args) {
uint64_t value = uv_get_constrained_memory();
if (value != 0) {
args.GetReturnValue().Set(static_cast<double>(value));
}
args.GetReturnValue().Set(static_cast<double>(value));
}
static void GetAvailableMemory(const FunctionCallbackInfo<Value>& args) {
@@ -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');