Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(717)

Unified Diff: src/parser.cc

Issue 1314203002: [strong] Class constructor bodies cannot contain "use strong" directive (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: formatting Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 71b1e558c29411a009c1382492b3643e5a365bf4..2bb69a877704c5e1e356a8dfefa921a094272720 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -1321,6 +1321,25 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
token_loc.end_pos - token_loc.beg_pos ==
ast_value_factory()->use_strong_string()->length() + 2;
if (use_strict_found || use_strong_found) {
+ // Strong mode implies strict mode. If there are several "use strict"
+ // / "use strong" directives, do the strict mode changes only once.
+ if (is_sloppy(scope_->language_mode())) {
+ scope_->SetLanguageMode(
+ static_cast<LanguageMode>(scope_->language_mode() | STRICT));
+ }
+
+ if (use_strong_found) {
+ scope_->SetLanguageMode(
+ static_cast<LanguageMode>(scope_->language_mode() | STRONG));
+ if (i::IsConstructor(function_state_->kind())) {
+ // "use strong" cannot occur in a class constructor body, to avoid
+ // unintuitive strong class object semantics.
+ ParserTraits::ReportMessageAt(
+ token_loc, MessageTemplate::kStrongConstructorDirective);
+ *ok = false;
+ return nullptr;
+ }
+ }
if (!scope_->HasSimpleParameters()) {
// TC39 deemed "use strict" directives to be an error when occurring
// in the body of a function with non-simple parameter list, on
@@ -1334,18 +1353,6 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
*ok = false;
return nullptr;
}
-
- // Strong mode implies strict mode. If there are several "use strict"
- // / "use strong" directives, do the strict mode changes only once.
- if (is_sloppy(scope_->language_mode())) {
- scope_->SetLanguageMode(static_cast<LanguageMode>(
- scope_->language_mode() | STRICT));
- }
-
- if (use_strong_found) {
- scope_->SetLanguageMode(static_cast<LanguageMode>(
- scope_->language_mode() | STRONG));
- }
// Because declarations in strict eval code don't leak into the scope
// of the eval call, it is likely that functions declared in strict
// eval code will be used within the eval code, so lazy parsing is
« no previous file with comments | « src/messages.h ('k') | src/preparser.cc » ('j') | test/mjsunit/strong/function-arity.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698