OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 // --------------------------------------------------------------------------- | 185 // --------------------------------------------------------------------------- |
186 // Scope-specific info. | 186 // Scope-specific info. |
187 | 187 |
188 // Inform the scope that the corresponding code contains a with statement. | 188 // Inform the scope that the corresponding code contains a with statement. |
189 void RecordWithStatement() { scope_contains_with_ = true; } | 189 void RecordWithStatement() { scope_contains_with_ = true; } |
190 | 190 |
191 // Inform the scope that the corresponding code contains an eval call. | 191 // Inform the scope that the corresponding code contains an eval call. |
192 void RecordEvalCall() { if (!is_global_scope()) scope_calls_eval_ = true; } | 192 void RecordEvalCall() { if (!is_global_scope()) scope_calls_eval_ = true; } |
193 | 193 |
194 // Set the strict mode flag (unless disabled by a global flag). | 194 // Set the strict mode flag (unless disabled by a global flag). |
195 void SetStrictModeFlag(StrictModeFlag strict_mode_flag) { | 195 void SetLanguageMode(LanguageMode language_mode) { |
196 strict_mode_flag_ = FLAG_strict_mode ? strict_mode_flag : kNonStrictMode; | 196 language_mode_ = FLAG_strict_mode ? language_mode : CLASSIC_MODE; |
rossberg
2011/11/08 15:02:46
Does such a flag still make sense given the new la
Steven
2011/11/08 16:13:49
Not really. Removing it.
On 2011/11/08 15:02:46, r
| |
197 } | 197 } |
198 | 198 |
199 // Position in the source where this scope begins and ends. | 199 // Position in the source where this scope begins and ends. |
200 // | 200 // |
201 // * For the scope of a with statement | 201 // * For the scope of a with statement |
202 // with (obj) stmt | 202 // with (obj) stmt |
203 // start position: start position of first token of 'stmt' | 203 // start position: start position of first token of 'stmt' |
204 // end position: end position of last token of 'stmt' | 204 // end position: end position of last token of 'stmt' |
205 // * For the scope of a block | 205 // * For the scope of a block |
206 // { stmts } | 206 // { stmts } |
(...skipping 26 matching lines...) Expand all Loading... | |
233 // Specific scope types. | 233 // Specific scope types. |
234 bool is_eval_scope() const { return type_ == EVAL_SCOPE; } | 234 bool is_eval_scope() const { return type_ == EVAL_SCOPE; } |
235 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; } | 235 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; } |
236 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; } | 236 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; } |
237 bool is_catch_scope() const { return type_ == CATCH_SCOPE; } | 237 bool is_catch_scope() const { return type_ == CATCH_SCOPE; } |
238 bool is_block_scope() const { return type_ == BLOCK_SCOPE; } | 238 bool is_block_scope() const { return type_ == BLOCK_SCOPE; } |
239 bool is_with_scope() const { return type_ == WITH_SCOPE; } | 239 bool is_with_scope() const { return type_ == WITH_SCOPE; } |
240 bool is_declaration_scope() const { | 240 bool is_declaration_scope() const { |
241 return is_eval_scope() || is_function_scope() || is_global_scope(); | 241 return is_eval_scope() || is_function_scope() || is_global_scope(); |
242 } | 242 } |
243 bool is_strict_mode() const { return strict_mode_flag() == kStrictMode; } | 243 bool is_classic_mode() const { |
244 bool is_strict_mode_eval_scope() const { | 244 return language_mode() == CLASSIC_MODE; |
245 return is_eval_scope() && is_strict_mode(); | 245 } |
246 bool is_extended_mode() const { | |
247 return language_mode() == EXTENDED_MODE; | |
248 } | |
249 bool is_strict_or_extended_mode() const { | |
rossberg
2011/11/08 15:02:46
And one more.
Steven
2011/11/08 16:13:49
Done.
| |
250 return language_mode() != CLASSIC_MODE; | |
251 } | |
252 bool is_strict_or_extended_eval_scope() const { | |
253 return is_eval_scope() && is_strict_or_extended_mode(); | |
246 } | 254 } |
247 | 255 |
248 // Information about which scopes calls eval. | 256 // Information about which scopes calls eval. |
249 bool calls_eval() const { return scope_calls_eval_; } | 257 bool calls_eval() const { return scope_calls_eval_; } |
250 bool calls_non_strict_eval() { | 258 bool calls_non_strict_eval() { |
251 return scope_calls_eval_ && !is_strict_mode(); | 259 return scope_calls_eval_ && is_classic_mode(); |
252 } | 260 } |
253 bool outer_scope_calls_non_strict_eval() const { | 261 bool outer_scope_calls_non_strict_eval() const { |
254 return outer_scope_calls_non_strict_eval_; | 262 return outer_scope_calls_non_strict_eval_; |
255 } | 263 } |
256 | 264 |
257 // Is this scope inside a with statement. | 265 // Is this scope inside a with statement. |
258 bool inside_with() const { return scope_inside_with_; } | 266 bool inside_with() const { return scope_inside_with_; } |
259 // Does this scope contain a with statement. | 267 // Does this scope contain a with statement. |
260 bool contains_with() const { return scope_contains_with_; } | 268 bool contains_with() const { return scope_contains_with_; } |
261 | 269 |
262 // The scope immediately surrounding this scope, or NULL. | 270 // The scope immediately surrounding this scope, or NULL. |
263 Scope* outer_scope() const { return outer_scope_; } | 271 Scope* outer_scope() const { return outer_scope_; } |
264 | 272 |
265 // --------------------------------------------------------------------------- | 273 // --------------------------------------------------------------------------- |
266 // Accessors. | 274 // Accessors. |
267 | 275 |
268 // The type of this scope. | 276 // The type of this scope. |
269 ScopeType type() const { return type_; } | 277 ScopeType type() const { return type_; } |
270 | 278 |
271 // The strict mode of this scope. | 279 // The language mode of this scope. |
272 StrictModeFlag strict_mode_flag() const { return strict_mode_flag_; } | 280 LanguageMode language_mode() const { return language_mode_; } |
273 | 281 |
274 // The variable corresponding the 'this' value. | 282 // The variable corresponding the 'this' value. |
275 Variable* receiver() { return receiver_; } | 283 Variable* receiver() { return receiver_; } |
276 | 284 |
277 // The variable holding the function literal for named function | 285 // The variable holding the function literal for named function |
278 // literals, or NULL. | 286 // literals, or NULL. |
279 // Only valid for function scopes. | 287 // Only valid for function scopes. |
280 VariableProxy* function() const { | 288 VariableProxy* function() const { |
281 ASSERT(is_function_scope()); | 289 ASSERT(is_function_scope()); |
282 return function_; | 290 return function_; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 // Scope-specific information computed during parsing. | 426 // Scope-specific information computed during parsing. |
419 // | 427 // |
420 // This scope is inside a 'with' of some outer scope. | 428 // This scope is inside a 'with' of some outer scope. |
421 bool scope_inside_with_; | 429 bool scope_inside_with_; |
422 // This scope contains a 'with' statement. | 430 // This scope contains a 'with' statement. |
423 bool scope_contains_with_; | 431 bool scope_contains_with_; |
424 // This scope or a nested catch scope or with scope contain an 'eval' call. At | 432 // This scope or a nested catch scope or with scope contain an 'eval' call. At |
425 // the 'eval' call site this scope is the declaration scope. | 433 // the 'eval' call site this scope is the declaration scope. |
426 bool scope_calls_eval_; | 434 bool scope_calls_eval_; |
427 // This scope is a strict mode scope. | 435 // This scope is a strict mode scope. |
428 StrictModeFlag strict_mode_flag_; | 436 LanguageMode language_mode_; |
429 // Source positions. | 437 // Source positions. |
430 int start_position_; | 438 int start_position_; |
431 int end_position_; | 439 int end_position_; |
432 | 440 |
433 // Computed via PropagateScopeInfo. | 441 // Computed via PropagateScopeInfo. |
434 bool outer_scope_calls_non_strict_eval_; | 442 bool outer_scope_calls_non_strict_eval_; |
435 bool inner_scope_calls_eval_; | 443 bool inner_scope_calls_eval_; |
436 bool force_eager_compilation_; | 444 bool force_eager_compilation_; |
437 | 445 |
438 // True if it doesn't need scope resolution (e.g., if the scope was | 446 // True if it doesn't need scope resolution (e.g., if the scope was |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 } | 552 } |
545 | 553 |
546 void SetDefaults(ScopeType type, | 554 void SetDefaults(ScopeType type, |
547 Scope* outer_scope, | 555 Scope* outer_scope, |
548 Handle<ScopeInfo> scope_info); | 556 Handle<ScopeInfo> scope_info); |
549 }; | 557 }; |
550 | 558 |
551 } } // namespace v8::internal | 559 } } // namespace v8::internal |
552 | 560 |
553 #endif // V8_SCOPES_H_ | 561 #endif // V8_SCOPES_H_ |
OLD | NEW |