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

Side by Side Diff: src/scopes.h

Issue 8344082: Replace boolean indications of strict mode by an enum value. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Some fixes and adapted the preparser. Created 9 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 194
195 // --------------------------------------------------------------------------- 195 // ---------------------------------------------------------------------------
196 // Scope-specific info. 196 // Scope-specific info.
197 197
198 // Inform the scope that the corresponding code contains a with statement. 198 // Inform the scope that the corresponding code contains a with statement.
199 void RecordWithStatement() { scope_contains_with_ = true; } 199 void RecordWithStatement() { scope_contains_with_ = true; }
200 200
201 // Inform the scope that the corresponding code contains an eval call. 201 // Inform the scope that the corresponding code contains an eval call.
202 void RecordEvalCall() { if (!is_global_scope()) scope_calls_eval_ = true; } 202 void RecordEvalCall() { if (!is_global_scope()) scope_calls_eval_ = true; }
203 203
204 // Enable strict mode for the scope (unless disabled by a global flag). 204 // Set the strict mode flag (unless disabled by a global flag).
205 void EnableStrictMode() { 205 void SetStrictModeFlag(StrictModeFlag strict_mode_flag) {
206 strict_mode_ = FLAG_strict_mode; 206 strict_mode_flag_ = FLAG_strict_mode ? strict_mode_flag : kNonStrictMode;
207 } 207 }
208 208
209 // --------------------------------------------------------------------------- 209 // ---------------------------------------------------------------------------
210 // Predicates. 210 // Predicates.
211 211
212 // Specific scope types. 212 // Specific scope types.
213 bool is_eval_scope() const { return type_ == EVAL_SCOPE; } 213 bool is_eval_scope() const { return type_ == EVAL_SCOPE; }
214 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; } 214 bool is_function_scope() const { return type_ == FUNCTION_SCOPE; }
215 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; } 215 bool is_global_scope() const { return type_ == GLOBAL_SCOPE; }
216 bool is_catch_scope() const { return type_ == CATCH_SCOPE; } 216 bool is_catch_scope() const { return type_ == CATCH_SCOPE; }
217 bool is_block_scope() const { return type_ == BLOCK_SCOPE; } 217 bool is_block_scope() const { return type_ == BLOCK_SCOPE; }
218 bool is_with_scope() const { return type_ == WITH_SCOPE; } 218 bool is_with_scope() const { return type_ == WITH_SCOPE; }
219 bool is_declaration_scope() const { 219 bool is_declaration_scope() const {
220 return is_eval_scope() || is_function_scope() || is_global_scope(); 220 return is_eval_scope() || is_function_scope() || is_global_scope();
221 } 221 }
222 bool is_strict_mode() const { return strict_mode_; } 222 bool is_strict_mode() const { return strict_mode_flag() == kStrictMode; }
223 bool is_strict_mode_eval_scope() const { 223 bool is_strict_mode_eval_scope() const {
224 return is_eval_scope() && is_strict_mode(); 224 return is_eval_scope() && is_strict_mode();
225 } 225 }
226 226
227 // Information about which scopes calls eval. 227 // Information about which scopes calls eval.
228 bool calls_eval() const { return scope_calls_eval_; } 228 bool calls_eval() const { return scope_calls_eval_; }
229 bool calls_non_strict_eval() { 229 bool calls_non_strict_eval() {
230 return scope_calls_eval_ && !is_strict_mode(); 230 return scope_calls_eval_ && !is_strict_mode();
231 } 231 }
232 bool outer_scope_calls_non_strict_eval() const { 232 bool outer_scope_calls_non_strict_eval() const {
233 return outer_scope_calls_non_strict_eval_; 233 return outer_scope_calls_non_strict_eval_;
234 } 234 }
235 235
236 // Is this scope inside a with statement. 236 // Is this scope inside a with statement.
237 bool inside_with() const { return scope_inside_with_; } 237 bool inside_with() const { return scope_inside_with_; }
238 // Does this scope contain a with statement. 238 // Does this scope contain a with statement.
239 bool contains_with() const { return scope_contains_with_; } 239 bool contains_with() const { return scope_contains_with_; }
240 240
241 // The scope immediately surrounding this scope, or NULL. 241 // The scope immediately surrounding this scope, or NULL.
242 Scope* outer_scope() const { return outer_scope_; } 242 Scope* outer_scope() const { return outer_scope_; }
243 243
244 // --------------------------------------------------------------------------- 244 // ---------------------------------------------------------------------------
245 // Accessors. 245 // Accessors.
246 246
247 StrictModeFlag strict_mode_flag() const { return strict_mode_flag_; }
248
247 // The variable corresponding the 'this' value. 249 // The variable corresponding the 'this' value.
248 Variable* receiver() { return receiver_; } 250 Variable* receiver() { return receiver_; }
249 251
250 // The variable holding the function literal for named function 252 // The variable holding the function literal for named function
251 // literals, or NULL. 253 // literals, or NULL.
252 // Only valid for function scopes. 254 // Only valid for function scopes.
253 VariableProxy* function() const { 255 VariableProxy* function() const {
254 ASSERT(is_function_scope()); 256 ASSERT(is_function_scope());
255 return function_; 257 return function_;
256 } 258 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 // Scope-specific information computed during parsing. 381 // Scope-specific information computed during parsing.
380 // 382 //
381 // This scope is inside a 'with' of some outer scope. 383 // This scope is inside a 'with' of some outer scope.
382 bool scope_inside_with_; 384 bool scope_inside_with_;
383 // This scope contains a 'with' statement. 385 // This scope contains a 'with' statement.
384 bool scope_contains_with_; 386 bool scope_contains_with_;
385 // This scope or a nested catch scope or with scope contain an 'eval' call. At 387 // This scope or a nested catch scope or with scope contain an 'eval' call. At
386 // the 'eval' call site this scope is the declaration scope. 388 // the 'eval' call site this scope is the declaration scope.
387 bool scope_calls_eval_; 389 bool scope_calls_eval_;
388 // This scope is a strict mode scope. 390 // This scope is a strict mode scope.
389 bool strict_mode_; 391 StrictModeFlag strict_mode_flag_;
390 392
391 // Computed via PropagateScopeInfo. 393 // Computed via PropagateScopeInfo.
392 bool outer_scope_calls_non_strict_eval_; 394 bool outer_scope_calls_non_strict_eval_;
393 bool inner_scope_calls_eval_; 395 bool inner_scope_calls_eval_;
394 bool force_eager_compilation_; 396 bool force_eager_compilation_;
395 397
396 // True if it doesn't need scope resolution (e.g., if the scope was 398 // True if it doesn't need scope resolution (e.g., if the scope was
397 // constructed based on a serialized scope info or a catch context). 399 // constructed based on a serialized scope info or a catch context).
398 bool already_resolved_; 400 bool already_resolved_;
399 401
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 504 }
503 505
504 void SetDefaults(Type type, 506 void SetDefaults(Type type,
505 Scope* outer_scope, 507 Scope* outer_scope,
506 Handle<SerializedScopeInfo> scope_info); 508 Handle<SerializedScopeInfo> scope_info);
507 }; 509 };
508 510
509 } } // namespace v8::internal 511 } } // namespace v8::internal
510 512
511 #endif // V8_SCOPES_H_ 513 #endif // V8_SCOPES_H_
OLDNEW
« src/compiler.cc ('K') | « src/runtime.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698