Chromium Code Reviews| Index: src/compiler.cc |
| diff --git a/src/compiler.cc b/src/compiler.cc |
| index 4a5f399677a79ef732009fd27fb5914f57fe5ee4..04fd9c65d4e708e80d4a7ffe911b7f6070b32ae4 100644 |
| --- a/src/compiler.cc |
| +++ b/src/compiler.cc |
| @@ -53,7 +53,7 @@ namespace internal { |
| CompilationInfo::CompilationInfo(Handle<Script> script) |
| : isolate_(script->GetIsolate()), |
| - flags_(0), |
| + flags_(LanguageModeField::encode(CLASSIC_MODE)), |
| function_(NULL), |
| scope_(NULL), |
| script_(script), |
| @@ -66,7 +66,8 @@ CompilationInfo::CompilationInfo(Handle<Script> script) |
| CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info) |
| : isolate_(shared_info->GetIsolate()), |
| - flags_(IsLazy::encode(true)), |
| + flags_(LanguageModeField::encode(CLASSIC_MODE) | |
| + IsLazy::encode(true)), |
| function_(NULL), |
| scope_(NULL), |
| shared_info_(shared_info), |
| @@ -80,7 +81,8 @@ CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info) |
| CompilationInfo::CompilationInfo(Handle<JSFunction> closure) |
| : isolate_(closure->GetIsolate()), |
| - flags_(IsLazy::encode(true)), |
| + flags_(LanguageModeField::encode(CLASSIC_MODE) | |
| + IsLazy::encode(true)), |
| function_(NULL), |
| scope_(NULL), |
| closure_(closure), |
| @@ -533,7 +535,7 @@ Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source, |
| Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source, |
| Handle<Context> context, |
| bool is_global, |
| - StrictModeFlag strict_mode) { |
| + LanguageMode language_mode) { |
| Isolate* isolate = source->GetIsolate(); |
| int source_length = source->length(); |
| isolate->counters()->total_eval_size()->Increment(source_length); |
| @@ -549,7 +551,7 @@ Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source, |
| result = compilation_cache->LookupEval(source, |
| context, |
| is_global, |
| - strict_mode); |
| + language_mode); |
| if (result.is_null()) { |
| // Create a script object describing the script to be compiled. |
| @@ -557,16 +559,20 @@ Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source, |
| CompilationInfo info(script); |
| info.MarkAsEval(); |
| if (is_global) info.MarkAsGlobal(); |
| - info.SetStrictModeFlag(strict_mode); |
| + info.SetLanguageMode(language_mode); |
| info.SetCallingContext(context); |
| result = MakeFunctionInfo(&info); |
| if (!result.is_null()) { |
| CompilationCache* compilation_cache = isolate->compilation_cache(); |
| - // If caller is strict mode, the result must be strict as well, |
| - // but not the other way around. Consider: |
| + // If caller is strict mode, the result must be in strict mode or |
| + // extended mode as well, but not the other way around. Consider: |
| // eval("'use strict'; ..."); |
| - // TODO(keuchel): adapt this for extended mode. |
| - ASSERT(strict_mode == kNonStrictMode || result->strict_mode()); |
| + ASSERT(language_mode != STRICT_MODE || |
| + result->is_strict_or_extended_mode()); |
| + // If caller is in extended mode, the result must also be in |
| + // extended mode. |
| + ASSERT(language_mode != EXTENDED_MODE || |
| + result->is_extended_mode()); |
| compilation_cache->PutEval(source, context, is_global, result); |
| } |
| } |
| @@ -596,14 +602,20 @@ bool Compiler::CompileLazy(CompilationInfo* info) { |
| // parsing statistics. |
| HistogramTimerScope timer(isolate->counters()->compile_lazy()); |
| - // After parsing we know function's strict mode. Remember it. |
| - StrictModeFlag strict_mode = info->function()->strict_mode_flag(); |
| - ASSERT(info->strict_mode_flag() == kNonStrictMode || |
| - info->strict_mode_flag() == strict_mode); |
| - ASSERT(shared->strict_mode_flag() == kNonStrictMode || |
| - shared->strict_mode_flag() == strict_mode); |
| - info->SetStrictModeFlag(strict_mode); |
| - shared->set_strict_mode_flag(strict_mode); |
| + // After parsing we know function's language mode. Remember it. |
| + LanguageMode language_mode = info->function()->language_mode(); |
| + ASSERT(info->language_mode() != STRICT_MODE || |
| + language_mode == STRICT_MODE || |
| + language_mode == EXTENDED_MODE); |
| + ASSERT(info->language_mode() != EXTENDED_MODE || |
| + language_mode == EXTENDED_MODE); |
| + ASSERT(shared->language_mode() != STRICT_MODE || |
| + language_mode == STRICT_MODE || |
| + language_mode == EXTENDED_MODE); |
| + ASSERT(shared->language_mode() != EXTENDED_MODE || |
| + language_mode == EXTENDED_MODE); |
|
rossberg
2011/11/08 15:02:46
These assertions can be simplified, too.
Steven
2011/11/08 16:13:49
Done.
|
| + info->SetLanguageMode(language_mode); |
| + shared->set_language_mode(language_mode); |
| // Compile the code. |
| if (!MakeCode(info)) { |
| @@ -682,7 +694,7 @@ Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, |
| CompilationInfo info(script); |
| info.SetFunction(literal); |
| info.SetScope(literal->scope()); |
| - info.SetStrictModeFlag(literal->scope()->strict_mode_flag()); |
| + info.SetLanguageMode(literal->scope()->language_mode()); |
| LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); |
| // Determine if the function can be lazily compiled. This is necessary to |
| @@ -748,7 +760,7 @@ void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info, |
| lit->has_only_simple_this_property_assignments(), |
| *lit->this_property_assignments()); |
| function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); |
| - function_info->set_strict_mode_flag(lit->strict_mode_flag()); |
| + function_info->set_language_mode(lit->language_mode()); |
| function_info->set_uses_arguments(lit->scope()->arguments() != NULL); |
| function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); |
| } |