Skip to content

Motivation beyond defensiveness against mutation of globals? #8

@bakkot

Description

@bakkot

The readme gives as the sole motivation for this proposal the desire to be defensive against mutation of Function.prototype.

I don't find this motivation nearly compelling enough to justify new syntax. If you want to run in an untrusted environment already need to be saving any other prototype methods, as the readme notes, even given this syntax:

// Our own trusted code, running before any adversary.
const { slice } = Array.prototype;

Once you're doing that, the additional overhead of saving the various Function.prototype methods is negligible. That is, code which wants to be defensive can (and indeed generally does) already write

const { bind, call } = Function.prototype;
const uncurryThis = bind.bind(call);
const slice = uncurryThis(Array.prototype.slice);

// [...]

delete Array.prototype.slice;
delete Function.prototype.call;

// [...]

slice([0, 1, 2], 1, 2); // works fine

So it seems to me that this syntax does relatively little to improve this relatively obscure use case. As such, it doesn't seem to me to even approach the bar for adding new syntax, at least not on the strength of the motivations given in the readme. Are there other motivations?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions