Banning assignment to a function call

# Jason Orendorff (12 years ago)

The program

if (0) Math.sin(0) = 1;
alert("OK");

is permitted in all the major browsers. This was explicitly optional in ES1-5, but dropped from ES6:

rwldrn/tc39-notes/blob/master/es6/2012-11/nov-29.md#eliminate-functions-returning-reference-values-from-the-specification

And good riddance, if we really think implementations can drop support for this cursed-legacy syntax. I'm willing to experiment with making this an early ReferenceError in Firefox. But if anyone has tried and run into Web compatibility issues, please speak up and save me some wasted effort!

Thanks,

# Brendan Eich (12 years ago)

I blame VBScript (really, scotti@ microsoft).

But I recall a couple of years ago, Maciej said JSC had to allow exactly such cursed-legacy content. Perhaps the content no longer exists, but if it does, we might not find out until Firefox Beta or Final release. That may be worthwhile, or not.

Cc'ing Oliver and Maciej in case they have a link or fresh data.

# Oliver Hunt (12 years ago)

I would be pro-killing this particular misfeature. I know we have tests that verify that we accept the syntax, but i'm not sure if there's still real content the depends on it.

Does strict mode disallow it? IIRC strict mode has a blanket ban on non-reference lhs in assignment expressions but I don't have the spec handy.

# Allen Wirfs-Brock (12 years ago)

On Jun 19, 2013, at 9:14 AM, Oliver Hunt wrote:

I would be pro-killing this particular misfeature. I know we have tests that verify that we accept the syntax, but i'm not sure if there's still real content the depends on it.

Does strict mode disallow it? IIRC strict mode has a blanket ban on non-reference lhs in assignment expressions but I don't have the spec handy.

No, not in ES5/5.1. ES5 allows an early error for an assignment to that can be statically determined to be to a non-reference. However, it also allows host functions to return references). So presumably a call on the the LHS must be accepted in ES5/5.1 even though it will likely produce a runtime Reference error.

In the ES6 spec. no function call is allowed to return a reference and so a call on the LHS would be an early Reference error.