Reviewers: rossberg, wingo, caitp,
Message:
I'm not at all sure we want to land this, but I wanted to bump its
visibility up
a bit.
Description:
Always lazy compile arrow functions
This causes the scope of default parameters to be correct, where otherwise
we'd get it wrong, as expressions in default parameters would be evaluated
in the scope containing the arrow function.
This is something of a hack. The right way to fix it would likely be to
do something like pattern-rewriter, but for scopes.
BUG=v8:4395
LOG=n
Please review this at https://codereview.chromium.org/1317033005/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+10, -4 lines):
M src/preparser.h
A + test/mjsunit/harmony/regress/regress-4395.js
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index
a5aa3709a6d509174fe9c02530b80cd940c907ab..2b07de94c47037d58c1f1a0652f96a75fe2d2677
100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -1083,6 +1083,7 @@ class PreParserExpression {
// More dummy implementations of things PreParser doesn't need to track:
void set_index(int index) {} // For YieldExpressions
void set_should_eager_compile() {}
+ FunctionKind kind() const { return FunctionKind::kNormalFunction; }
int position() const { return RelocInfo::kNoPosition; }
void set_function_token_position(int position) {}
@@ -3279,8 +3280,12 @@ ParserBase<Traits>::ParseLeftHandSideExpression(
pos = peek_position();
// Also the trailing parenthesis are a hint that the function
will
// be called immediately. If we happen to have parsed a preceding
- // function literal eagerly, we can also compile it eagerly.
- if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) {
+ // function literal eagerly, we can also compile it eagerly
(unless
+ // that literal was an arrow function, in which case we always
+ // compile lazily in order to get scoping right for its
parameters,
+ // see https://code.google.com/p/v8/issues/detail?id=4395).
+ if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY &&
+ !IsArrowFunction(result->AsFunctionLiteral()->kind())) {
result->AsFunctionLiteral()->set_should_eager_compile();
}
}
Index: test/mjsunit/harmony/regress/regress-4395.js
diff --git a/test/message/arrow-param-after-rest.js
b/test/mjsunit/harmony/regress/regress-4395.js
similarity index 54%
copy from test/message/arrow-param-after-rest.js
copy to test/mjsunit/harmony/regress/regress-4395.js
index
0fade6c31d3cb6c2e82fb7027628fdfae96e1962..3d957137be1bf61b8a4663f634d10097d457024d
100644
--- a/test/message/arrow-param-after-rest.js
+++ b/test/mjsunit/harmony/regress/regress-4395.js
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
-// Flags: --harmony-rest-parameters --harmony-arrow-functions
+// Flags: --harmony-default-parameters
-(...x, y) => 10
+assertEquals([42, 42], ((a, b=a=42) => [a, b])(10));
+assertEquals([10, 10], ((a, b=a) => [a, b])(10));
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.