Advertisement
Guest User

Untitled

a guest
Sep 30th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void LCodeGen::DoArrayForEach(LArrayForEach* instr) {
  2.   Register receiver = ToRegister(instr->receiver());
  3.   Register function = ToRegister(instr->function());
  4.   Register index = ToRegister(instr->index());
  5.   Register length = ToRegister(instr->length());
  6.   Register scratch = ToRegister(instr->temp());
  7.  
  8.   Label loop, done, body, footer;
  9.  
  10.   ASSERT(function.is(edi));  // Required by InvokeFunction.
  11.  
  12.   __ RecordComment(";;; check JSFunction");
  13.   __ test(function, Immediate(kSmiTagMask));
  14.   DeoptimizeIf(zero, instr->environment());
  15.   __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch);
  16.   DeoptimizeIf(not_equal, instr->environment());
  17.  
  18.   LPointerMap* pointers = instr->pointer_map();
  19.   RecordPosition(pointers->position());
  20.   SafepointGenerator safepoint_generator(
  21.       this, pointers, Safepoint::kLazyDeopt);
  22.   ParameterCount actual(3);
  23.  
  24.   __ mov(length, FieldOperand(receiver, JSArray::kLengthOffset));
  25.   __ mov(scratch, receiver);
  26.   __ mov(receiver, FieldOperand(receiver, JSObject::kElementsOffset));
  27.   __ xor_(index, index);
  28.   __ bind(&loop);
  29.   __ cmp(index, length);
  30.   __ j(above_equal, &done, Label::kNear);
  31.   //How to add stack-check here
  32.   __ mov(edx, Operand(receiver, index, times_half_pointer_size,
  33.                       FixedArray::kHeaderSize - 1));
  34.   __ test(edx, Immediate(kSmiTagMask));
  35.   __ j(zero, &body, Label::kNear);
  36.   __ cmp(FieldOperand(edx, HeapObject::kMapOffset),
  37.          factory()->the_hole_value());
  38.   __ j(equal, &footer, Label::kNear);
  39.   __ bind(&body);
  40.   //(item, index, array)
  41.   __ push(edx);
  42.   __ push(index);
  43.   __ push(scratch);
  44.   __ InvokeFunction(function, actual, CALL_FUNCTION,
  45.                     safepoint_generator, CALL_AS_FUNCTION);
  46.   //todo check that array map didn't change
  47.   __ bind(&footer);
  48.   __ add(index, Immediate(2));
  49.   __ jmp(&loop);
  50.   __ bind(&done);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement