Spread operator should be allowed when not the first argument of parameter list
https://bugs.webkit.org/show_bug.cgi?id=152721
Reviewed by Saam Barati.
Source/JavaScriptCore:
Spread arguments to functions should now be ES6 compliant. Before we
would only take a spread operator if it was the sole argument to a
function. Additionally, we would not use the Symbol.iterator on the
object to generate the arguments. Instead we would do a loop up to the
length mapping indexed properties to the corresponding argument. We fix
both these issues by doing an AST transformation from foo(...a, b, ...c, d)
to foo(...[...a, b, ...c, d]) (where the spread on the rhs uses the
old spread semantics). This solution has the downside of requiring the
allocation of another object and copying each element twice but avoids a
large change to the vm calling convention.
- interpreter/Interpreter.cpp:
(JSC::loadVarargs):
(JSC::ASTBuilder::createElementList):
(JSC::Parser<LexerType>::parseArguments):
(JSC::Parser<LexerType>::parseArgument):
(JSC::Parser<LexerType>::parseMemberExpression):
- parser/Parser.h:
- parser/SyntaxChecker.h:
(JSC::SyntaxChecker::createElementList):
- tests/es6.yaml:
- tests/stress/spread-calling.js: Added.
(testFunction):
(testEmpty):
(makeObject):
(otherIterator.return.next):
(otherIterator):
(totalIter):
(throwingIter.return.next):
(throwingIter):
(i.catch):
LayoutTests:
Update tests with new semantics of spread calling. Additionally,
adjust benchmarks to run in a more reasonable time now that
spread is implemented correctly.
- js/basic-spread-expected.txt:
- js/parser-syntax-check-expected.txt:
- js/regress/script-tests/deltablue-varargs.js:
(deltaBlue):
- js/regress/script-tests/varargs-construct.js:
- js/script-tests/basic-spread.js:
- js/script-tests/parser-syntax-check.js: