Reviewers: arv, conradw,
Description:
[strong] Make strong 'this' optional for experimentation
[email protected], [email protected]
BUG=v8:3956
Please review this at https://codereview.chromium.org/1180943007/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+6, -3 lines):
M src/flag-definitions.h
M src/parser.cc
M src/preparser.h
M src/preparser.cc
Index: src/flag-definitions.h
diff --git a/src/flag-definitions.h b/src/flag-definitions.h
index
b9219372b906e0837fa10592abee6436cab1f423..54ea288d058281a73d175f2f03c38bf40406be79
100644
--- a/src/flag-definitions.h
+++ b/src/flag-definitions.h
@@ -174,6 +174,7 @@ DEFINE_IMPLICATION(use_strong, use_strict)
DEFINE_BOOL(strong_mode, false, "experimental strong language mode")
DEFINE_IMPLICATION(use_strong, strong_mode)
+DEFINE_BOOL(strong_this, true, "don't allow 'this' to escape from
constructors")
DEFINE_BOOL(es_staging, false, "enable all completed harmony features")
DEFINE_BOOL(harmony, false, "enable all completed harmony features")
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index
96c269546f755b6a706a4cc9d13b555453ad3d25..7e0c1a8aa629d8e60b9cacc6f56931bb7873f4cd
100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -2563,7 +2563,8 @@ Statement* Parser::ParseExpressionOrLabelledStatement(
case Token::THIS:
case Token::SUPER:
- if (is_strong(language_mode()) &&
+ if ((FLAG_strong_this || peek() != Token::THIS) &&
+ is_strong(language_mode()) &&
i::IsConstructor(function_state_->kind())) {
bool is_this = peek() == Token::THIS;
Expression* expr;
Index: src/preparser.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index
ddea1792781a5d10310b2095b9c67e7dff9531f2..42703d6ddfc357838641521e74cce906678e0b16
100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -600,7 +600,8 @@ PreParser::Statement
PreParser::ParseExpressionOrLabelledStatement(bool* ok) {
case Token::THIS:
case Token::SUPER:
- if (is_strong(language_mode()) &&
+ if ((FLAG_strong_this || peek() != Token::THIS) &&
+ is_strong(language_mode()) &&
i::IsConstructor(function_state_->kind())) {
bool is_this = peek() == Token::THIS;
Expression expr = Expression::Default();
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index
dd36de789090d35e8724e71fce2b4f7605acd5a8..fe31564daf71242c3197a41d30dc758d2622febf
100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -2064,7 +2064,7 @@
ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
case Token::THIS: {
BindingPatternUnexpectedToken(classifier);
Consume(Token::THIS);
- if (is_strong(language_mode())) {
+ if (FLAG_strong_this && is_strong(language_mode())) {
// Constructors' usages of 'this' in strong mode are parsed
separately.
// TODO(rossberg): this does not work with arrow functions yet.
if (i::IsConstructor(function_state_->kind())) {
--
--
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.