ChakraCore icon indicating copy to clipboard operation
ChakraCore copied to clipboard

LHS should be evaluated first in the assignment.

Open akroshg opened this issue 10 years ago • 6 comments

(function() {
    var x = 1;
    (function() {
        x = (eval('var x = 20'), 2);
        console.log(x == 20); // this should be true
    })();
    console.log(x == 2); // this should be true
})();

Both should print true. (Edge/Chrome don't but Firefox does) see https://tc39.github.io/ecma262/#sec-assignment-operators-runtime-semantics-evaluation

akroshg avatar Oct 14 '16 17:10 akroshg

So the issue is the fact that we let the eval side-effect change the binding of the LHS of the =? Yeah, this has been around since IE9, and to this point we’ve chosen not to fix it, because of Chrome interop, the fact that the issue surfaces very rarely in RWC, and the difficulty of changing our infrastructure to deal with this kind of case.

-- Paul

From: Akrosh Gandhi [mailto:[email protected]] Sent: Friday, October 14, 2016 10:09 AM To: Microsoft/ChakraCore [email protected] Subject: [Microsoft/ChakraCore] LHS should be evaluated first in the assignment. (#1745)

(function() {

var x = 1;

(function() {

    x = (eval('var x = 20'), 2);

    console.log(x == 20); // this should be true

})();

console.log(x == 2); // this should be true

})();

Both should print true. (Edge/Chrome don't but Firefox does) see https://tc39.github.io/ecma262/#sec-assignment-operators-runtime-semantics-evaluationhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Ftc39.github.io%2Fecma262%2F%23sec-assignment-operators-runtime-semantics-evaluation&data=01%7C01%7Cpleath%40microsoft.com%7Cffbd57c39ce24ab43d3208d3f454c0d6%7C72f988bf86f141af91ab2d7cd011db47%7C1&sdata=DLaEj624LgTm5lHP9fQTqx7DI8IQ2SdtBnX6O1lZUzw%3D&reserved=0

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMicrosoft%2FChakraCore%2Fissues%2F1745&data=01%7C01%7Cpleath%40microsoft.com%7Cffbd57c39ce24ab43d3208d3f454c0d6%7C72f988bf86f141af91ab2d7cd011db47%7C1&sdata=p61akBdUPUdcslbOlbJKkchAjGA1LpbKEC1Anuo0Xd8%3D&reserved=0, or mute the threadhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAPF8RKTqOuZvP95c-TP4hucj_lOO3Zcoks5qz7cagaJpZM4KXO9J&data=01%7C01%7Cpleath%40microsoft.com%7Cffbd57c39ce24ab43d3208d3f454c0d6%7C72f988bf86f141af91ab2d7cd011db47%7C1&sdata=oDigYpVI%2BZleJMoQbZLQ0hVDBZ%2BjOmdR83lThmC4%2Fu0%3D&reserved=0.

pleath avatar Oct 14 '16 17:10 pleath

@bterlson is this something that should be clarified/updated in the spec, or should we think about implementing the correct behavior?

dilijev avatar Oct 17 '16 21:10 dilijev

I tried previously and could not get consensus. We should fix it. It was apparently easy for SM.

bterlson avatar Oct 17 '16 21:10 bterlson

Should note that our implementation is significantly harder. Only pointing out that SM has now fixed this issue.

bterlson avatar Oct 17 '16 22:10 bterlson

Has been in the product for a long time. Impact not large but effort to fix is. Not a 1.4.1 candidate

EdMaurer avatar Dec 27 '16 22:12 EdMaurer

Still the case that this is Chrome interop.

## Source
(function() {
    var x = 1;
    (function() {
        x = (eval('var x = 20'), 2);
        print(x == 20); // this should be true
    })();
    print(x == 2); // this should be true
})();

┌──────────┬───────┐
│ jsvu-ch  │ false │
│ jsvu-v8  │ false │
├──────────┼───────┤
│ jsvu-jsc │ true  │
│ jsvu-sm  │ true  │
└──────────┴───────┘

dilijev avatar Jun 06 '18 23:06 dilijev