Open
Description
Node contains a lot of methods that are uncurry the value of this
in order to safely obtain functionality like [0, 1].slice()
that is not subject to prototype pollution. This proposal would effectively have a lexical way to perform the uncurryThis
usage of those primordials.
// instead of
const slice = Function.prototype.call.bind(Array.prototype.slice);
function copyArray(arr) {
return slice(arr); // changes ordering of syntax and diverges from common coding appearance of JS
}
// you could do
function copyArray(arr) {
return arr::slice();
}
CC: @ljharb
This wouldn't cover all the use cases but is potentially a solution to an ongoing problem Node is facing regarding maintainability of parts written in JS needing to be robust. I wonder if we could expand this proposal just a little to intercept protocols like Symbol.iterator
as well as that would greatly simplify parts of Node's internals and migrate towards something that looks like more idiomatic JS.
// currently
for (let x of y) { // unsafe due to prototype mutation or shadowing potentially in `y`
}
// something (bikeshed)
// this would basically need to shadow the properties used by protocol hooks to be the robust/safe/well known forms
for (let x of y::{Symbol.iterator: Array.prototype[Symbol.iterator]}) {
}
for (let x of y::{...Array.prototype}) {
}
Metadata
Metadata
Assignees
Labels
No labels