libraries/v8/runtime.cc
/**
 * A helper function that visits elements of a JSArray in numerical
 * order.
 *
 * The visitor argument called for each existing element in the array
 * with the element index and the element's value.
 * Afterwards it increments the base-index of the visitor by the array
 * length.
 * Returns false if any access threw an exception, otherwise true.
 */
A helper function that visits elements of a JSArray in numerical
order.

The visitor argument called for each existing element in the array
with the element index and the element's value.
Afterwards it increments the base-index of the visitor by the array
length.
Returns false if any access threw an exception, otherwise true.
A helper function that visits elements of a JSArray in numerical order . The visitor argument called for each existing element in the array with the element index and the element ' s value . Afterwards it increments the base - index of the visitor by the array length . Returns false if any access threw an exception otherwise true .
static bool IterateElements(Isolate* isolate,
                            Handle<JSArray> receiver,
                            ArrayConcatVisitor* visitor) {
  uint32_t length = static_cast<uint32_t>(receiver->length()->Number());
  switch (receiver->GetElementsKind()) {
    case FAST_SMI_ELEMENTS:
    case FAST_ELEMENTS:
    case FAST_HOLEY_SMI_ELEMENTS:
    case FAST_HOLEY_ELEMENTS: {
      Handle<FixedArray> elements(FixedArray::cast(receiver->elements()));
      int fast_length = static_cast<int>(length);
      ASSERT(fast_length <= elements->length());
      for (int j = 0; j < fast_length; j++) {
        HandleScope loop_scope(isolate);
        Handle<Object> element_value(elements->get(j), isolate);
        if (!element_value->IsTheHole()) {
          visitor->visit(j, element_value);
        } else if (JSReceiver::HasElement(receiver, j)) {
          element_value = Object::GetElement(isolate, receiver, j);
          RETURN_IF_EMPTY_HANDLE_VALUE(isolate, element_value, false);
          visitor->visit(j, element_value);
        }
      }
      break;
    }
    case FAST_HOLEY_DOUBLE_ELEMENTS:
    case FAST_DOUBLE_ELEMENTS: {
      Handle<FixedDoubleArray> elements(
          FixedDoubleArray::cast(receiver->elements()));
      int fast_length = static_cast<int>(length);
      ASSERT(fast_length <= elements->length());
      for (int j = 0; j < fast_length; j++) {
        HandleScope loop_scope(isolate);
        if (!elements->is_the_hole(j)) {
          double double_value = elements->get_scalar(j);
          Handle<Object> element_value =
              isolate->factory()->NewNumber(double_value);
          visitor->visit(j, element_value);
        } else if (JSReceiver::HasElement(receiver, j)) {
          Handle<Object> element_value =
              Object::GetElement(isolate, receiver, j);
          RETURN_IF_EMPTY_HANDLE_VALUE(isolate, element_value, false);
          visitor->visit(j, element_value);
        }
      }
      break;
    }
    case DICTIONARY_ELEMENTS: {
      Handle<SeededNumberDictionary> dict(receiver->element_dictionary());
      List<uint32_t> indices(dict->Capacity() / 2);
      CollectElementIndices(receiver, length, &indices);
      indices.Sort(&compareUInt32);
      int j = 0;
      int n = indices.length();
      while (j < n) {
        HandleScope loop_scope(isolate);
        uint32_t index = indices[j];
        Handle<Object> element = Object::GetElement(isolate, receiver, index);
        RETURN_IF_EMPTY_HANDLE_VALUE(isolate, element, false);
        visitor->visit(index, element);
        do {
          j++;
        } while (j < n && indices[j] == index);
      }
      break;
    }
    case EXTERNAL_PIXEL_ELEMENTS: {
      Handle<ExternalPixelArray> pixels(ExternalPixelArray::cast(
          receiver->elements()));
      for (uint32_t j = 0; j < length; j++) {
        Handle<Smi> e(Smi::FromInt(pixels->get_scalar(j)), isolate);
        visitor->visit(j, e);
      }
      break;
    }
    case EXTERNAL_BYTE_ELEMENTS: {
      IterateExternalArrayElements<ExternalByteArray, int8_t>(
          isolate, receiver, true, true, visitor);
      break;
    }
    case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: {
      IterateExternalArrayElements<ExternalUnsignedByteArray, uint8_t>(
          isolate, receiver, true, true, visitor);
      break;
    }
    case EXTERNAL_SHORT_ELEMENTS: {
      IterateExternalArrayElements<ExternalShortArray, int16_t>(
          isolate, receiver, true, true, visitor);
      break;
    }
    case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: {
      IterateExternalArrayElements<ExternalUnsignedShortArray, uint16_t>(
          isolate, receiver, true, true, visitor);
      break;
    }
    case EXTERNAL_INT_ELEMENTS: {
      IterateExternalArrayElements<ExternalIntArray, int32_t>(
          isolate, receiver, true, false, visitor);
      break;
    }
    case EXTERNAL_UNSIGNED_INT_ELEMENTS: {
      IterateExternalArrayElements<ExternalUnsignedIntArray, uint32_t>(
          isolate, receiver, true, false, visitor);
      break;
    }
    case EXTERNAL_FLOAT_ELEMENTS: {
      IterateExternalArrayElements<ExternalFloatArray, float>(
          isolate, receiver, false, false, visitor);
      break;
    }
    case EXTERNAL_DOUBLE_ELEMENTS: {
      IterateExternalArrayElements<ExternalDoubleArray, double>(
          isolate, receiver, false, false, visitor);
      break;
    }
    default:
      UNREACHABLE();
      break;
  }
  visitor->increase_index_offset(length);
  return true;
}
static bool IterateElements ( Isolate * isolate , Handle < JSArray > receiver , ArrayConcatVisitor * visitor ) { uint32_t length = static_cast < uint32_t > ( receiver -> length ( ) -> Number ( ) ) ; switch ( receiver -> GetElementsKind ( ) ) { case FAST_SMI_ELEMENTS : case FAST_ELEMENTS : case FAST_HOLEY_SMI_ELEMENTS : case FAST_HOLEY_ELEMENTS : { Handle < FixedArray > elements ( FixedArray :: cast ( receiver -> elements ( ) ) ) ; int fast_length = static_cast < int > ( length ) ; ASSERT ( fast_length <= elements -> length ( ) ) ; for ( int j = 0 ; j < fast_length ; j ++ ) { HandleScope loop_scope ( isolate ) ; Handle < Object > element_value ( elements -> get ( j ) , isolate ) ; if ( ! element_value -> IsTheHole ( ) ) { visitor -> visit ( j , element_value ) ; } else if ( JSReceiver :: HasElement ( receiver , j ) ) { element_value = Object :: GetElement ( isolate , receiver , j ) ; RETURN_IF_EMPTY_HANDLE_VALUE ( isolate , element_value , false ) ; visitor -> visit ( j , element_value ) ; } } break ; } case FAST_HOLEY_DOUBLE_ELEMENTS : case FAST_DOUBLE_ELEMENTS : { Handle < FixedDoubleArray > elements ( FixedDoubleArray :: cast ( receiver -> elements ( ) ) ) ; int fast_length = static_cast < int > ( length ) ; ASSERT ( fast_length <= elements -> length ( ) ) ; for ( int j = 0 ; j < fast_length ; j ++ ) { HandleScope loop_scope ( isolate ) ; if ( ! elements -> is_the_hole ( j ) ) { double double_value = elements -> get_scalar ( j ) ; Handle < Object > element_value = isolate -> factory ( ) -> NewNumber ( double_value ) ; visitor -> visit ( j , element_value ) ; } else if ( JSReceiver :: HasElement ( receiver , j ) ) { Handle < Object > element_value = Object :: GetElement ( isolate , receiver , j ) ; RETURN_IF_EMPTY_HANDLE_VALUE ( isolate , element_value , false ) ; visitor -> visit ( j , element_value ) ; } } break ; } case DICTIONARY_ELEMENTS : { Handle < SeededNumberDictionary > dict ( receiver -> element_dictionary ( ) ) ; List < uint32_t > indices ( dict -> Capacity ( ) / 2 ) ; CollectElementIndices ( receiver , length , & indices ) ; indices . Sort ( & compareUInt32 ) ; int j = 0 ; int n = indices . length ( ) ; while ( j < n ) { HandleScope loop_scope ( isolate ) ; uint32_t index = indices [ j ] ; Handle < Object > element = Object :: GetElement ( isolate , receiver , index ) ; RETURN_IF_EMPTY_HANDLE_VALUE ( isolate , element , false ) ; visitor -> visit ( index , element ) ; do { j ++ ; } while ( j < n && indices [ j ] == index ) ; } break ; } case EXTERNAL_PIXEL_ELEMENTS : { Handle < ExternalPixelArray > pixels ( ExternalPixelArray :: cast ( receiver -> elements ( ) ) ) ; for ( uint32_t j = 0 ; j < length ; j ++ ) { Handle < Smi > e ( Smi :: FromInt ( pixels -> get_scalar ( j ) ) , isolate ) ; visitor -> visit ( j , e ) ; } break ; } case EXTERNAL_BYTE_ELEMENTS : { IterateExternalArrayElements < ExternalByteArray , int8_t > ( isolate , receiver , true , true , visitor ) ; break ; } case EXTERNAL_UNSIGNED_BYTE_ELEMENTS : { IterateExternalArrayElements < ExternalUnsignedByteArray , uint8_t > ( isolate , receiver , true , true , visitor ) ; break ; } case EXTERNAL_SHORT_ELEMENTS : { IterateExternalArrayElements < ExternalShortArray , int16_t > ( isolate , receiver , true , true , visitor ) ; break ; } case EXTERNAL_UNSIGNED_SHORT_ELEMENTS : { IterateExternalArrayElements < ExternalUnsignedShortArray , uint16_t > ( isolate , receiver , true , true , visitor ) ; break ; } case EXTERNAL_INT_ELEMENTS : { IterateExternalArrayElements < ExternalIntArray , int32_t > ( isolate , receiver , true , false , visitor ) ; break ; } case EXTERNAL_UNSIGNED_INT_ELEMENTS : { IterateExternalArrayElements < ExternalUnsignedIntArray , uint32_t > ( isolate , receiver , true , false , visitor ) ; break ; } case EXTERNAL_FLOAT_ELEMENTS : { IterateExternalArrayElements < ExternalFloatArray , float > ( isolate , receiver , false , false , visitor ) ; break ; } case EXTERNAL_DOUBLE_ELEMENTS : { IterateExternalArrayElements < ExternalDoubleArray , double > ( isolate , receiver , false , false , visitor ) ; break ; } default : UNREACHABLE ( ) ; break ; } visitor -> increase_index_offset ( length ) ; return true ; }
A helper function that visits elements of a JSArray in numerical
 order.
A helper function that visits elements of a JSArray in numerical order .
// Run through the elements FixedArray and use HasElement and GetElement // to check the prototype for missing elements. // Call GetElement on receiver, not its prototype, or getters won't // have the correct receiver. // Run through the elements FixedArray and use HasElement and GetElement // to check the prototype for missing elements. // Call GetElement on receiver, not its prototype, or getters won't // have the correct receiver. // Collect all indices in the object and the prototypes less // than length. This might introduce duplicates in the indices list. // Skip to next different index (i.e., omit duplicates).