Add support for function argument initializers. (#2571)
EcmaScript 2015 14.1. Note: arrow functions with default arguments are not supported yet. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
committed by
László Langó
parent
aeddb1cd88
commit
83fc0aa04f
@@ -0,0 +1,81 @@
|
||||
// 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.
|
||||
|
||||
var local = 0;
|
||||
|
||||
switch(0) { /* This switch forces a pre-scanner run. */
|
||||
default:
|
||||
|
||||
function f(a = (5, local = 6),
|
||||
b = ((5 + function(a = 6) { return a }() * 3)),
|
||||
c,
|
||||
d = true ? 1 : 2)
|
||||
{
|
||||
return "" + a + ", " + b + ", " + c + ", " + d;
|
||||
}
|
||||
|
||||
assert(f() === "6, 23, undefined, 1");
|
||||
assert(local === 6);
|
||||
|
||||
var obj = {
|
||||
f: function(a = [10,,20],
|
||||
b,
|
||||
c = Math.cos(0),
|
||||
d)
|
||||
{
|
||||
return "" + a + ", " + b + ", " + c + ", " + d;
|
||||
}
|
||||
};
|
||||
|
||||
assert(obj.f() === "10,,20, undefined, 1, undefined");
|
||||
|
||||
function g(a, b = (local = 7)) { }
|
||||
|
||||
local = 0;
|
||||
g();
|
||||
assert(local === 7);
|
||||
|
||||
local = 0;
|
||||
g(0);
|
||||
assert(local === 7);
|
||||
|
||||
local = 0;
|
||||
g(0, undefined);
|
||||
assert(local === 7);
|
||||
|
||||
local = 0;
|
||||
g(0, null);
|
||||
assert(local === 0);
|
||||
|
||||
local = 0;
|
||||
g(0, false);
|
||||
assert(local === 0);
|
||||
break;
|
||||
}
|
||||
|
||||
function CheckSyntaxError(str)
|
||||
{
|
||||
try {
|
||||
eval(str);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof SyntaxError);
|
||||
}
|
||||
}
|
||||
|
||||
CheckSyntaxError('function x(a += 5) {}');
|
||||
CheckSyntaxError('function x(a =, b) {}');
|
||||
CheckSyntaxError('function x(a = (b) {}');
|
||||
CheckSyntaxError('function x(a, a = 5) {}');
|
||||
CheckSyntaxError('function x(a = 5, a) {}');
|
||||
Reference in New Issue
Block a user