diff --git a/doc/api/errors.md b/doc/api/errors.md index 151a6bb5581fa1..01bd6676d89b91 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1990,6 +1990,11 @@ meaning of the error depends on the specific function. The `execArgv` option passed to the `Worker` constructor contains invalid flags. + +### `ERR_WORKER_OUT_OF_MEMORY` + +The `Worker` instance terminated because it reached its memory limit. + ### `ERR_WORKER_PATH` diff --git a/doc/api/worker_threads.md b/doc/api/worker_threads.md index 34fd6b7aa94736..e0eac312149c3d 100644 --- a/doc/api/worker_threads.md +++ b/doc/api/worker_threads.md @@ -157,6 +157,22 @@ console.log(receiveMessageOnPort(port2)); When this function is used, no `'message'` event will be emitted and the `onmessage` listener will not be invoked. +### `worker.resourceLimits` + + +* {Object|undefined} + * `maxYoungGenerationSizeMb` {number} + * `maxOldGenerationSizeMb` {number} + * `codeRangeSizeMb` {number} + +Provides the set of JS engine resource constraints inside this Worker thread. +If the `resourceLimits` option was passed to the [`Worker`][] constructor, +this matches its values. + +If this is used in the main thread, its value is an empty object. + ## `worker.SHARE_ENV` * `filename` {string} The path to the Worker’s main script. Must be either an absolute path or a relative path (i.e. relative to the @@ -519,6 +542,16 @@ if (isMainThread) { occur as described in the [HTML structured clone algorithm][], and an error will be thrown if the object cannot be cloned (e.g. because it contains `function`s). + * `resourceLimits` {Object} An optional set of resource limits for the new + JS engine instance. Reaching these limits will lead to termination of the + `Worker` instance. These limits only affect the JS engine, and no external + data, including no `ArrayBuffer`s. Even if these limits are set, the process + may still abort if it encounters a global out-of-memory situation. + * `maxOldGenerationSizeMb` {number} The maximum size of the main heap in MB. + * `maxYoungGenerationSizeMb` {number} The maximum size of a heap space for + recently created objects. + * `codeRangeSizeMb` {number} The size of a pre-allocated memory range + used for generated code. ### Event: `'error'` + +* {Object} + * `maxYoungGenerationSizeMb` {number} + * `maxOldGenerationSizeMb` {number} + * `codeRangeSizeMb` {number} + +Provides the set of JS engine resource constraints for this Worker thread. +If the `resourceLimits` option was passed to the [`Worker`][] constructor, +this matches its values. + +If the worker has stopped, the return value is an empty object. ### `worker.stderr`