From 4c1fd1a111f03091cd3b8a2d7f95b31f314254c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Fri, 25 Sep 2026 11:23:35 +0100 Subject: [PATCH] doc: add indexed `Array.prototype` properties to primordial exclusions Signed-off-by: Renegade334 PR-URL: https://github.com/nodejs/node/pull/66234 Reviewed-By: Antoine du Hamel Reviewed-By: Filip Skokan Reviewed-By: Marco Ippolito Reviewed-By: Luigi Pinca --- doc/contributing/primordials.md | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/doc/contributing/primordials.md b/doc/contributing/primordials.md index 4b143c485ff..ec64e028197 100644 --- a/doc/contributing/primordials.md +++ b/doc/contributing/primordials.md @@ -105,7 +105,9 @@ There are some built-in functions that accept a variable number of arguments the list of arguments as an array. You can use primordial function with the suffix `Apply` (e.g.: `MathMaxApply`, `ArrayPrototypePushApply`) to do that. -## Primordials with known performance issues +## Limitations and exclusions + +### Primordials with known performance issues One of the reasons why the current Node.js API is not completely tamper-proof is performance: sometimes the use of primordials can cause performance regressions @@ -137,6 +139,32 @@ performance of code in Node.js. In general, when sending or reviewing a PR that makes changes in a hot code path, use extra caution and run extensive benchmarks. +### User-defined index properties on `Array.prototype` + +A recurring theme in issues/PRs is that changing the behavior of indexed +array properties via `Array.prototype` breaks a particular Node.js API. + + + +```js +// User-land +Object.defineProperty( + Array.prototype, + '0', + { set() {} }, +); + +// Core +const array = []; +ArrayPrototypePush(array, 'some value'); +console.log(array[0]); // undefined +``` + +These patterns are expected to break both ECMAScript builtins and application +code, and Node.js does not make any attempt to harden against them. To do so +would necessitate using property descriptor methods for every single array +interaction, which is not practical. + ## Implicit use of user-mutable methods ### Unsafe array iteration