Skip to content

Commit 5071a97

Browse files
gskachkovwebkit-commit-queue
authored andcommitted
[ES6] Arrow function syntax. Emit loading&putting this/super only if they are used in arrow function
https://bugs.webkit.org/show_bug.cgi?id=153981 Patch by Skachkov Oleksandr <gskachkov@gmail.com> on 2016-02-24 Reviewed by Saam Barati. Source/JavaScriptCore: In first iteration of implemenation arrow function, we emit load and store variables 'this', 'arguments', 'super', 'new.target' in case if arrow function is exist even variables are not used in arrow function. Current patch added logic that prevent from emiting those varibles if they are not used in arrow function. During syntax analyze parser store information about using variables in arrow function inside of the ordinary function scope and then put to BytecodeGenerator through UnlinkedCodeBlock * bytecode/ExecutableInfo.h: (JSC::ExecutableInfo::ExecutableInfo): (JSC::ExecutableInfo::arrowFunctionCodeFeatures): * bytecode/UnlinkedCodeBlock.cpp: (JSC::UnlinkedCodeBlock::UnlinkedCodeBlock): * bytecode/UnlinkedCodeBlock.h: (JSC::UnlinkedCodeBlock::arrowFunctionCodeFeatures): (JSC::UnlinkedCodeBlock::doAnyInnerArrowFunctionsUseArguments): (JSC::UnlinkedCodeBlock::doAnyInnerArrowFunctionsUseSuperCall): (JSC::UnlinkedCodeBlock::doAnyInnerArrowFunctionsUseSuperProperty): (JSC::UnlinkedCodeBlock::doAnyInnerArrowFunctionsUseEval): (JSC::UnlinkedCodeBlock::doAnyInnerArrowFunctionsUseThis): (JSC::UnlinkedCodeBlock::doAnyInnerArrowFunctionsUseNewTarget): * bytecode/UnlinkedFunctionExecutable.cpp: (JSC::generateUnlinkedFunctionCodeBlock): (JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable): * bytecode/UnlinkedFunctionExecutable.h: * bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::BytecodeGenerator): (JSC::BytecodeGenerator::initializeArrowFunctionContextScopeIfNeeded): (JSC::BytecodeGenerator::emitLoadArrowFunctionLexicalEnvironment): (JSC::BytecodeGenerator::emitLoadThisFromArrowFunctionLexicalEnvironment): (JSC::BytecodeGenerator::emitLoadNewTargetFromArrowFunctionLexicalEnvironment): (JSC::BytecodeGenerator::emitLoadDerivedConstructorFromArrowFunctionLexicalEnvironment): (JSC::BytecodeGenerator::isThisUsedInInnerArrowFunction): (JSC::BytecodeGenerator::isArgumentsUsedInInnerArrowFunction): (JSC::BytecodeGenerator::isNewTargetUsedInInnerArrowFunction): (JSC::BytecodeGenerator::isSuperUsedInInnerArrowFunction): (JSC::BytecodeGenerator::emitPutNewTargetToArrowFunctionContextScope): (JSC::BytecodeGenerator::emitPutDerivedConstructorToArrowFunctionContextScope): (JSC::BytecodeGenerator::emitPutThisToArrowFunctionContextScope): * bytecompiler/BytecodeGenerator.h: * bytecompiler/NodesCodegen.cpp: (JSC::ThisNode::emitBytecode): (JSC::EvalFunctionCallNode::emitBytecode): (JSC::FunctionCallValueNode::emitBytecode): (JSC::FunctionNode::emitBytecode): * parser/ASTBuilder.h: (JSC::ASTBuilder::createFunctionMetadata): * parser/Nodes.cpp: (JSC::FunctionMetadataNode::FunctionMetadataNode): * parser/Nodes.h: * parser/Parser.cpp: (JSC::Parser<LexerType>::parseGeneratorFunctionSourceElements): (JSC::Parser<LexerType>::parseFunctionBody): (JSC::Parser<LexerType>::parseFunctionInfo): (JSC::Parser<LexerType>::parseProperty): (JSC::Parser<LexerType>::parsePrimaryExpression): (JSC::Parser<LexerType>::parseMemberExpression): * parser/Parser.h: (JSC::Scope::Scope): (JSC::Scope::isArrowFunctionBoundary): (JSC::Scope::innerArrowFunctionFeatures): (JSC::Scope::setInnerArrowFunctionUseSuperCall): (JSC::Scope::setInnerArrowFunctionUseSuperProperty): (JSC::Scope::setInnerArrowFunctionUseEval): (JSC::Scope::setInnerArrowFunctionUseThis): (JSC::Scope::setInnerArrowFunctionUseNewTarget): (JSC::Scope::setInnerArrowFunctionUseArguments): (JSC::Scope::setInnerArrowFunctionUseEvalAndUseArgumentsIfNeeded): (JSC::Scope::collectFreeVariables): (JSC::Scope::mergeInnerArrowFunctionFeatures): (JSC::Scope::fillParametersForSourceProviderCache): (JSC::Scope::restoreFromSourceProviderCache): (JSC::Scope::setIsFunction): (JSC::Scope::setIsArrowFunction): (JSC::Parser::closestParentNonArrowFunctionNonLexicalScope): (JSC::Parser::pushScope): (JSC::Parser::popScopeInternal): * parser/ParserModes.h: * parser/SourceProviderCacheItem.h: (JSC::SourceProviderCacheItem::SourceProviderCacheItem): * parser/SyntaxChecker.h: (JSC::SyntaxChecker::createFunctionMetadata): * tests/stress/arrowfunction-lexical-bind-arguments-non-strict-1.js: * tests/stress/arrowfunction-lexical-bind-arguments-strict.js: * tests/stress/arrowfunction-lexical-bind-newtarget.js: * tests/stress/arrowfunction-lexical-bind-superproperty.js: * tests/stress/arrowfunction-lexical-bind-this-8.js: Added. LayoutTests: Added new benchmark tests for invoking arrow function within function, class's constructor and method * js/regress/arrowfunction-call-in-class-constructor-expected.txt: Added. * js/regress/arrowfunction-call-in-class-constructor.html: Added. * js/regress/arrowfunction-call-in-class-method-expected.txt: Added. * js/regress/arrowfunction-call-in-class-method.html: Added. * js/regress/arrowfunction-call-in-function-expected.txt: Added. * js/regress/arrowfunction-call-in-function.html: Added. * js/regress/script-tests/arrowfunction-call-in-class-constructor.js: Added. * js/regress/script-tests/arrowfunction-call-in-class-method.js: Added. * js/regress/script-tests/arrowfunction-call-in-function.js: Added. * js/regress/script-tests/arrowfunction-call.js: Canonical link: https://commits.webkit.org/172739@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197033 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 2762820 commit 5071a97

33 files changed

Lines changed: 615 additions & 58 deletions

‎LayoutTests/ChangeLog‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
2016-02-24 Skachkov Oleksandr <gskachkov@gmail.com>
2+
3+
[ES6] Arrow function syntax. Emit loading&putting this/super only if they are used in arrow function
4+
https://bugs.webkit.org/show_bug.cgi?id=153981
5+
6+
Reviewed by Saam Barati.
7+
8+
Added new benchmark tests for invoking arrow function within function, class's constructor and method
9+
10+
* js/regress/arrowfunction-call-in-class-constructor-expected.txt: Added.
11+
* js/regress/arrowfunction-call-in-class-constructor.html: Added.
12+
* js/regress/arrowfunction-call-in-class-method-expected.txt: Added.
13+
* js/regress/arrowfunction-call-in-class-method.html: Added.
14+
* js/regress/arrowfunction-call-in-function-expected.txt: Added.
15+
* js/regress/arrowfunction-call-in-function.html: Added.
16+
* js/regress/script-tests/arrowfunction-call-in-class-constructor.js: Added.
17+
* js/regress/script-tests/arrowfunction-call-in-class-method.js: Added.
18+
* js/regress/script-tests/arrowfunction-call-in-function.js: Added.
19+
* js/regress/script-tests/arrowfunction-call.js:
20+
121
2016-02-24 Zalan Bujtas <zalan@apple.com>
222

323
Background of an absolutely positioned inline element inside text-indented parent is positioned statically.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
JSRegress/arrowfunction-call-in-class-constructor
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
PASS no exception thrown
7+
PASS successfullyParsed is true
8+
9+
TEST COMPLETE
10+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2+
<html>
3+
<head>
4+
<script src="../../resources/js-test-pre.js"></script>
5+
</head>
6+
<body>
7+
<script src="../../resources/regress-pre.js"></script>
8+
<script src="script-tests/arrowfunction-call-in-class-constructor.js"></script>
9+
<script src="../../resources/regress-post.js"></script>
10+
<script src="../../resources/js-test-post.js"></script>
11+
</body>
12+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
JSRegress/arrowfunction-call-in-class-method
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
PASS no exception thrown
7+
PASS successfullyParsed is true
8+
9+
TEST COMPLETE
10+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2+
<html>
3+
<head>
4+
<script src="../../resources/js-test-pre.js"></script>
5+
</head>
6+
<body>
7+
<script src="../../resources/regress-pre.js"></script>
8+
<script src="script-tests/arrowfunction-call-in-class-method.js"></script>
9+
<script src="../../resources/regress-post.js"></script>
10+
<script src="../../resources/js-test-post.js"></script>
11+
</body>
12+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
JSRegress/arrowfunction-call-in-function
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
PASS no exception thrown
7+
PASS successfullyParsed is true
8+
9+
TEST COMPLETE
10+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2+
<html>
3+
<head>
4+
<script src="../../resources/js-test-pre.js"></script>
5+
</head>
6+
<body>
7+
<script src="../../resources/regress-pre.js"></script>
8+
<script src="script-tests/arrowfunction-call-in-function.js"></script>
9+
<script src="../../resources/regress-post.js"></script>
10+
<script src="../../resources/js-test-post.js"></script>
11+
</body>
12+
</html>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var testValue = 'test-value';
2+
3+
class A {
4+
constructor() {
5+
this.value = testValue;
6+
}
7+
}
8+
9+
class B extends A {
10+
constructor() {
11+
super();
12+
var arrow = () => testValue;
13+
arrow();
14+
}
15+
}
16+
17+
noInline(B);
18+
19+
for (let i = 0; i < 1000000; ++i) {
20+
let b = new B();
21+
if (b.value != testValue)
22+
throw "Error: bad result: " + result;
23+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var testValue = 'test-value';
2+
3+
class A {
4+
constructor() {
5+
this.value = testValue;
6+
}
7+
8+
getValue () {
9+
return this.value;
10+
}
11+
}
12+
13+
class B extends A {
14+
getParentValue() {
15+
var arrow = () => testValue;
16+
return arrow();
17+
}
18+
}
19+
20+
for (let i = 0; i < 100000; ++i) {
21+
let b = new B();
22+
if (b.getParentValue() != testValue)
23+
throw "Error: bad result: " + result;
24+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function bar(a, b) {
2+
return ((_a, _b) => _a + _b)(a, b);
3+
}
4+
5+
noInline(bar);
6+
7+
for (let i = 0; i < 1000000; ++i) {
8+
let result = bar(1, 2);
9+
if (result != 3)
10+
throw "Error: bad result: " + result;
11+
}

0 commit comments

Comments
 (0)