Support comma after last argument for function declarations (#3910)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2020-06-24 10:41:03 +02:00
committed by GitHub
parent e64fc9aca9
commit 5d8c5f3e92
5 changed files with 146 additions and 66 deletions
-2
View File
@@ -138,10 +138,8 @@ must_throw ("var x => x;");
must_throw ("(()) => 0");
must_throw ("((x)) => 0");
must_throw ("(((x))) => 0");
must_throw ("(x,) => 0");
must_throw ("(x==6) => 0");
must_throw ("(x y) => 0");
must_throw ("(x,y,) => 0");
must_throw ("x\n => 0");
must_throw ("this => 0");
must_throw ("(true) => 0");
+48
View File
@@ -0,0 +1,48 @@
// Copyright JS Foundation and other contributors, http://js.foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
function check_syntax_error (code)
{
try {
eval (code)
assert (false)
} catch (e) {
assert (e instanceof SyntaxError)
}
}
check_syntax_error ("function f(,) {}")
check_syntax_error ("function f(...a,) {}")
check_syntax_error ("function f(a = 1 + 1,,) {}")
check_syntax_error ("function f(a,,b) {}")
check_syntax_error ("function f(,a) {}")
function f1(a,) {}
assert(f1.length === 1)
function f2(a = 1,) {}
assert(f2.length === 1)
function f3(a = 1, b = 1 + 1, c,) {}
assert(f3.length === 3)
var f4 = async(a,) => {}
assert(f4.length === 1)
var f5 = async(a = 1,) => {}
assert(f5.length === 1)
assert(((a = 1, b = 1 + 1, c,) => {}).length === 3)
assert(((a = 1, b, c = 1 + 1,) => {}).length === 3)