OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/parser.h" | 5 #include "src/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/ast-literal-reindexer.h" | 9 #include "src/ast-literal-reindexer.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 ast_value_factory()->use_strict_string() && | 1314 ast_value_factory()->use_strict_string() && |
1315 token_loc.end_pos - token_loc.beg_pos == | 1315 token_loc.end_pos - token_loc.beg_pos == |
1316 ast_value_factory()->use_strict_string()->length() + 2; | 1316 ast_value_factory()->use_strict_string()->length() + 2; |
1317 bool use_strong_found = | 1317 bool use_strong_found = |
1318 allow_strong_mode() && | 1318 allow_strong_mode() && |
1319 literal->raw_value()->AsString() == | 1319 literal->raw_value()->AsString() == |
1320 ast_value_factory()->use_strong_string() && | 1320 ast_value_factory()->use_strong_string() && |
1321 token_loc.end_pos - token_loc.beg_pos == | 1321 token_loc.end_pos - token_loc.beg_pos == |
1322 ast_value_factory()->use_strong_string()->length() + 2; | 1322 ast_value_factory()->use_strong_string()->length() + 2; |
1323 if (use_strict_found || use_strong_found) { | 1323 if (use_strict_found || use_strong_found) { |
| 1324 // Strong mode implies strict mode. If there are several "use strict" |
| 1325 // / "use strong" directives, do the strict mode changes only once. |
| 1326 if (is_sloppy(scope_->language_mode())) { |
| 1327 scope_->SetLanguageMode( |
| 1328 static_cast<LanguageMode>(scope_->language_mode() | STRICT)); |
| 1329 } |
| 1330 |
| 1331 if (use_strong_found) { |
| 1332 scope_->SetLanguageMode( |
| 1333 static_cast<LanguageMode>(scope_->language_mode() | STRONG)); |
| 1334 if (i::IsConstructor(function_state_->kind())) { |
| 1335 // "use strong" cannot occur in a class constructor body, to avoid |
| 1336 // unintuitive strong class object semantics. |
| 1337 ParserTraits::ReportMessageAt( |
| 1338 token_loc, MessageTemplate::kStrongConstructorDirective); |
| 1339 *ok = false; |
| 1340 return nullptr; |
| 1341 } |
| 1342 } |
1324 if (!scope_->HasSimpleParameters()) { | 1343 if (!scope_->HasSimpleParameters()) { |
1325 // TC39 deemed "use strict" directives to be an error when occurring | 1344 // TC39 deemed "use strict" directives to be an error when occurring |
1326 // in the body of a function with non-simple parameter list, on | 1345 // in the body of a function with non-simple parameter list, on |
1327 // 29/7/2015. https://goo.gl/ueA7Ln | 1346 // 29/7/2015. https://goo.gl/ueA7Ln |
1328 // | 1347 // |
1329 // In V8, this also applies to "use strong " directives. | 1348 // In V8, this also applies to "use strong " directives. |
1330 const AstRawString* string = literal->raw_value()->AsString(); | 1349 const AstRawString* string = literal->raw_value()->AsString(); |
1331 ParserTraits::ReportMessageAt( | 1350 ParserTraits::ReportMessageAt( |
1332 token_loc, MessageTemplate::kIllegalLanguageModeDirective, | 1351 token_loc, MessageTemplate::kIllegalLanguageModeDirective, |
1333 string); | 1352 string); |
1334 *ok = false; | 1353 *ok = false; |
1335 return nullptr; | 1354 return nullptr; |
1336 } | 1355 } |
1337 | |
1338 // Strong mode implies strict mode. If there are several "use strict" | |
1339 // / "use strong" directives, do the strict mode changes only once. | |
1340 if (is_sloppy(scope_->language_mode())) { | |
1341 scope_->SetLanguageMode(static_cast<LanguageMode>( | |
1342 scope_->language_mode() | STRICT)); | |
1343 } | |
1344 | |
1345 if (use_strong_found) { | |
1346 scope_->SetLanguageMode(static_cast<LanguageMode>( | |
1347 scope_->language_mode() | STRONG)); | |
1348 } | |
1349 // Because declarations in strict eval code don't leak into the scope | 1356 // Because declarations in strict eval code don't leak into the scope |
1350 // of the eval call, it is likely that functions declared in strict | 1357 // of the eval call, it is likely that functions declared in strict |
1351 // eval code will be used within the eval code, so lazy parsing is | 1358 // eval code will be used within the eval code, so lazy parsing is |
1352 // probably not a win. | 1359 // probably not a win. |
1353 if (scope_->is_eval_scope()) mode_ = PARSE_EAGERLY; | 1360 if (scope_->is_eval_scope()) mode_ = PARSE_EAGERLY; |
1354 } else if (literal->raw_value()->AsString() == | 1361 } else if (literal->raw_value()->AsString() == |
1355 ast_value_factory()->use_asm_string() && | 1362 ast_value_factory()->use_asm_string() && |
1356 token_loc.end_pos - token_loc.beg_pos == | 1363 token_loc.end_pos - token_loc.beg_pos == |
1357 ast_value_factory()->use_asm_string()->length() + 2) { | 1364 ast_value_factory()->use_asm_string()->length() + 2) { |
1358 // Store the usage count; The actual use counter on the isolate is | 1365 // Store the usage count; The actual use counter on the isolate is |
(...skipping 4744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6103 | 6110 |
6104 Expression* Parser::SpreadCallNew(Expression* function, | 6111 Expression* Parser::SpreadCallNew(Expression* function, |
6105 ZoneList<v8::internal::Expression*>* args, | 6112 ZoneList<v8::internal::Expression*>* args, |
6106 int pos) { | 6113 int pos) { |
6107 args->InsertAt(0, function, zone()); | 6114 args->InsertAt(0, function, zone()); |
6108 | 6115 |
6109 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); | 6116 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); |
6110 } | 6117 } |
6111 } // namespace internal | 6118 } // namespace internal |
6112 } // namespace v8 | 6119 } // namespace v8 |
OLD | NEW |