Skip to content

Commit db2665b

Browse files
Renegade334aduh95
authored andcommitted
doc: add indexed Array.prototype properties to primordial exclusions
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk> PR-URL: #66234 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent f7d3d11 commit db2665b

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

‎doc/contributing/primordials.md‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ There are some built-in functions that accept a variable number of arguments
105105
the list of arguments as an array. You can use primordial function with the
106106
suffix `Apply` (e.g.: `MathMaxApply`, `ArrayPrototypePushApply`) to do that.
107107

108-
## Primordials with known performance issues
108+
## Limitations and exclusions
109+
110+
### Primordials with known performance issues
109111

110112
One of the reasons why the current Node.js API is not completely tamper-proof is
111113
performance: sometimes the use of primordials can cause performance regressions
@@ -137,6 +139,32 @@ performance of code in Node.js.
137139
In general, when sending or reviewing a PR that makes changes in a hot code
138140
path, use extra caution and run extensive benchmarks.
139141

142+
### User-defined index properties on `Array.prototype`
143+
144+
A recurring theme in issues/PRs is that changing the behavior of indexed
145+
array properties via `Array.prototype` breaks a particular Node.js API.
146+
147+
<!-- eslint-disable accessor-pairs -->
148+
149+
```js
150+
// User-land
151+
Object.defineProperty(
152+
Array.prototype,
153+
'0',
154+
{ set() {} },
155+
);
156+
157+
// Core
158+
const array = [];
159+
ArrayPrototypePush(array, 'some value');
160+
console.log(array[0]); // undefined
161+
```
162+
163+
These patterns are expected to break both ECMAScript builtins and application
164+
code, and Node.js does not make any attempt to harden against them. To do so
165+
would necessitate using property descriptor methods for every single array
166+
interaction, which is not practical.
167+
140168
## Implicit use of user-mutable methods
141169

142170
### Unsafe array iteration

0 commit comments

Comments
 (0)