Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: src/runtime.cc

Issue 7849017: Mechanical refactor to move ElementsKind type out of JSObject. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: latest changes Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/objects-inl.h ('k') | src/stub-cache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 if (!maybe_result->ToObject(&result)) return maybe_result; 170 if (!maybe_result->ToObject(&result)) return maybe_result;
171 } 171 }
172 } 172 }
173 } 173 }
174 } 174 }
175 175
176 // Deep copy local elements. 176 // Deep copy local elements.
177 // Pixel elements cannot be created using an object literal. 177 // Pixel elements cannot be created using an object literal.
178 ASSERT(!copy->HasExternalArrayElements()); 178 ASSERT(!copy->HasExternalArrayElements());
179 switch (copy->GetElementsKind()) { 179 switch (copy->GetElementsKind()) {
180 case JSObject::FAST_ELEMENTS: { 180 case FAST_ELEMENTS: {
181 FixedArray* elements = FixedArray::cast(copy->elements()); 181 FixedArray* elements = FixedArray::cast(copy->elements());
182 if (elements->map() == heap->fixed_cow_array_map()) { 182 if (elements->map() == heap->fixed_cow_array_map()) {
183 isolate->counters()->cow_arrays_created_runtime()->Increment(); 183 isolate->counters()->cow_arrays_created_runtime()->Increment();
184 #ifdef DEBUG 184 #ifdef DEBUG
185 for (int i = 0; i < elements->length(); i++) { 185 for (int i = 0; i < elements->length(); i++) {
186 ASSERT(!elements->get(i)->IsJSObject()); 186 ASSERT(!elements->get(i)->IsJSObject());
187 } 187 }
188 #endif 188 #endif
189 } else { 189 } else {
190 for (int i = 0; i < elements->length(); i++) { 190 for (int i = 0; i < elements->length(); i++) {
191 Object* value = elements->get(i); 191 Object* value = elements->get(i);
192 if (value->IsJSObject()) { 192 if (value->IsJSObject()) {
193 JSObject* js_object = JSObject::cast(value); 193 JSObject* js_object = JSObject::cast(value);
194 { MaybeObject* maybe_result = DeepCopyBoilerplate(isolate, 194 { MaybeObject* maybe_result = DeepCopyBoilerplate(isolate,
195 js_object); 195 js_object);
196 if (!maybe_result->ToObject(&result)) return maybe_result; 196 if (!maybe_result->ToObject(&result)) return maybe_result;
197 } 197 }
198 elements->set(i, result); 198 elements->set(i, result);
199 } 199 }
200 } 200 }
201 } 201 }
202 break; 202 break;
203 } 203 }
204 case JSObject::DICTIONARY_ELEMENTS: { 204 case DICTIONARY_ELEMENTS: {
205 NumberDictionary* element_dictionary = copy->element_dictionary(); 205 NumberDictionary* element_dictionary = copy->element_dictionary();
206 int capacity = element_dictionary->Capacity(); 206 int capacity = element_dictionary->Capacity();
207 for (int i = 0; i < capacity; i++) { 207 for (int i = 0; i < capacity; i++) {
208 Object* k = element_dictionary->KeyAt(i); 208 Object* k = element_dictionary->KeyAt(i);
209 if (element_dictionary->IsKey(k)) { 209 if (element_dictionary->IsKey(k)) {
210 Object* value = element_dictionary->ValueAt(i); 210 Object* value = element_dictionary->ValueAt(i);
211 if (value->IsJSObject()) { 211 if (value->IsJSObject()) {
212 JSObject* js_object = JSObject::cast(value); 212 JSObject* js_object = JSObject::cast(value);
213 { MaybeObject* maybe_result = DeepCopyBoilerplate(isolate, 213 { MaybeObject* maybe_result = DeepCopyBoilerplate(isolate,
214 js_object); 214 js_object);
215 if (!maybe_result->ToObject(&result)) return maybe_result; 215 if (!maybe_result->ToObject(&result)) return maybe_result;
216 } 216 }
217 element_dictionary->ValueAtPut(i, result); 217 element_dictionary->ValueAtPut(i, result);
218 } 218 }
219 } 219 }
220 } 220 }
221 break; 221 break;
222 } 222 }
223 case JSObject::NON_STRICT_ARGUMENTS_ELEMENTS: 223 case NON_STRICT_ARGUMENTS_ELEMENTS:
224 UNIMPLEMENTED(); 224 UNIMPLEMENTED();
225 break; 225 break;
226 case JSObject::EXTERNAL_PIXEL_ELEMENTS: 226 case EXTERNAL_PIXEL_ELEMENTS:
227 case JSObject::EXTERNAL_BYTE_ELEMENTS: 227 case EXTERNAL_BYTE_ELEMENTS:
228 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS: 228 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
229 case JSObject::EXTERNAL_SHORT_ELEMENTS: 229 case EXTERNAL_SHORT_ELEMENTS:
230 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS: 230 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
231 case JSObject::EXTERNAL_INT_ELEMENTS: 231 case EXTERNAL_INT_ELEMENTS:
232 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS: 232 case EXTERNAL_UNSIGNED_INT_ELEMENTS:
233 case JSObject::EXTERNAL_FLOAT_ELEMENTS: 233 case EXTERNAL_FLOAT_ELEMENTS:
234 case JSObject::EXTERNAL_DOUBLE_ELEMENTS: 234 case EXTERNAL_DOUBLE_ELEMENTS:
235 case JSObject::FAST_DOUBLE_ELEMENTS: 235 case FAST_DOUBLE_ELEMENTS:
236 // No contained objects, nothing to do. 236 // No contained objects, nothing to do.
237 break; 237 break;
238 } 238 }
239 return copy; 239 return copy;
240 } 240 }
241 241
242 242
243 RUNTIME_FUNCTION(MaybeObject*, Runtime_CloneLiteralBoilerplate) { 243 RUNTIME_FUNCTION(MaybeObject*, Runtime_CloneLiteralBoilerplate) {
244 CONVERT_CHECKED(JSObject, boilerplate, args[0]); 244 CONVERT_CHECKED(JSObject, boilerplate, args[0]);
245 return DeepCopyBoilerplate(isolate, boilerplate); 245 return DeepCopyBoilerplate(isolate, boilerplate);
(...skipping 4047 matching lines...) Expand 10 before | Expand all | Expand 10 after
4293 if (proto->IsNull()) return *obj_value; 4293 if (proto->IsNull()) return *obj_value;
4294 js_object = Handle<JSObject>::cast(proto); 4294 js_object = Handle<JSObject>::cast(proto);
4295 } 4295 }
4296 Handle<NumberDictionary> dictionary = NormalizeElements(js_object); 4296 Handle<NumberDictionary> dictionary = NormalizeElements(js_object);
4297 // Make sure that we never go back to fast case. 4297 // Make sure that we never go back to fast case.
4298 dictionary->set_requires_slow_elements(); 4298 dictionary->set_requires_slow_elements();
4299 PropertyDetails details = PropertyDetails(attr, NORMAL); 4299 PropertyDetails details = PropertyDetails(attr, NORMAL);
4300 Handle<NumberDictionary> extended_dictionary = 4300 Handle<NumberDictionary> extended_dictionary =
4301 NumberDictionarySet(dictionary, index, obj_value, details); 4301 NumberDictionarySet(dictionary, index, obj_value, details);
4302 if (*extended_dictionary != *dictionary) { 4302 if (*extended_dictionary != *dictionary) {
4303 if (js_object->GetElementsKind() == 4303 if (js_object->GetElementsKind() == NON_STRICT_ARGUMENTS_ELEMENTS) {
4304 JSObject::NON_STRICT_ARGUMENTS_ELEMENTS) {
4305 FixedArray::cast(js_object->elements())->set(1, *extended_dictionary); 4304 FixedArray::cast(js_object->elements())->set(1, *extended_dictionary);
4306 } else { 4305 } else {
4307 js_object->set_elements(*extended_dictionary); 4306 js_object->set_elements(*extended_dictionary);
4308 } 4307 }
4309 } 4308 }
4310 return *obj_value; 4309 return *obj_value;
4311 } 4310 }
4312 4311
4313 LookupResult result; 4312 LookupResult result;
4314 js_object->LocalLookupRealNamedProperty(*name, &result); 4313 js_object->LocalLookupRealNamedProperty(*name, &result);
(...skipping 3448 matching lines...) Expand 10 before | Expand all | Expand 10 after
7763 if (parameter_count > 0) { 7762 if (parameter_count > 0) {
7764 int mapped_count = Min(argument_count, parameter_count); 7763 int mapped_count = Min(argument_count, parameter_count);
7765 Handle<FixedArray> parameter_map = 7764 Handle<FixedArray> parameter_map =
7766 isolate->factory()->NewFixedArray(mapped_count + 2, NOT_TENURED); 7765 isolate->factory()->NewFixedArray(mapped_count + 2, NOT_TENURED);
7767 parameter_map->set_map( 7766 parameter_map->set_map(
7768 isolate->heap()->non_strict_arguments_elements_map()); 7767 isolate->heap()->non_strict_arguments_elements_map());
7769 7768
7770 Handle<Map> old_map(result->map()); 7769 Handle<Map> old_map(result->map());
7771 Handle<Map> new_map = 7770 Handle<Map> new_map =
7772 isolate->factory()->CopyMapDropTransitions(old_map); 7771 isolate->factory()->CopyMapDropTransitions(old_map);
7773 new_map->set_elements_kind(JSObject::NON_STRICT_ARGUMENTS_ELEMENTS); 7772 new_map->set_elements_kind(NON_STRICT_ARGUMENTS_ELEMENTS);
7774 7773
7775 result->set_map(*new_map); 7774 result->set_map(*new_map);
7776 result->set_elements(*parameter_map); 7775 result->set_elements(*parameter_map);
7777 7776
7778 // Store the context and the arguments array at the beginning of the 7777 // Store the context and the arguments array at the beginning of the
7779 // parameter map. 7778 // parameter map.
7780 Handle<Context> context(isolate->context()); 7779 Handle<Context> context(isolate->context());
7781 Handle<FixedArray> arguments = 7780 Handle<FixedArray> arguments =
7782 isolate->factory()->NewFixedArray(argument_count, NOT_TENURED); 7781 isolate->factory()->NewFixedArray(argument_count, NOT_TENURED);
7783 parameter_map->set(0, *context); 7782 parameter_map->set(0, *context);
(...skipping 1677 matching lines...) Expand 10 before | Expand all | Expand 10 after
9461 // JSObject::kMaxElementCount. 9460 // JSObject::kMaxElementCount.
9462 uint32_t index_offset_; 9461 uint32_t index_offset_;
9463 bool fast_elements_; 9462 bool fast_elements_;
9464 }; 9463 };
9465 9464
9466 9465
9467 static uint32_t EstimateElementCount(Handle<JSArray> array) { 9466 static uint32_t EstimateElementCount(Handle<JSArray> array) {
9468 uint32_t length = static_cast<uint32_t>(array->length()->Number()); 9467 uint32_t length = static_cast<uint32_t>(array->length()->Number());
9469 int element_count = 0; 9468 int element_count = 0;
9470 switch (array->GetElementsKind()) { 9469 switch (array->GetElementsKind()) {
9471 case JSObject::FAST_ELEMENTS: { 9470 case FAST_ELEMENTS: {
9472 // Fast elements can't have lengths that are not representable by 9471 // Fast elements can't have lengths that are not representable by
9473 // a 32-bit signed integer. 9472 // a 32-bit signed integer.
9474 ASSERT(static_cast<int32_t>(FixedArray::kMaxLength) >= 0); 9473 ASSERT(static_cast<int32_t>(FixedArray::kMaxLength) >= 0);
9475 int fast_length = static_cast<int>(length); 9474 int fast_length = static_cast<int>(length);
9476 Handle<FixedArray> elements(FixedArray::cast(array->elements())); 9475 Handle<FixedArray> elements(FixedArray::cast(array->elements()));
9477 for (int i = 0; i < fast_length; i++) { 9476 for (int i = 0; i < fast_length; i++) {
9478 if (!elements->get(i)->IsTheHole()) element_count++; 9477 if (!elements->get(i)->IsTheHole()) element_count++;
9479 } 9478 }
9480 break; 9479 break;
9481 } 9480 }
9482 case JSObject::DICTIONARY_ELEMENTS: { 9481 case DICTIONARY_ELEMENTS: {
9483 Handle<NumberDictionary> dictionary( 9482 Handle<NumberDictionary> dictionary(
9484 NumberDictionary::cast(array->elements())); 9483 NumberDictionary::cast(array->elements()));
9485 int capacity = dictionary->Capacity(); 9484 int capacity = dictionary->Capacity();
9486 for (int i = 0; i < capacity; i++) { 9485 for (int i = 0; i < capacity; i++) {
9487 Handle<Object> key(dictionary->KeyAt(i)); 9486 Handle<Object> key(dictionary->KeyAt(i));
9488 if (dictionary->IsKey(*key)) { 9487 if (dictionary->IsKey(*key)) {
9489 element_count++; 9488 element_count++;
9490 } 9489 }
9491 } 9490 }
9492 break; 9491 break;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
9548 static int compareUInt32(const uint32_t* ap, const uint32_t* bp) { 9547 static int compareUInt32(const uint32_t* ap, const uint32_t* bp) {
9549 uint32_t a = *ap; 9548 uint32_t a = *ap;
9550 uint32_t b = *bp; 9549 uint32_t b = *bp;
9551 return (a == b) ? 0 : (a < b) ? -1 : 1; 9550 return (a == b) ? 0 : (a < b) ? -1 : 1;
9552 } 9551 }
9553 9552
9554 9553
9555 static void CollectElementIndices(Handle<JSObject> object, 9554 static void CollectElementIndices(Handle<JSObject> object,
9556 uint32_t range, 9555 uint32_t range,
9557 List<uint32_t>* indices) { 9556 List<uint32_t>* indices) {
9558 JSObject::ElementsKind kind = object->GetElementsKind(); 9557 ElementsKind kind = object->GetElementsKind();
9559 switch (kind) { 9558 switch (kind) {
9560 case JSObject::FAST_ELEMENTS: { 9559 case FAST_ELEMENTS: {
9561 Handle<FixedArray> elements(FixedArray::cast(object->elements())); 9560 Handle<FixedArray> elements(FixedArray::cast(object->elements()));
9562 uint32_t length = static_cast<uint32_t>(elements->length()); 9561 uint32_t length = static_cast<uint32_t>(elements->length());
9563 if (range < length) length = range; 9562 if (range < length) length = range;
9564 for (uint32_t i = 0; i < length; i++) { 9563 for (uint32_t i = 0; i < length; i++) {
9565 if (!elements->get(i)->IsTheHole()) { 9564 if (!elements->get(i)->IsTheHole()) {
9566 indices->Add(i); 9565 indices->Add(i);
9567 } 9566 }
9568 } 9567 }
9569 break; 9568 break;
9570 } 9569 }
9571 case JSObject::DICTIONARY_ELEMENTS: { 9570 case DICTIONARY_ELEMENTS: {
9572 Handle<NumberDictionary> dict(NumberDictionary::cast(object->elements())); 9571 Handle<NumberDictionary> dict(NumberDictionary::cast(object->elements()));
9573 uint32_t capacity = dict->Capacity(); 9572 uint32_t capacity = dict->Capacity();
9574 for (uint32_t j = 0; j < capacity; j++) { 9573 for (uint32_t j = 0; j < capacity; j++) {
9575 HandleScope loop_scope; 9574 HandleScope loop_scope;
9576 Handle<Object> k(dict->KeyAt(j)); 9575 Handle<Object> k(dict->KeyAt(j));
9577 if (dict->IsKey(*k)) { 9576 if (dict->IsKey(*k)) {
9578 ASSERT(k->IsNumber()); 9577 ASSERT(k->IsNumber());
9579 uint32_t index = static_cast<uint32_t>(k->Number()); 9578 uint32_t index = static_cast<uint32_t>(k->Number());
9580 if (index < range) { 9579 if (index < range) {
9581 indices->Add(index); 9580 indices->Add(index);
9582 } 9581 }
9583 } 9582 }
9584 } 9583 }
9585 break; 9584 break;
9586 } 9585 }
9587 default: { 9586 default: {
9588 int dense_elements_length; 9587 int dense_elements_length;
9589 switch (kind) { 9588 switch (kind) {
9590 case JSObject::EXTERNAL_PIXEL_ELEMENTS: { 9589 case EXTERNAL_PIXEL_ELEMENTS: {
9591 dense_elements_length = 9590 dense_elements_length =
9592 ExternalPixelArray::cast(object->elements())->length(); 9591 ExternalPixelArray::cast(object->elements())->length();
9593 break; 9592 break;
9594 } 9593 }
9595 case JSObject::EXTERNAL_BYTE_ELEMENTS: { 9594 case EXTERNAL_BYTE_ELEMENTS: {
9596 dense_elements_length = 9595 dense_elements_length =
9597 ExternalByteArray::cast(object->elements())->length(); 9596 ExternalByteArray::cast(object->elements())->length();
9598 break; 9597 break;
9599 } 9598 }
9600 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS: { 9599 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: {
9601 dense_elements_length = 9600 dense_elements_length =
9602 ExternalUnsignedByteArray::cast(object->elements())->length(); 9601 ExternalUnsignedByteArray::cast(object->elements())->length();
9603 break; 9602 break;
9604 } 9603 }
9605 case JSObject::EXTERNAL_SHORT_ELEMENTS: { 9604 case EXTERNAL_SHORT_ELEMENTS: {
9606 dense_elements_length = 9605 dense_elements_length =
9607 ExternalShortArray::cast(object->elements())->length(); 9606 ExternalShortArray::cast(object->elements())->length();
9608 break; 9607 break;
9609 } 9608 }
9610 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS: { 9609 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: {
9611 dense_elements_length = 9610 dense_elements_length =
9612 ExternalUnsignedShortArray::cast(object->elements())->length(); 9611 ExternalUnsignedShortArray::cast(object->elements())->length();
9613 break; 9612 break;
9614 } 9613 }
9615 case JSObject::EXTERNAL_INT_ELEMENTS: { 9614 case EXTERNAL_INT_ELEMENTS: {
9616 dense_elements_length = 9615 dense_elements_length =
9617 ExternalIntArray::cast(object->elements())->length(); 9616 ExternalIntArray::cast(object->elements())->length();
9618 break; 9617 break;
9619 } 9618 }
9620 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS: { 9619 case EXTERNAL_UNSIGNED_INT_ELEMENTS: {
9621 dense_elements_length = 9620 dense_elements_length =
9622 ExternalUnsignedIntArray::cast(object->elements())->length(); 9621 ExternalUnsignedIntArray::cast(object->elements())->length();
9623 break; 9622 break;
9624 } 9623 }
9625 case JSObject::EXTERNAL_FLOAT_ELEMENTS: { 9624 case EXTERNAL_FLOAT_ELEMENTS: {
9626 dense_elements_length = 9625 dense_elements_length =
9627 ExternalFloatArray::cast(object->elements())->length(); 9626 ExternalFloatArray::cast(object->elements())->length();
9628 break; 9627 break;
9629 } 9628 }
9630 case JSObject::EXTERNAL_DOUBLE_ELEMENTS: { 9629 case EXTERNAL_DOUBLE_ELEMENTS: {
9631 dense_elements_length = 9630 dense_elements_length =
9632 ExternalDoubleArray::cast(object->elements())->length(); 9631 ExternalDoubleArray::cast(object->elements())->length();
9633 break; 9632 break;
9634 } 9633 }
9635 default: 9634 default:
9636 UNREACHABLE(); 9635 UNREACHABLE();
9637 dense_elements_length = 0; 9636 dense_elements_length = 0;
9638 break; 9637 break;
9639 } 9638 }
9640 uint32_t length = static_cast<uint32_t>(dense_elements_length); 9639 uint32_t length = static_cast<uint32_t>(dense_elements_length);
(...skipping 28 matching lines...) Expand all
9669 * with the element index and the element's value. 9668 * with the element index and the element's value.
9670 * Afterwards it increments the base-index of the visitor by the array 9669 * Afterwards it increments the base-index of the visitor by the array
9671 * length. 9670 * length.
9672 * Returns false if any access threw an exception, otherwise true. 9671 * Returns false if any access threw an exception, otherwise true.
9673 */ 9672 */
9674 static bool IterateElements(Isolate* isolate, 9673 static bool IterateElements(Isolate* isolate,
9675 Handle<JSArray> receiver, 9674 Handle<JSArray> receiver,
9676 ArrayConcatVisitor* visitor) { 9675 ArrayConcatVisitor* visitor) {
9677 uint32_t length = static_cast<uint32_t>(receiver->length()->Number()); 9676 uint32_t length = static_cast<uint32_t>(receiver->length()->Number());
9678 switch (receiver->GetElementsKind()) { 9677 switch (receiver->GetElementsKind()) {
9679 case JSObject::FAST_ELEMENTS: { 9678 case FAST_ELEMENTS: {
9680 // Run through the elements FixedArray and use HasElement and GetElement 9679 // Run through the elements FixedArray and use HasElement and GetElement
9681 // to check the prototype for missing elements. 9680 // to check the prototype for missing elements.
9682 Handle<FixedArray> elements(FixedArray::cast(receiver->elements())); 9681 Handle<FixedArray> elements(FixedArray::cast(receiver->elements()));
9683 int fast_length = static_cast<int>(length); 9682 int fast_length = static_cast<int>(length);
9684 ASSERT(fast_length <= elements->length()); 9683 ASSERT(fast_length <= elements->length());
9685 for (int j = 0; j < fast_length; j++) { 9684 for (int j = 0; j < fast_length; j++) {
9686 HandleScope loop_scope(isolate); 9685 HandleScope loop_scope(isolate);
9687 Handle<Object> element_value(elements->get(j), isolate); 9686 Handle<Object> element_value(elements->get(j), isolate);
9688 if (!element_value->IsTheHole()) { 9687 if (!element_value->IsTheHole()) {
9689 visitor->visit(j, element_value); 9688 visitor->visit(j, element_value);
9690 } else if (receiver->HasElement(j)) { 9689 } else if (receiver->HasElement(j)) {
9691 // Call GetElement on receiver, not its prototype, or getters won't 9690 // Call GetElement on receiver, not its prototype, or getters won't
9692 // have the correct receiver. 9691 // have the correct receiver.
9693 element_value = GetElement(receiver, j); 9692 element_value = GetElement(receiver, j);
9694 if (element_value.is_null()) return false; 9693 if (element_value.is_null()) return false;
9695 visitor->visit(j, element_value); 9694 visitor->visit(j, element_value);
9696 } 9695 }
9697 } 9696 }
9698 break; 9697 break;
9699 } 9698 }
9700 case JSObject::DICTIONARY_ELEMENTS: { 9699 case DICTIONARY_ELEMENTS: {
9701 Handle<NumberDictionary> dict(receiver->element_dictionary()); 9700 Handle<NumberDictionary> dict(receiver->element_dictionary());
9702 List<uint32_t> indices(dict->Capacity() / 2); 9701 List<uint32_t> indices(dict->Capacity() / 2);
9703 // Collect all indices in the object and the prototypes less 9702 // Collect all indices in the object and the prototypes less
9704 // than length. This might introduce duplicates in the indices list. 9703 // than length. This might introduce duplicates in the indices list.
9705 CollectElementIndices(receiver, length, &indices); 9704 CollectElementIndices(receiver, length, &indices);
9706 indices.Sort(&compareUInt32); 9705 indices.Sort(&compareUInt32);
9707 int j = 0; 9706 int j = 0;
9708 int n = indices.length(); 9707 int n = indices.length();
9709 while (j < n) { 9708 while (j < n) {
9710 HandleScope loop_scope; 9709 HandleScope loop_scope;
9711 uint32_t index = indices[j]; 9710 uint32_t index = indices[j];
9712 Handle<Object> element = GetElement(receiver, index); 9711 Handle<Object> element = GetElement(receiver, index);
9713 if (element.is_null()) return false; 9712 if (element.is_null()) return false;
9714 visitor->visit(index, element); 9713 visitor->visit(index, element);
9715 // Skip to next different index (i.e., omit duplicates). 9714 // Skip to next different index (i.e., omit duplicates).
9716 do { 9715 do {
9717 j++; 9716 j++;
9718 } while (j < n && indices[j] == index); 9717 } while (j < n && indices[j] == index);
9719 } 9718 }
9720 break; 9719 break;
9721 } 9720 }
9722 case JSObject::EXTERNAL_PIXEL_ELEMENTS: { 9721 case EXTERNAL_PIXEL_ELEMENTS: {
9723 Handle<ExternalPixelArray> pixels(ExternalPixelArray::cast( 9722 Handle<ExternalPixelArray> pixels(ExternalPixelArray::cast(
9724 receiver->elements())); 9723 receiver->elements()));
9725 for (uint32_t j = 0; j < length; j++) { 9724 for (uint32_t j = 0; j < length; j++) {
9726 Handle<Smi> e(Smi::FromInt(pixels->get_scalar(j))); 9725 Handle<Smi> e(Smi::FromInt(pixels->get_scalar(j)));
9727 visitor->visit(j, e); 9726 visitor->visit(j, e);
9728 } 9727 }
9729 break; 9728 break;
9730 } 9729 }
9731 case JSObject::EXTERNAL_BYTE_ELEMENTS: { 9730 case EXTERNAL_BYTE_ELEMENTS: {
9732 IterateExternalArrayElements<ExternalByteArray, int8_t>( 9731 IterateExternalArrayElements<ExternalByteArray, int8_t>(
9733 isolate, receiver, true, true, visitor); 9732 isolate, receiver, true, true, visitor);
9734 break; 9733 break;
9735 } 9734 }
9736 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS: { 9735 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: {
9737 IterateExternalArrayElements<ExternalUnsignedByteArray, uint8_t>( 9736 IterateExternalArrayElements<ExternalUnsignedByteArray, uint8_t>(
9738 isolate, receiver, true, true, visitor); 9737 isolate, receiver, true, true, visitor);
9739 break; 9738 break;
9740 } 9739 }
9741 case JSObject::EXTERNAL_SHORT_ELEMENTS: { 9740 case EXTERNAL_SHORT_ELEMENTS: {
9742 IterateExternalArrayElements<ExternalShortArray, int16_t>( 9741 IterateExternalArrayElements<ExternalShortArray, int16_t>(
9743 isolate, receiver, true, true, visitor); 9742 isolate, receiver, true, true, visitor);
9744 break; 9743 break;
9745 } 9744 }
9746 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS: { 9745 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: {
9747 IterateExternalArrayElements<ExternalUnsignedShortArray, uint16_t>( 9746 IterateExternalArrayElements<ExternalUnsignedShortArray, uint16_t>(
9748 isolate, receiver, true, true, visitor); 9747 isolate, receiver, true, true, visitor);
9749 break; 9748 break;
9750 } 9749 }
9751 case JSObject::EXTERNAL_INT_ELEMENTS: { 9750 case EXTERNAL_INT_ELEMENTS: {
9752 IterateExternalArrayElements<ExternalIntArray, int32_t>( 9751 IterateExternalArrayElements<ExternalIntArray, int32_t>(
9753 isolate, receiver, true, false, visitor); 9752 isolate, receiver, true, false, visitor);
9754 break; 9753 break;
9755 } 9754 }
9756 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS: { 9755 case EXTERNAL_UNSIGNED_INT_ELEMENTS: {
9757 IterateExternalArrayElements<ExternalUnsignedIntArray, uint32_t>( 9756 IterateExternalArrayElements<ExternalUnsignedIntArray, uint32_t>(
9758 isolate, receiver, true, false, visitor); 9757 isolate, receiver, true, false, visitor);
9759 break; 9758 break;
9760 } 9759 }
9761 case JSObject::EXTERNAL_FLOAT_ELEMENTS: { 9760 case EXTERNAL_FLOAT_ELEMENTS: {
9762 IterateExternalArrayElements<ExternalFloatArray, float>( 9761 IterateExternalArrayElements<ExternalFloatArray, float>(
9763 isolate, receiver, false, false, visitor); 9762 isolate, receiver, false, false, visitor);
9764 break; 9763 break;
9765 } 9764 }
9766 case JSObject::EXTERNAL_DOUBLE_ELEMENTS: { 9765 case EXTERNAL_DOUBLE_ELEMENTS: {
9767 IterateExternalArrayElements<ExternalDoubleArray, double>( 9766 IterateExternalArrayElements<ExternalDoubleArray, double>(
9768 isolate, receiver, false, false, visitor); 9767 isolate, receiver, false, false, visitor);
9769 break; 9768 break;
9770 } 9769 }
9771 default: 9770 default:
9772 UNREACHABLE(); 9771 UNREACHABLE();
9773 break; 9772 break;
9774 } 9773 }
9775 visitor->increase_index_offset(length); 9774 visitor->increase_index_offset(length);
9776 return true; 9775 return true;
(...skipping 3357 matching lines...) Expand 10 before | Expand all | Expand 10 after
13134 } else { 13133 } else {
13135 // Handle last resort GC and make sure to allow future allocations 13134 // Handle last resort GC and make sure to allow future allocations
13136 // to grow the heap without causing GCs (if possible). 13135 // to grow the heap without causing GCs (if possible).
13137 isolate->counters()->gc_last_resort_from_js()->Increment(); 13136 isolate->counters()->gc_last_resort_from_js()->Increment();
13138 isolate->heap()->CollectAllGarbage(false); 13137 isolate->heap()->CollectAllGarbage(false);
13139 } 13138 }
13140 } 13139 }
13141 13140
13142 13141
13143 } } // namespace v8::internal 13142 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | src/stub-cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698