Chromium Code Reviews| Index: src/ia32/full-codegen-ia32.cc |
| diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc |
| index 72021b4a9d4eeef30ff8f8f818754442ed589061..26363d6dfe205c867146f4e2045cc7757ae2db48 100644 |
| --- a/src/ia32/full-codegen-ia32.cc |
| +++ b/src/ia32/full-codegen-ia32.cc |
| @@ -754,8 +754,7 @@ void FullCodeGenerator::PrepareForBailoutBeforeSplit(Expression* expr, |
| void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { |
| - // The variable in the declaration always resides in the current function |
| - // context. |
| + // The variable in the declaration always resides in the current context. |
| ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); |
| if (generate_debug_code_) { |
| // Check that we're not inside a with or catch context. |
| @@ -884,33 +883,37 @@ void FullCodeGenerator::VisitFunctionDeclaration( |
| void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { |
| - VariableProxy* proxy = declaration->proxy(); |
| - Variable* variable = proxy->var(); |
| - Handle<JSModule> instance = declaration->module()->interface()->Instance(); |
| - ASSERT(!instance.is_null()); |
| + Variable* variable = declaration->proxy()->var(); |
| + ASSERT(variable->location() == Variable::CONTEXT); |
| + ASSERT(variable->interface()->IsFrozen()); |
| - switch (variable->location()) { |
| - case Variable::UNALLOCATED: { |
| - Comment cmnt(masm_, "[ ModuleDeclaration"); |
| - globals_->Add(variable->name(), zone()); |
| - globals_->Add(instance, zone()); |
| - Visit(declaration->module()); |
| - break; |
| - } |
| + Comment cmnt(masm_, "[ ModuleDeclaration"); |
| + EmitDebugCheckDeclarationContext(variable); |
| - case Variable::CONTEXT: { |
| - Comment cmnt(masm_, "[ ModuleDeclaration"); |
| - EmitDebugCheckDeclarationContext(variable); |
| - __ mov(ContextOperand(esi, variable->index()), Immediate(instance)); |
| - Visit(declaration->module()); |
| - break; |
| - } |
| + // Find hosting scope. |
| + Scope* host = scope_; |
| + while (host->is_module_scope()) host = host->outer_scope(); |
|
Michael Starzinger
2012/11/20 12:05:05
Can we move this into a Scope::GlobalScope() helpe
rossberg
2012/11/20 17:23:45
Done.
|
| + ASSERT(host->is_global_scope()); |
| - case Variable::PARAMETER: |
| - case Variable::LOCAL: |
| - case Variable::LOOKUP: |
| - UNREACHABLE(); |
| - } |
| + // Load instance object. |
| + __ LoadContext(eax, scope_->ContextChainLength(host)); |
| + __ mov(eax, ContextOperand(eax, variable->interface()->Index())); |
| + __ mov(eax, ContextOperand(eax, Context::EXTENSION_INDEX)); |
| + |
| + // Assign it. |
| + __ mov(ContextOperand(esi, variable->index()), eax); |
| + // We know that we have written a module, which is not a smi. |
| + __ RecordWriteContextSlot(esi, |
| + Context::SlotOffset(variable->index()), |
| + eax, |
| + ecx, |
| + kDontSaveFPRegs, |
| + EMIT_REMEMBERED_SET, |
| + OMIT_SMI_CHECK); |
| + PrepareForBailoutForId(declaration->proxy()->id(), NO_REGISTERS); |
| + |
| + // Traverse into body. |
| + Visit(declaration->module()); |
| } |
| @@ -952,6 +955,14 @@ void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
| } |
| +void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) { |
| + // Call the runtime to declare the modules. |
| + __ push(Immediate(descriptions)); |
| + __ CallRuntime(Runtime::kDeclareModules, 1); |
| + // Return value is ignored. |
| +} |
| + |
| + |
| void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { |
| Comment cmnt(masm_, "[ SwitchStatement"); |
| Breakable nested_statement(this, stmt); |
| @@ -1346,9 +1357,9 @@ void FullCodeGenerator::EmitDynamicLookupFastCase(Variable* var, |
| } else if (var->mode() == DYNAMIC_LOCAL) { |
| Variable* local = var->local_if_not_shadowed(); |
| __ mov(eax, ContextSlotOperandCheckExtensions(local, slow)); |
| - if (local->mode() == CONST || |
| - local->mode() == CONST_HARMONY || |
| - local->mode() == LET) { |
| + if (local->mode() == LET || |
| + local->mode() == CONST || |
| + local->mode() == CONST_HARMONY) { |
| __ cmp(eax, isolate()->factory()->the_hole_value()); |
| __ j(not_equal, done); |
| if (local->mode() == CONST) { |