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/v8.h" | 5 #include "src/v8.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/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 int pos, int end_pos) { | 282 int pos, int end_pos) { |
283 int materialized_literal_count = -1; | 283 int materialized_literal_count = -1; |
284 int expected_property_count = -1; | 284 int expected_property_count = -1; |
285 int handler_count = 0; | 285 int handler_count = 0; |
286 int parameter_count = 0; | 286 int parameter_count = 0; |
287 const AstRawString* name = ast_value_factory()->empty_string(); | 287 const AstRawString* name = ast_value_factory()->empty_string(); |
288 | 288 |
289 Scope* function_scope = | 289 Scope* function_scope = |
290 NewScope(scope, FUNCTION_SCOPE, FunctionKind::kDefaultConstructor); | 290 NewScope(scope, FUNCTION_SCOPE, FunctionKind::kDefaultConstructor); |
291 function_scope->SetLanguageMode( | 291 function_scope->SetLanguageMode( |
292 static_cast<LanguageMode>(scope->language_mode() | STRICT)); | 292 static_cast<LanguageMode>(scope->language_mode() | STRICT_BIT)); |
293 // Set start and end position to the same value | 293 // Set start and end position to the same value |
294 function_scope->set_start_position(pos); | 294 function_scope->set_start_position(pos); |
295 function_scope->set_end_position(pos); | 295 function_scope->set_end_position(pos); |
296 ZoneList<Statement*>* body = NULL; | 296 ZoneList<Statement*>* body = NULL; |
297 | 297 |
298 { | 298 { |
299 AstNodeFactory function_factory(ast_value_factory()); | 299 AstNodeFactory function_factory(ast_value_factory()); |
300 FunctionState function_state(&function_state_, &scope_, function_scope, | 300 FunctionState function_state(&function_state_, &scope_, function_scope, |
301 &function_factory); | 301 &function_factory); |
302 | 302 |
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1138 } | 1138 } |
1139 | 1139 |
1140 if (directive_prologue) { | 1140 if (directive_prologue) { |
1141 // A shot at a directive. | 1141 // A shot at a directive. |
1142 ExpressionStatement* e_stat; | 1142 ExpressionStatement* e_stat; |
1143 Literal* literal; | 1143 Literal* literal; |
1144 // Still processing directive prologue? | 1144 // Still processing directive prologue? |
1145 if ((e_stat = stat->AsExpressionStatement()) != NULL && | 1145 if ((e_stat = stat->AsExpressionStatement()) != NULL && |
1146 (literal = e_stat->expression()->AsLiteral()) != NULL && | 1146 (literal = e_stat->expression()->AsLiteral()) != NULL && |
1147 literal->raw_value()->IsString()) { | 1147 literal->raw_value()->IsString()) { |
1148 // Check "use strict" directive (ES5 14.1) and "use asm" directive. Only | 1148 // Check "use strict" directive (ES5 14.1), "use asm" directive, and |
1149 // one can be present. | 1149 // "use sanity" directive (experimental). Only one can be present. |
1150 if (is_sloppy(language_mode()) && | 1150 bool use_strict_found = |
1151 is_sloppy(language_mode()) && | |
1151 literal->raw_value()->AsString() == | 1152 literal->raw_value()->AsString() == |
1152 ast_value_factory()->use_strict_string() && | 1153 ast_value_factory()->use_strict_string() && |
1153 token_loc.end_pos - token_loc.beg_pos == | 1154 token_loc.end_pos - token_loc.beg_pos == |
1154 ast_value_factory()->use_strict_string()->length() + 2) { | 1155 ast_value_factory()->use_strict_string()->length() + 2; |
1156 bool use_sanity_found = | |
arv (Not doing code reviews)
2015/02/04 16:17:11
Don't we want a flag for this work?
rossberg
2015/02/04 16:19:57
Ah, excellent point! Yes, we need a flag. I sugges
marja
2015/02/05 12:11:37
Done.
| |
1157 !use_strict_found && !is_sane(language_mode()) && | |
rossberg
2015/02/04 16:18:09
If I read this correctly then
"use sanity"; "us
marja
2015/02/05 12:11:37
Done. (Oops, preparser was already following that
| |
1158 literal->raw_value()->AsString() == | |
1159 ast_value_factory()->use_sanity_string() && | |
1160 token_loc.end_pos - token_loc.beg_pos == | |
1161 ast_value_factory()->use_sanity_string()->length() + 2; | |
1162 if (use_strict_found || use_sanity_found) { | |
1163 // Sane mode implies strict mode. | |
1164 | |
1155 // TODO(mstarzinger): Global strict eval calls, need their own scope | 1165 // TODO(mstarzinger): Global strict eval calls, need their own scope |
1156 // as specified in ES5 10.4.2(3). The correct fix would be to always | 1166 // as specified in ES5 10.4.2(3). The correct fix would be to always |
1157 // add this scope in DoParseProgram(), but that requires adaptations | 1167 // add this scope in DoParseProgram(), but that requires adaptations |
1158 // all over the code base, so we go with a quick-fix for now. | 1168 // all over the code base, so we go with a quick-fix for now. |
1159 // In the same manner, we have to patch the parsing mode. | 1169 // In the same manner, we have to patch the parsing mode. |
1160 if (is_eval && !scope_->is_eval_scope()) { | 1170 if (is_eval && !scope_->is_eval_scope()) { |
1161 DCHECK(scope_->is_script_scope()); | 1171 DCHECK(scope_->is_script_scope()); |
1162 Scope* scope = NewScope(scope_, EVAL_SCOPE); | 1172 Scope* scope = NewScope(scope_, EVAL_SCOPE); |
1163 scope->set_start_position(scope_->start_position()); | 1173 scope->set_start_position(scope_->start_position()); |
1164 scope->set_end_position(scope_->end_position()); | 1174 scope->set_end_position(scope_->end_position()); |
1165 scope_ = scope; | 1175 scope_ = scope; |
1166 if (eval_scope != NULL) { | 1176 if (eval_scope != NULL) { |
1167 // Caller will correct the positions of the ad hoc eval scope. | 1177 // Caller will correct the positions of the ad hoc eval scope. |
1168 *eval_scope = scope; | 1178 *eval_scope = scope; |
1169 } | 1179 } |
1170 mode_ = PARSE_EAGERLY; | 1180 mode_ = PARSE_EAGERLY; |
1171 } | 1181 } |
1172 scope_->SetLanguageMode( | 1182 scope_->SetLanguageMode( |
1173 static_cast<LanguageMode>(scope_->language_mode() | STRICT)); | 1183 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); |
1174 // "use strict" is the only directive for now. | 1184 |
1185 if (use_sanity_found) { | |
1186 scope_->SetLanguageMode( | |
1187 static_cast<LanguageMode>(scope_->language_mode() | SANE_BIT)); | |
1188 } | |
1189 | |
1190 // Don't allow additional directives. | |
1175 directive_prologue = false; | 1191 directive_prologue = false; |
1176 } else if (literal->raw_value()->AsString() == | 1192 } else if (literal->raw_value()->AsString() == |
1177 ast_value_factory()->use_asm_string() && | 1193 ast_value_factory()->use_asm_string() && |
1178 token_loc.end_pos - token_loc.beg_pos == | 1194 token_loc.end_pos - token_loc.beg_pos == |
1179 ast_value_factory()->use_asm_string()->length() + 2) { | 1195 ast_value_factory()->use_asm_string()->length() + 2) { |
1180 // Store the usage count; The actual use counter on the isolate is | 1196 // Store the usage count; The actual use counter on the isolate is |
1181 // incremented after parsing is done. | 1197 // incremented after parsing is done. |
1182 ++use_counts_[v8::Isolate::kUseAsm]; | 1198 ++use_counts_[v8::Isolate::kUseAsm]; |
1183 scope_->SetAsmModule(); | 1199 scope_->SetAsmModule(); |
1200 // Don't allow additional directives. | |
1201 directive_prologue = false; | |
1184 } | 1202 } |
1185 } else { | 1203 } else { |
1186 // End of the directive prologue. | 1204 // End of the directive prologue. |
1187 directive_prologue = false; | 1205 directive_prologue = false; |
1188 } | 1206 } |
1189 } | 1207 } |
1190 | 1208 |
1191 body->Add(stat, zone()); | 1209 body->Add(stat, zone()); |
1192 } | 1210 } |
1193 | 1211 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1250 int pos = peek_position(); | 1268 int pos = peek_position(); |
1251 // Construct block expecting 16 statements. | 1269 // Construct block expecting 16 statements. |
1252 Block* body = factory()->NewBlock(NULL, 16, false, RelocInfo::kNoPosition); | 1270 Block* body = factory()->NewBlock(NULL, 16, false, RelocInfo::kNoPosition); |
1253 #ifdef DEBUG | 1271 #ifdef DEBUG |
1254 if (FLAG_print_interface_details) PrintF("# Literal "); | 1272 if (FLAG_print_interface_details) PrintF("# Literal "); |
1255 #endif | 1273 #endif |
1256 Scope* scope = NewScope(scope_, MODULE_SCOPE); | 1274 Scope* scope = NewScope(scope_, MODULE_SCOPE); |
1257 | 1275 |
1258 scope->set_start_position(scanner()->location().beg_pos); | 1276 scope->set_start_position(scanner()->location().beg_pos); |
1259 scope->SetLanguageMode( | 1277 scope->SetLanguageMode( |
1260 static_cast<LanguageMode>(scope->language_mode() | STRICT)); | 1278 static_cast<LanguageMode>(scope->language_mode() | STRICT_BIT)); |
1261 | 1279 |
1262 { | 1280 { |
1263 BlockState block_state(&scope_, scope); | 1281 BlockState block_state(&scope_, scope); |
1264 Target target(&this->target_stack_, body); | 1282 Target target(&this->target_stack_, body); |
1265 | 1283 |
1266 while (peek() != Token::EOS) { | 1284 while (peek() != Token::EOS) { |
1267 Statement* stat = ParseModuleItem(CHECK_OK); | 1285 Statement* stat = ParseModuleItem(CHECK_OK); |
1268 if (stat && !stat->IsEmpty()) { | 1286 if (stat && !stat->IsEmpty()) { |
1269 body->AddStatement(stat, zone()); | 1287 body->AddStatement(stat, zone()); |
1270 } | 1288 } |
(...skipping 2758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4029 } | 4047 } |
4030 if (IsEvalOrArguments(name)) { | 4048 if (IsEvalOrArguments(name)) { |
4031 ReportMessageAt(class_name_location, "strict_eval_arguments"); | 4049 ReportMessageAt(class_name_location, "strict_eval_arguments"); |
4032 *ok = false; | 4050 *ok = false; |
4033 return NULL; | 4051 return NULL; |
4034 } | 4052 } |
4035 | 4053 |
4036 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); | 4054 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); |
4037 BlockState block_state(&scope_, block_scope); | 4055 BlockState block_state(&scope_, block_scope); |
4038 scope_->SetLanguageMode( | 4056 scope_->SetLanguageMode( |
4039 static_cast<LanguageMode>(scope_->language_mode() | STRICT)); | 4057 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); |
4040 scope_->SetScopeName(name); | 4058 scope_->SetScopeName(name); |
4041 | 4059 |
4042 VariableProxy* proxy = NULL; | 4060 VariableProxy* proxy = NULL; |
4043 if (name != NULL) { | 4061 if (name != NULL) { |
4044 proxy = NewUnresolved(name, CONST, Interface::NewConst()); | 4062 proxy = NewUnresolved(name, CONST, Interface::NewConst()); |
4045 Declaration* declaration = | 4063 Declaration* declaration = |
4046 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); | 4064 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); |
4047 Declare(declaration, true, CHECK_OK); | 4065 Declare(declaration, true, CHECK_OK); |
4048 } | 4066 } |
4049 | 4067 |
(...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5412 } else { | 5430 } else { |
5413 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); | 5431 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); |
5414 running_hash = StringHasher::ComputeRunningHash(running_hash, data, | 5432 running_hash = StringHasher::ComputeRunningHash(running_hash, data, |
5415 raw_string->length()); | 5433 raw_string->length()); |
5416 } | 5434 } |
5417 } | 5435 } |
5418 | 5436 |
5419 return running_hash; | 5437 return running_hash; |
5420 } | 5438 } |
5421 } } // namespace v8::internal | 5439 } } // namespace v8::internal |
OLD | NEW |