Reviewers: Mads Ager,

Description:
Revert "Reapply change to with/arguments interaction."

Revert this change again.  Somewhat mysteriously we sometimes get empty
contexts that we do not expect in the context chain.

Please review this at http://codereview.chromium.org/6372013/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/arm/code-stubs-arm.cc
  M src/arm/codegen-arm.cc
  M src/arm/full-codegen-arm.cc
  M src/code-stubs.h
  M src/ia32/code-stubs-ia32.cc
  M src/ia32/codegen-ia32.cc
  M src/ia32/full-codegen-ia32.cc
  M src/scopes.cc
  M src/x64/code-stubs-x64.cc
  M src/x64/codegen-x64.cc
  M src/x64/full-codegen-x64.cc
  M test/mjsunit/debug-evaluate-locals.js


Index: src/arm/code-stubs-arm.cc
diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc
index 273a3104f8a558b6746993a1f8c42fe6283c22a2..f0fd09a72f4eee795890ac718941920ed57b9aaa 100644
--- a/src/arm/code-stubs-arm.cc
+++ b/src/arm/code-stubs-arm.cc
@@ -112,9 +112,10 @@ void FastNewClosureStub::Generate(MacroAssembler* masm) {
 void FastNewContextStub::Generate(MacroAssembler* masm) {
   // Try to allocate the context in new space.
   Label gc;
+  int length = slots_ + Context::MIN_CONTEXT_SLOTS;

   // Attempt to allocate the context in new space.
-  __ AllocateInNewSpace(FixedArray::SizeFor(slots_),
+  __ AllocateInNewSpace(FixedArray::SizeFor(length),
                         r0,
                         r1,
                         r2,
@@ -127,7 +128,7 @@ void FastNewContextStub::Generate(MacroAssembler* masm) {
   // Setup the object header.
   __ LoadRoot(r2, Heap::kContextMapRootIndex);
   __ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset));
-  __ mov(r2, Operand(Smi::FromInt(slots_)));
+  __ mov(r2, Operand(Smi::FromInt(length)));
   __ str(r2, FieldMemOperand(r0, FixedArray::kLengthOffset));

   // Setup the fixed slots.
@@ -143,7 +144,7 @@ void FastNewContextStub::Generate(MacroAssembler* masm) {

   // Initialize the rest of the slots to undefined.
   __ LoadRoot(r1, Heap::kUndefinedValueRootIndex);
-  for (int i = Context::MIN_CONTEXT_SLOTS; i < slots_; i++) {
+  for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) {
     __ str(r1, MemOperand(r0, Context::SlotOffset(i)));
   }

Index: src/arm/codegen-arm.cc
diff --git a/src/arm/codegen-arm.cc b/src/arm/codegen-arm.cc
index c5a2b2bbaa461262d80bbd433aa3a8098998ae7a..f76bd358d4c93df8335766f5bd70efc55de6d319 100644
--- a/src/arm/codegen-arm.cc
+++ b/src/arm/codegen-arm.cc
@@ -209,7 +209,7 @@ void CodeGenerator::Generate(CompilationInfo* info) {
     frame_->AllocateStackSlots();

     frame_->AssertIsSpilled();
-    int heap_slots = scope()->num_heap_slots();
+ int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
     if (heap_slots > 0) {
       // Allocate local context.
       // Get outer context and create a new context based on it.
Index: src/arm/full-codegen-arm.cc
diff --git a/src/arm/full-codegen-arm.cc b/src/arm/full-codegen-arm.cc
index eb66527d1f5499f0e3d1e4da9e96fa2a20c5143f..9483b73bf0b0e0b52c9e71680cd5d9d2130da42d 100644
--- a/src/arm/full-codegen-arm.cc
+++ b/src/arm/full-codegen-arm.cc
@@ -92,7 +92,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) {
   bool function_in_register = true;

   // Possibly allocate a local context.
-  int heap_slots = scope()->num_heap_slots();
+  int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
   if (heap_slots > 0) {
     Comment cmnt(masm_, "[ Allocate local context");
     // Argument to NewContext is the function, which is in r1.
Index: src/code-stubs.h
diff --git a/src/code-stubs.h b/src/code-stubs.h
index 0ca5b4dae0ed0b7456fbd8b9cb95dc69a276dbd2..06cffed4912699cd8ac0f7104d63d4d4aba09266 100644
--- a/src/code-stubs.h
+++ b/src/code-stubs.h
@@ -273,21 +273,20 @@ class FastNewClosureStub : public CodeStub {

 class FastNewContextStub : public CodeStub {
  public:
-  // We want no more than 64 different stubs.
-  static const int kMaximumSlots = Context::MIN_CONTEXT_SLOTS + 63;
+  static const int kMaximumSlots = 64;

   explicit FastNewContextStub(int slots) : slots_(slots) {
- ASSERT(slots_ >= Context::MIN_CONTEXT_SLOTS && slots_ <= kMaximumSlots);
+    ASSERT(slots_ > 0 && slots <= kMaximumSlots);
   }

   void Generate(MacroAssembler* masm);

  private:
-  virtual const char* GetName() { return "FastNewContextStub"; }
-  virtual Major MajorKey() { return FastNewContext; }
-  virtual int MinorKey() { return slots_; }
-
   int slots_;
+
+  const char* GetName() { return "FastNewContextStub"; }
+  Major MajorKey() { return FastNewContext; }
+  int MinorKey() { return slots_; }
 };


Index: src/ia32/code-stubs-ia32.cc
diff --git a/src/ia32/code-stubs-ia32.cc b/src/ia32/code-stubs-ia32.cc
index c1747323aeea2f4a61f34d3b46930051de04082f..5f3400f83e8ea649f297fb872325fdfef243355d 100644
--- a/src/ia32/code-stubs-ia32.cc
+++ b/src/ia32/code-stubs-ia32.cc
@@ -91,7 +91,8 @@ void FastNewClosureStub::Generate(MacroAssembler* masm) {
 void FastNewContextStub::Generate(MacroAssembler* masm) {
   // Try to allocate the context in new space.
   Label gc;
-  __ AllocateInNewSpace((slots_ * kPointerSize) + FixedArray::kHeaderSize,
+  int length = slots_ + Context::MIN_CONTEXT_SLOTS;
+  __ AllocateInNewSpace((length * kPointerSize) + FixedArray::kHeaderSize,
                         eax, ebx, ecx, &gc, TAG_OBJECT);

   // Get the function from the stack.
@@ -100,7 +101,7 @@ void FastNewContextStub::Generate(MacroAssembler* masm) {
   // Setup the object header.
__ mov(FieldOperand(eax, HeapObject::kMapOffset), Factory::context_map());
   __ mov(FieldOperand(eax, Context::kLengthOffset),
-         Immediate(Smi::FromInt(slots_)));
+         Immediate(Smi::FromInt(length)));

   // Setup the fixed slots.
   __ Set(ebx, Immediate(0));  // Set to NULL.
@@ -118,7 +119,7 @@ void FastNewContextStub::Generate(MacroAssembler* masm) {

   // Initialize the rest of the slots to undefined.
   __ mov(ebx, Factory::undefined_value());
-  for (int i = Context::MIN_CONTEXT_SLOTS; i < slots_; i++) {
+  for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) {
     __ mov(Operand(eax, Context::SlotOffset(i)), ebx);
   }

Index: src/ia32/codegen-ia32.cc
diff --git a/src/ia32/codegen-ia32.cc b/src/ia32/codegen-ia32.cc
index 28ca5d0dfa5db5d613919ce9befd13c605c62702..2b48b0bc99d2bd5aeec682450b82120395ac21e9 100644
--- a/src/ia32/codegen-ia32.cc
+++ b/src/ia32/codegen-ia32.cc
@@ -209,7 +209,7 @@ void CodeGenerator::Generate(CompilationInfo* info) {
     frame_->AllocateStackSlots();

     // Allocate the local context if needed.
-    int heap_slots = scope()->num_heap_slots();
+ int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
     if (heap_slots > 0) {
       Comment cmnt(masm_, "[ allocate local context");
       // Allocate local context.
Index: src/ia32/full-codegen-ia32.cc
diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc
index 95213d1ebd97ad8332c7982e068a142b187eb415..aa0dafb8383e11418aa109f47bb815b161fb30a7 100644
--- a/src/ia32/full-codegen-ia32.cc
+++ b/src/ia32/full-codegen-ia32.cc
@@ -142,7 +142,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) {
   bool function_in_register = true;

   // Possibly allocate a local context.
-  int heap_slots = scope()->num_heap_slots();
+  int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
   if (heap_slots > 0) {
     Comment cmnt(masm_, "[ Allocate local context");
     // Argument to NewContext is the function, which is still in edi.
Index: src/scopes.cc
diff --git a/src/scopes.cc b/src/scopes.cc
index 50da1faf913cc391ad07f2d672d94e1e2fc241eb..d3f54ad3f2d9ad8b47fefae2d89fd692bd3e2eda 100644
--- a/src/scopes.cc
+++ b/src/scopes.cc
@@ -726,7 +726,6 @@ void Scope::ResolveVariable(Scope* global_scope,
     // Note that we must do a lookup anyway, because if we find one,
     // we must mark that variable as potentially accessed from this
     // inner scope (the property may not be in the 'with' object).
-    if (var != NULL) var->set_is_used(true);
     var = NonLocal(proxy->name(), Variable::DYNAMIC);

   } else {
@@ -834,8 +833,8 @@ bool Scope::MustAllocate(Variable* var) {
   // visible name.
   if ((var->is_this() || var->name()->length() > 0) &&
       (var->is_accessed_from_inner_scope() ||
-       scope_calls_eval_ ||
-       inner_scope_calls_eval_)) {
+       scope_calls_eval_ || inner_scope_calls_eval_ ||
+       scope_contains_with_)) {
     var->set_is_used(true);
   }
   // Global variables do not need to be allocated.
Index: src/x64/code-stubs-x64.cc
diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc
index 61f94bea487a4acef7e811964bfb9985f42bc890..e38591580b10e765c845bc5689d93445b240e8b1 100644
--- a/src/x64/code-stubs-x64.cc
+++ b/src/x64/code-stubs-x64.cc
@@ -91,7 +91,8 @@ void FastNewClosureStub::Generate(MacroAssembler* masm) {
 void FastNewContextStub::Generate(MacroAssembler* masm) {
   // Try to allocate the context in new space.
   Label gc;
-  __ AllocateInNewSpace((slots_ * kPointerSize) + FixedArray::kHeaderSize,
+  int length = slots_ + Context::MIN_CONTEXT_SLOTS;
+  __ AllocateInNewSpace((length * kPointerSize) + FixedArray::kHeaderSize,
                         rax, rbx, rcx, &gc, TAG_OBJECT);

   // Get the function from the stack.
@@ -100,7 +101,7 @@ void FastNewContextStub::Generate(MacroAssembler* masm) {
   // Setup the object header.
   __ LoadRoot(kScratchRegister, Heap::kContextMapRootIndex);
   __ movq(FieldOperand(rax, HeapObject::kMapOffset), kScratchRegister);
- __ Move(FieldOperand(rax, FixedArray::kLengthOffset), Smi::FromInt(slots_)); + __ Move(FieldOperand(rax, FixedArray::kLengthOffset), Smi::FromInt(length));

   // Setup the fixed slots.
   __ Set(rbx, 0);  // Set to NULL.
@@ -115,7 +116,7 @@ void FastNewContextStub::Generate(MacroAssembler* masm) {

   // Initialize the rest of the slots to undefined.
   __ LoadRoot(rbx, Heap::kUndefinedValueRootIndex);
-  for (int i = Context::MIN_CONTEXT_SLOTS; i < slots_; i++) {
+  for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) {
     __ movq(Operand(rax, Context::SlotOffset(i)), rbx);
   }

Index: src/x64/codegen-x64.cc
diff --git a/src/x64/codegen-x64.cc b/src/x64/codegen-x64.cc
index e13b2e9004929de5c6e6b18043445893a5a3f051..bebe4682d65e0fdc5839903d3002f3fb97da0689 100644
--- a/src/x64/codegen-x64.cc
+++ b/src/x64/codegen-x64.cc
@@ -206,7 +206,7 @@ void CodeGenerator::Generate(CompilationInfo* info) {
     frame_->AllocateStackSlots();

     // Allocate the local context if needed.
-    int heap_slots = scope()->num_heap_slots();
+ int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
     if (heap_slots > 0) {
       Comment cmnt(masm_, "[ allocate local context");
       // Allocate local context.
Index: src/x64/full-codegen-x64.cc
diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc
index da1a7aee44b0600b12f38c8d6a92a92caadf9fb4..60efe03db71c6a75d7602b5614501e950427b33c 100644
--- a/src/x64/full-codegen-x64.cc
+++ b/src/x64/full-codegen-x64.cc
@@ -88,7 +88,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) {
   bool function_in_register = true;

   // Possibly allocate a local context.
-  int heap_slots = scope()->num_heap_slots();
+  int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
   if (heap_slots > 0) {
     Comment cmnt(masm_, "[ Allocate local context");
     // Argument to NewContext is the function, which is still in rdi.
Index: test/mjsunit/debug-evaluate-locals.js
diff --git a/test/mjsunit/debug-evaluate-locals.js b/test/mjsunit/debug-evaluate-locals.js index 8430bd3576e7465541fba241e2a76ba657cbf5fa..4b87829169586ed4885bee9236138ecbd51faa87 100644
--- a/test/mjsunit/debug-evaluate-locals.js
+++ b/test/mjsunit/debug-evaluate-locals.js
@@ -34,18 +34,18 @@ exception = false;


 function checkFrame0(name, value) {
-  assertTrue(name == 'a' || name == 'b', 'frame0 name');
+  assertTrue(name == 'a' || name == 'b');
   if (name == 'a') {
     assertEquals(1, value);
-  } else if (name == 'b') {
+  }
+  if (name == 'b') {
     assertEquals(2, value);
   }
 }


 function checkFrame1(name, value) {
-  assertTrue(name == '.arguments' || name == 'arguments' || name == 'a',
-             'frame1 name');
+  assertTrue(name == '.arguments' || name == 'a');
   if (name == 'a') {
     assertEquals(3, value);
   }
@@ -53,10 +53,12 @@ function checkFrame1(name, value) {


 function checkFrame2(name, value) {
-  assertTrue(name == 'a' || name == 'b', 'frame2 name');
+  assertTrue(name == '.arguments' || name == 'a' ||
+             name == 'arguments' || name == 'b');
   if (name == 'a') {
     assertEquals(5, value);
-  } else if (name == 'b') {
+  }
+  if (name == 'b') {
     assertEquals(0, value);
   }
 }
@@ -71,17 +73,18 @@ function listener(event, exec_state, event_data, data) {
       checkFrame0(frame0.localName(0), frame0.localValue(0).value());
       checkFrame0(frame0.localName(1), frame0.localValue(1).value());

-      // Frame 1 has normal variables a and arguments (and the .arguments
-      // variable).
+      // Frame 1 has normal variable a (and the .arguments variable).
       var frame1 = exec_state.frame(1);
       checkFrame1(frame1.localName(0), frame1.localValue(0).value());
       checkFrame1(frame1.localName(1), frame1.localValue(1).value());
-      checkFrame1(frame1.localName(2), frame1.localValue(2).value());

-      // Frame 2 has normal variables a and b.
+      // Frame 2 has normal variables a and b (and both the .arguments and
+      // arguments variable).
       var frame2 = exec_state.frame(2);
       checkFrame2(frame2.localName(0), frame2.localValue(0).value());
       checkFrame2(frame2.localName(1), frame2.localValue(1).value());
+      checkFrame2(frame2.localName(2), frame2.localValue(2).value());
+      checkFrame2(frame2.localName(3), frame2.localValue(3).value());

// Evaluating a and b on frames 0, 1 and 2 produces 1, 2, 3, 4, 5 and 6.
       assertEquals(1, exec_state.frame(0).evaluate('a').value());


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to