mozilla / rhino

Rhino is an open-source implementation of JavaScript written entirely in Java
https://rhino.github.io
Other
4.13k stars 847 forks source link

Duplicate formal argument should be banned in strict mode #576

Open YaoHouyou opened 5 years ago

YaoHouyou commented 5 years ago

According to ECMA-262 6th edition, early errors ensure that duplicate parameter names can only occur in non-strict functions [reference]. Rhino does not throw any error in strict mode while others engines throw a syntaxError, such as v8, spiderMonkey, javascriptCore and chakra.

Version: rhino-1.7.11, rhino-1.7.10, rhino-1.7.9

Testcase:

function func() {
        function foo(param, param) {
                'use strict';
        }
        foo(2,3);
}
func();

Command:

java -jar rhino/rhino-1.7.11.jar -debug -version 200 testcase.js
ty5491003 commented 5 years ago

@gbrail Can you explain this issue plz? Is this a bug or a implementation property? thx.

gbrail commented 5 years ago

I get the desired error if I do one of a few things:

1) Add the "-strict" command-line flag 2) Add 'use strict'; as the first line of the script, before the function is declared. 3) Add 'use strict' right before the declaration of "foo".

It may take some spec-sleuthing to know whether this particular example should fail. If it's supposed to fail unmodified, then somewhere Rhino may not be applying "use strict" at the correct scope, and in that case it's something that Rhino should fix.

YaoHouyou commented 5 years ago

@gbrail If I read the ECMAScript-262 standard correctly, the strict function code scope of rhino is not meet ES5.1 and ES6, and Rhrino should be fixed.

NWU-NISL commented 3 years ago

I get the desired error if I do one of a few things:

  1. Add the "-strict" command-line flag
  2. Add 'use strict'; as the first line of the script, before the function is declared.
  3. Add 'use strict' right before the declaration of "foo".

It may take some spec-sleuthing to know whether this particular example should fail. If it's supposed to fail unmodified, then somewhere Rhino may not be applying "use strict" at the correct scope, and in that case it's something that Rhino should fix.

Hi, @gbrail, I tested Rhino-1.7.11 and Rhino-1.7.12 according to your three suggestions. The error was not reproduced according to 2th and 3th recommendations. The test cases are as following:

Testcase1

function func() {
    'use strict';
    function foo(param, param) {
    }
    foo(2,3);
}
func();

Testcase2

'use` strict';
function func() {
    function foo(param, param) {
    }
    foo(2,3);
}
func();