On Tue, Oct 4, 2011 at 6:19 PM, David Bruant <[email protected]> wrote:

> **
> I sent a message here explaining the necessity of a syntax construct for a
> reliable bind [1]. There is a need to investingate (one reply was very close
> from a solution) to make sure that such a thing is not possible in pure ES5
> (without making Function.prototype.bind non-configurable), but that would be
> one such thing that no language compiling to JavaScript could emulate (since
> impossible in the language itself).
>

I don't think "security" from malicious changes to Function.prototype.bind
is a good argument for adding new operator syntax.

The problem doesn't stop with Function.prototype.bind. ES5 as a compilation
target is built on a quagmire since almost all fundamental language
operations are methods that can be changed. The operators are the exception,
since you can't override their meaning[1], and I can see why you wish to
introduce modification-safe operators for the operations you want to
preserve - but why is Function.prototype.bind more important than, say,
Math.pow? In the wrong hands, I'm sure you can subvert an encryption
algorithm with a malicious Math.pow. We can't have operators for all
functions, and you can't check every function before using it (and it
wouldn't help if you could).

Also, with proxies and getters/setters, even operators aren't guaranteed to
be safe unless they are defined extremely carefully. It used to be that
property access (o.foo) was a safe way to look up a property on an
object. Now it might trigger a proxy or accessor instead. This has actually
diluted the safety of operators. Will new operators that seem safe now be
diluted the same way in the future?

With ES5 getters and (inherited!) setters, you can install a "javascript
rootkit" that modifies some of the builtins, perhaps put some selected
getters/setters on Object.prototype, and hides every trace of it from other
scripts.
To prevent that kind of maliciousness, you need to go the way of SES and
lock down the entire environment *before* any untrusted code is touched, and
in that case Function.prototype.bind is just as safe as an operator.


(On the other hand, it's actually a fun experience to write Javascript code
that can't be affected by a modified environment - the same way three-legged
races are fun :)

Personally, I'd prefer all the built-in functions to be unconfigurable, so a
language user would actually know what function they are calling ahead of
time.

/L 'Freeze them! Freeze them all!'

[1] But the operators can potentially do type coercion that allows arbitrary
side-effects at unexpected times.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to