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

Side by Side Diff: src/runtime.cc

Issue 3522008: This is a little experiment to move Failure to a superclass above Object... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 2 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/property.h ('k') | src/stub-cache.cc » ('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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 RUNTIME_ASSERT(obj->IsNumber()); \ 95 RUNTIME_ASSERT(obj->IsNumber()); \
96 type name = NumberTo##Type(obj); 96 type name = NumberTo##Type(obj);
97 97
98 // Non-reentrant string buffer for efficient general use in this file. 98 // Non-reentrant string buffer for efficient general use in this file.
99 static StaticResource<StringInputBuffer> runtime_string_input_buffer; 99 static StaticResource<StringInputBuffer> runtime_string_input_buffer;
100 100
101 101
102 MUST_USE_RESULT static Object* DeepCopyBoilerplate(JSObject* boilerplate) { 102 MUST_USE_RESULT static Object* DeepCopyBoilerplate(JSObject* boilerplate) {
103 StackLimitCheck check; 103 StackLimitCheck check;
104 if (check.HasOverflowed()) return Top::StackOverflow(); 104 if (check.HasOverflowed()) return Top::StackOverflow();
105 Object* result;
106 { TryAllocation t = Heap::CopyJSObject(boilerplate);
107 if (!t->ToObject(&result)) return t;
108 }
105 109
106 Object* result = Heap::CopyJSObject(boilerplate);
107 if (result->IsFailure()) return result;
108 JSObject* copy = JSObject::cast(result); 110 JSObject* copy = JSObject::cast(result);
109 111
110 // Deep copy local properties. 112 // Deep copy local properties.
111 if (copy->HasFastProperties()) { 113 if (copy->HasFastProperties()) {
112 FixedArray* properties = copy->properties(); 114 FixedArray* properties = copy->properties();
113 for (int i = 0; i < properties->length(); i++) { 115 for (int i = 0; i < properties->length(); i++) {
114 Object* value = properties->get(i); 116 Object* value = properties->get(i);
115 if (value->IsJSObject()) { 117 if (value->IsJSObject()) {
118 { TryAllocation t = DeepCopyBoilerplate(js_object);
119 if (!t->ToObject(&result)) return t;
120 }
116 JSObject* js_object = JSObject::cast(value); 121 JSObject* js_object = JSObject::cast(value);
117 result = DeepCopyBoilerplate(js_object);
118 if (result->IsFailure()) return result;
119 properties->set(i, result); 122 properties->set(i, result);
120 } 123 }
121 } 124 }
122 int nof = copy->map()->inobject_properties(); 125 int nof = copy->map()->inobject_properties();
123 for (int i = 0; i < nof; i++) { 126 for (int i = 0; i < nof; i++) {
124 Object* value = copy->InObjectPropertyAt(i); 127 Object* value = copy->InObjectPropertyAt(i);
125 if (value->IsJSObject()) { 128 if (value->IsJSObject()) {
129 { TryAllocation t = DeepCopyBoilerplate(js_object);
130 if (!t->ToObject(&result)) return t;
131 }
126 JSObject* js_object = JSObject::cast(value); 132 JSObject* js_object = JSObject::cast(value);
127 result = DeepCopyBoilerplate(js_object);
128 if (result->IsFailure()) return result;
129 copy->InObjectPropertyAtPut(i, result); 133 copy->InObjectPropertyAtPut(i, result);
130 } 134 }
131 } 135 }
136 { TryAllocation t =
137 Heap::AllocateFixedArray(copy->NumberOfLocalProperties(NONE));
138 if (!t->ToObject(&result)) return t;
139 }
132 } else { 140 } else {
133 result = Heap::AllocateFixedArray(copy->NumberOfLocalProperties(NONE));
134 if (result->IsFailure()) return result;
135 FixedArray* names = FixedArray::cast(result); 141 FixedArray* names = FixedArray::cast(result);
136 copy->GetLocalPropertyNames(names, 0); 142 copy->GetLocalPropertyNames(names, 0);
137 for (int i = 0; i < names->length(); i++) { 143 for (int i = 0; i < names->length(); i++) {
138 ASSERT(names->get(i)->IsString()); 144 ASSERT(names->get(i)->IsString());
139 String* key_string = String::cast(names->get(i)); 145 String* key_string = String::cast(names->get(i));
140 PropertyAttributes attributes = 146 PropertyAttributes attributes =
141 copy->GetLocalPropertyAttribute(key_string); 147 copy->GetLocalPropertyAttribute(key_string);
142 // Only deep copy fields from the object literal expression. 148 // Only deep copy fields from the object literal expression.
143 // In particular, don't try to copy the length attribute of 149 // In particular, don't try to copy the length attribute of
144 // an array. 150 // an array.
145 if (attributes != NONE) continue; 151 if (attributes != NONE) continue;
146 Object* value = copy->GetProperty(key_string, &attributes); 152 Object* value = copy->GetProperty(key_string, &attributes);
147 ASSERT(!value->IsFailure()); 153 ASSERT(!value->IsFailure());
148 if (value->IsJSObject()) { 154 if (value->IsJSObject()) {
155 { TryAllocation t = DeepCopyBoilerplate(js_object);
156 if (!t->ToObject(&result)) return t;
157 }
149 JSObject* js_object = JSObject::cast(value); 158 JSObject* js_object = JSObject::cast(value);
150 result = DeepCopyBoilerplate(js_object); 159 { TryAllocation t = copy->SetProperty(key_string, result, NONE);
151 if (result->IsFailure()) return result; 160 if (!t->ToObject(&result)) return t;
152 result = copy->SetProperty(key_string, result, NONE); 161 }
153 if (result->IsFailure()) return result;
154 } 162 }
155 } 163 }
156 } 164 }
157 165
158 // Deep copy local elements. 166 // Deep copy local elements.
159 // Pixel elements cannot be created using an object literal. 167 // Pixel elements cannot be created using an object literal.
160 ASSERT(!copy->HasPixelElements() && !copy->HasExternalArrayElements()); 168 ASSERT(!copy->HasPixelElements() && !copy->HasExternalArrayElements());
161 switch (copy->GetElementsKind()) { 169 switch (copy->GetElementsKind()) {
162 case JSObject::FAST_ELEMENTS: { 170 case JSObject::FAST_ELEMENTS: {
163 FixedArray* elements = FixedArray::cast(copy->elements()); 171 FixedArray* elements = FixedArray::cast(copy->elements());
164 if (elements->map() == Heap::fixed_cow_array_map()) { 172 if (elements->map() == Heap::fixed_cow_array_map()) {
165 Counters::cow_arrays_created_runtime.Increment(); 173 Counters::cow_arrays_created_runtime.Increment();
166 #ifdef DEBUG 174 #ifdef DEBUG
167 for (int i = 0; i < elements->length(); i++) { 175 for (int i = 0; i < elements->length(); i++) {
168 ASSERT(!elements->get(i)->IsJSObject()); 176 ASSERT(!elements->get(i)->IsJSObject());
169 } 177 }
170 #endif 178 #endif
171 } else { 179 } else {
172 for (int i = 0; i < elements->length(); i++) { 180 for (int i = 0; i < elements->length(); i++) {
173 Object* value = elements->get(i); 181 Object* value = elements->get(i);
174 if (value->IsJSObject()) { 182 if (value->IsJSObject()) {
183 { TryAllocation t = DeepCopyBoilerplate(js_object);
184 if (!t->ToObject(&result)) return t;
185 }
175 JSObject* js_object = JSObject::cast(value); 186 JSObject* js_object = JSObject::cast(value);
176 result = DeepCopyBoilerplate(js_object);
177 if (result->IsFailure()) return result;
178 elements->set(i, result); 187 elements->set(i, result);
179 } 188 }
180 } 189 }
181 } 190 }
182 break; 191 break;
183 } 192 }
184 case JSObject::DICTIONARY_ELEMENTS: { 193 case JSObject::DICTIONARY_ELEMENTS: {
185 NumberDictionary* element_dictionary = copy->element_dictionary(); 194 NumberDictionary* element_dictionary = copy->element_dictionary();
186 int capacity = element_dictionary->Capacity(); 195 int capacity = element_dictionary->Capacity();
187 for (int i = 0; i < capacity; i++) { 196 for (int i = 0; i < capacity; i++) {
188 Object* k = element_dictionary->KeyAt(i); 197 Object* k = element_dictionary->KeyAt(i);
189 if (element_dictionary->IsKey(k)) { 198 if (element_dictionary->IsKey(k)) {
190 Object* value = element_dictionary->ValueAt(i); 199 Object* value = element_dictionary->ValueAt(i);
191 if (value->IsJSObject()) { 200 if (value->IsJSObject()) {
201 { TryAllocation t = DeepCopyBoilerplate(js_object);
202 if (!t->ToObject(&result)) return t;
203 }
192 JSObject* js_object = JSObject::cast(value); 204 JSObject* js_object = JSObject::cast(value);
193 result = DeepCopyBoilerplate(js_object);
194 if (result->IsFailure()) return result;
195 element_dictionary->ValueAtPut(i, result); 205 element_dictionary->ValueAtPut(i, result);
196 } 206 }
197 } 207 }
198 } 208 }
199 break; 209 break;
200 } 210 }
201 default: 211 default:
202 UNREACHABLE(); 212 UNREACHABLE();
203 break; 213 break;
204 } 214 }
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 return Heap::CopyJSObject(JSObject::cast(*boilerplate)); 521 return Heap::CopyJSObject(JSObject::cast(*boilerplate));
512 } 522 }
513 523
514 524
515 static Object* Runtime_CreateCatchExtensionObject(Arguments args) { 525 static Object* Runtime_CreateCatchExtensionObject(Arguments args) {
516 ASSERT(args.length() == 2); 526 ASSERT(args.length() == 2);
517 CONVERT_CHECKED(String, key, args[0]); 527 CONVERT_CHECKED(String, key, args[0]);
518 Object* value = args[1]; 528 Object* value = args[1];
519 // Create a catch context extension object. 529 // Create a catch context extension object.
520 JSFunction* constructor = 530 JSFunction* constructor =
531 Object* object;
532 { TryAllocation t = Heap::AllocateJSObject(constructor);
533 if (!t->ToObject(&object)) return t;
534 }
521 Top::context()->global_context()->context_extension_function(); 535 Top::context()->global_context()->context_extension_function();
522 Object* object = Heap::AllocateJSObject(constructor);
523 if (object->IsFailure()) return object;
524 // Assign the exception value to the catch variable and make sure 536 // Assign the exception value to the catch variable and make sure
537 { TryAllocation t =
538 JSObject::cast(object)->SetProperty(key, value, DONT_DELETE);
539 if (!t->ToObject(&value)) return t;
540 }
525 // that the catch variable is DontDelete. 541 // that the catch variable is DontDelete.
526 value = JSObject::cast(object)->SetProperty(key, value, DONT_DELETE);
527 if (value->IsFailure()) return value;
528 return object; 542 return object;
529 } 543 }
530 544
531 545
532 static Object* Runtime_ClassOf(Arguments args) { 546 static Object* Runtime_ClassOf(Arguments args) {
533 NoHandleAllocation ha; 547 NoHandleAllocation ha;
534 ASSERT(args.length() == 1); 548 ASSERT(args.length() == 1);
535 Object* obj = args[0]; 549 Object* obj = args[0];
536 if (!obj->IsJSObject()) return Heap::null_value(); 550 if (!obj->IsJSObject()) return Heap::null_value();
537 return JSObject::cast(obj)->class_name(); 551 return JSObject::cast(obj)->class_name();
(...skipping 22 matching lines...) Expand all
560 CONVERT_CHECKED(JSObject, jsobject, args[0]); 574 CONVERT_CHECKED(JSObject, jsobject, args[0]);
561 CONVERT_CHECKED(JSObject, proto, args[1]); 575 CONVERT_CHECKED(JSObject, proto, args[1]);
562 576
563 // Sanity checks. The old prototype (that we are replacing) could 577 // Sanity checks. The old prototype (that we are replacing) could
564 // theoretically be null, but if it is not null then check that we 578 // theoretically be null, but if it is not null then check that we
565 // didn't already install a hidden prototype here. 579 // didn't already install a hidden prototype here.
566 RUNTIME_ASSERT(!jsobject->GetPrototype()->IsHeapObject() || 580 RUNTIME_ASSERT(!jsobject->GetPrototype()->IsHeapObject() ||
567 !HeapObject::cast(jsobject->GetPrototype())->map()->is_hidden_prototype()); 581 !HeapObject::cast(jsobject->GetPrototype())->map()->is_hidden_prototype());
568 RUNTIME_ASSERT(!proto->map()->is_hidden_prototype()); 582 RUNTIME_ASSERT(!proto->map()->is_hidden_prototype());
569 583
584 Object* map_or_failure;
585 { TryAllocation t = proto->map()->CopyDropTransitions();
586 if (!t->ToObject(&map_or_failure)) return t;
587 }
570 // Allocate up front before we start altering state in case we get a GC. 588 // Allocate up front before we start altering state in case we get a GC.
571 Object* map_or_failure = proto->map()->CopyDropTransitions();
572 if (map_or_failure->IsFailure()) return map_or_failure;
573 Map* new_proto_map = Map::cast(map_or_failure); 589 Map* new_proto_map = Map::cast(map_or_failure);
590 { TryAllocation t = jsobject->map()->CopyDropTransitions();
591 if (!t->ToObject(&map_or_failure)) return t;
592 }
574 593
575 map_or_failure = jsobject->map()->CopyDropTransitions();
576 if (map_or_failure->IsFailure()) return map_or_failure;
577 Map* new_map = Map::cast(map_or_failure); 594 Map* new_map = Map::cast(map_or_failure);
578 595
579 // Set proto's prototype to be the old prototype of the object. 596 // Set proto's prototype to be the old prototype of the object.
580 new_proto_map->set_prototype(jsobject->GetPrototype()); 597 new_proto_map->set_prototype(jsobject->GetPrototype());
581 proto->set_map(new_proto_map); 598 proto->set_map(new_proto_map);
582 new_proto_map->set_is_hidden_prototype(); 599 new_proto_map->set_is_hidden_prototype();
583 600
584 // Set the object's prototype to proto. 601 // Set the object's prototype to proto.
585 new_map->set_prototype(proto); 602 new_map->set_prototype(proto);
586 jsobject->set_map(new_map); 603 jsobject->set_map(new_map);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 GetOwnPropertyImplementation(*obj, *name, &result); 729 GetOwnPropertyImplementation(*obj, *name, &result);
713 730
714 if (!result.IsProperty()) { 731 if (!result.IsProperty()) {
715 return Heap::undefined_value(); 732 return Heap::undefined_value();
716 } 733 }
717 if (result.type() == CALLBACKS) { 734 if (result.type() == CALLBACKS) {
718 Object* structure = result.GetCallbackObject(); 735 Object* structure = result.GetCallbackObject();
719 if (structure->IsProxy() || structure->IsAccessorInfo()) { 736 if (structure->IsProxy() || structure->IsAccessorInfo()) {
720 // Property that is internally implemented as a callback or 737 // Property that is internally implemented as a callback or
721 // an API defined callback. 738 // an API defined callback.
722 Object* value = obj->GetPropertyWithCallback( 739 Object* value;
723 *obj, structure, *name, result.holder()); 740 { TryAllocation t = obj->GetPropertyWithCallback(
724 if (value->IsFailure()) return value; 741 *obj, structure, *name, result.holder());
742 if (!t->ToObject(&value)) return t;
743 }
725 elms->set(IS_ACCESSOR_INDEX, Heap::false_value()); 744 elms->set(IS_ACCESSOR_INDEX, Heap::false_value());
726 elms->set(VALUE_INDEX, value); 745 elms->set(VALUE_INDEX, value);
727 elms->set(WRITABLE_INDEX, Heap::ToBoolean(!result.IsReadOnly())); 746 elms->set(WRITABLE_INDEX, Heap::ToBoolean(!result.IsReadOnly()));
728 } else if (structure->IsFixedArray()) { 747 } else if (structure->IsFixedArray()) {
729 // __defineGetter__/__defineSetter__ callback. 748 // __defineGetter__/__defineSetter__ callback.
730 elms->set(IS_ACCESSOR_INDEX, Heap::true_value()); 749 elms->set(IS_ACCESSOR_INDEX, Heap::true_value());
731 elms->set(GETTER_INDEX, FixedArray::cast(structure)->get(0)); 750 elms->set(GETTER_INDEX, FixedArray::cast(structure)->get(0));
732 elms->set(SETTER_INDEX, FixedArray::cast(structure)->get(1)); 751 elms->set(SETTER_INDEX, FixedArray::cast(structure)->get(1));
733 } else { 752 } else {
734 return Heap::undefined_value(); 753 return Heap::undefined_value();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 return *HeapObject::RawField(templ, offset); 824 return *HeapObject::RawField(templ, offset);
806 } 825 }
807 826
808 827
809 static Object* Runtime_DisableAccessChecks(Arguments args) { 828 static Object* Runtime_DisableAccessChecks(Arguments args) {
810 ASSERT(args.length() == 1); 829 ASSERT(args.length() == 1);
811 CONVERT_CHECKED(HeapObject, object, args[0]); 830 CONVERT_CHECKED(HeapObject, object, args[0]);
812 Map* old_map = object->map(); 831 Map* old_map = object->map();
813 bool needs_access_checks = old_map->is_access_check_needed(); 832 bool needs_access_checks = old_map->is_access_check_needed();
814 if (needs_access_checks) { 833 if (needs_access_checks) {
834 Object* new_map;
835 { TryAllocation t = old_map->CopyDropTransitions();
836 if (!t->ToObject(&new_map)) return t;
837 }
815 // Copy map so it won't interfere constructor's initial map. 838 // Copy map so it won't interfere constructor's initial map.
816 Object* new_map = old_map->CopyDropTransitions();
817 if (new_map->IsFailure()) return new_map;
818 839
819 Map::cast(new_map)->set_is_access_check_needed(false); 840 Map::cast(new_map)->set_is_access_check_needed(false);
820 object->set_map(Map::cast(new_map)); 841 object->set_map(Map::cast(new_map));
821 } 842 }
822 return needs_access_checks ? Heap::true_value() : Heap::false_value(); 843 return needs_access_checks ? Heap::true_value() : Heap::false_value();
823 } 844 }
824 845
825 846
826 static Object* Runtime_EnableAccessChecks(Arguments args) { 847 static Object* Runtime_EnableAccessChecks(Arguments args) {
827 ASSERT(args.length() == 1); 848 ASSERT(args.length() == 1);
828 CONVERT_CHECKED(HeapObject, object, args[0]); 849 CONVERT_CHECKED(HeapObject, object, args[0]);
829 Map* old_map = object->map(); 850 Map* old_map = object->map();
830 if (!old_map->is_access_check_needed()) { 851 if (!old_map->is_access_check_needed()) {
852 Object* new_map;
853 { TryAllocation t = old_map->CopyDropTransitions();
854 if (!t->ToObject(&new_map)) return t;
855 }
831 // Copy map so it won't interfere constructor's initial map. 856 // Copy map so it won't interfere constructor's initial map.
832 Object* new_map = old_map->CopyDropTransitions();
833 if (new_map->IsFailure()) return new_map;
834 857
835 Map::cast(new_map)->set_is_access_check_needed(true); 858 Map::cast(new_map)->set_is_access_check_needed(true);
836 object->set_map(Map::cast(new_map)); 859 object->set_map(Map::cast(new_map));
837 } 860 }
838 return Heap::undefined_value(); 861 return Heap::undefined_value();
839 } 862 }
840 863
841 864
842 static Object* ThrowRedeclarationError(const char* type, Handle<String> name) { 865 static Object* ThrowRedeclarationError(const char* type, Handle<String> name) {
843 HandleScope scope; 866 HandleScope scope;
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 if (result.is_null()) return Failure::Exception(); 1382 if (result.is_null()) return Failure::Exception();
1360 return *result; 1383 return *result;
1361 } 1384 }
1362 1385
1363 1386
1364 static Object* Runtime_RegExpConstructResult(Arguments args) { 1387 static Object* Runtime_RegExpConstructResult(Arguments args) {
1365 ASSERT(args.length() == 3); 1388 ASSERT(args.length() == 3);
1366 CONVERT_SMI_CHECKED(elements_count, args[0]); 1389 CONVERT_SMI_CHECKED(elements_count, args[0]);
1367 if (elements_count > JSArray::kMaxFastElementsLength) { 1390 if (elements_count > JSArray::kMaxFastElementsLength) {
1368 return Top::ThrowIllegalOperation(); 1391 return Top::ThrowIllegalOperation();
1392 Object* new_object;
1393 { TryAllocation t = Heap::AllocateFixedArrayWithHoles(elements_count);
1394 if (!t->ToObject(&new_object)) return t;
1369 } 1395 }
1370 Object* new_object = Heap::AllocateFixedArrayWithHoles(elements_count); 1396 }
1371 if (new_object->IsFailure()) return new_object;
1372 FixedArray* elements = FixedArray::cast(new_object); 1397 FixedArray* elements = FixedArray::cast(new_object);
1373 new_object = Heap::AllocateRaw(JSRegExpResult::kSize, 1398 new_object = Heap::AllocateRaw(JSRegExpResult::kSize,
1374 NEW_SPACE, 1399 NEW_SPACE,
1375 OLD_POINTER_SPACE); 1400 OLD_POINTER_SPACE);
1376 if (new_object->IsFailure()) return new_object; 1401 if (new_object->IsFailure()) return new_object;
1377 { 1402 {
1378 AssertNoAllocation no_gc; 1403 AssertNoAllocation no_gc;
1379 HandleScope scope; 1404 HandleScope scope;
1380 reinterpret_cast<HeapObject*>(new_object)-> 1405 reinterpret_cast<HeapObject*>(new_object)->
1381 set_map(Top::global_context()->regexp_result_map()); 1406 set_map(Top::global_context()->regexp_result_map());
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 CONVERT_CHECKED(String, name, args[1]); 1627 CONVERT_CHECKED(String, name, args[1]);
1603 f->shared()->set_name(name); 1628 f->shared()->set_name(name);
1604 return Heap::undefined_value(); 1629 return Heap::undefined_value();
1605 } 1630 }
1606 1631
1607 1632
1608 static Object* Runtime_FunctionRemovePrototype(Arguments args) { 1633 static Object* Runtime_FunctionRemovePrototype(Arguments args) {
1609 NoHandleAllocation ha; 1634 NoHandleAllocation ha;
1610 ASSERT(args.length() == 1); 1635 ASSERT(args.length() == 1);
1611 1636
1637 Object* obj;
1638 { TryAllocation t = f->RemovePrototype();
1639 if (!t->ToObject(&obj)) return t;
1640 }
1612 CONVERT_CHECKED(JSFunction, f, args[0]); 1641 CONVERT_CHECKED(JSFunction, f, args[0]);
1613 Object* obj = f->RemovePrototype();
1614 if (obj->IsFailure()) return obj;
1615 1642
1616 return Heap::undefined_value(); 1643 return Heap::undefined_value();
1617 } 1644 }
1618 1645
1619 1646
1620 static Object* Runtime_FunctionGetScript(Arguments args) { 1647 static Object* Runtime_FunctionGetScript(Arguments args) {
1621 HandleScope scope; 1648 HandleScope scope;
1622 ASSERT(args.length() == 1); 1649 ASSERT(args.length() == 1);
1623 1650
1624 CONVERT_CHECKED(JSFunction, fun, args[0]); 1651 CONVERT_CHECKED(JSFunction, fun, args[0]);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 fun->shared()->set_length(length->value()); 1710 fun->shared()->set_length(length->value());
1684 return length; 1711 return length;
1685 } 1712 }
1686 1713
1687 1714
1688 static Object* Runtime_FunctionSetPrototype(Arguments args) { 1715 static Object* Runtime_FunctionSetPrototype(Arguments args) {
1689 NoHandleAllocation ha; 1716 NoHandleAllocation ha;
1690 ASSERT(args.length() == 2); 1717 ASSERT(args.length() == 2);
1691 1718
1692 CONVERT_CHECKED(JSFunction, fun, args[0]); 1719 CONVERT_CHECKED(JSFunction, fun, args[0]);
1720 Object* obj;
1721 { TryAllocation t = Accessors::FunctionSetPrototype(fun, args[1], NULL);
1722 if (!t->ToObject(&obj)) return t;
1723 }
1693 ASSERT(fun->should_have_prototype()); 1724 ASSERT(fun->should_have_prototype());
1694 Object* obj = Accessors::FunctionSetPrototype(fun, args[1], NULL);
1695 if (obj->IsFailure()) return obj;
1696 return args[0]; // return TOS 1725 return args[0]; // return TOS
1697 } 1726 }
1698 1727
1699 1728
1700 static Object* Runtime_FunctionIsAPIFunction(Arguments args) { 1729 static Object* Runtime_FunctionIsAPIFunction(Arguments args) {
1701 NoHandleAllocation ha; 1730 NoHandleAllocation ha;
1702 ASSERT(args.length() == 1); 1731 ASSERT(args.length() == 1);
1703 1732
1704 CONVERT_CHECKED(JSFunction, f, args[0]); 1733 CONVERT_CHECKED(JSFunction, f, args[0]);
1705 return f->shared()->IsApiFunction() ? Heap::true_value() 1734 return f->shared()->IsApiFunction() ? Heap::true_value()
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1808 if (value < 0) return Heap::nan_value(); 1837 if (value < 0) return Heap::nan_value();
1809 i = value; 1838 i = value;
1810 } else { 1839 } else {
1811 ASSERT(index->IsHeapNumber()); 1840 ASSERT(index->IsHeapNumber());
1812 double value = HeapNumber::cast(index)->value(); 1841 double value = HeapNumber::cast(index)->value();
1813 i = static_cast<uint32_t>(DoubleToInteger(value)); 1842 i = static_cast<uint32_t>(DoubleToInteger(value));
1814 } 1843 }
1815 1844
1816 // Flatten the string. If someone wants to get a char at an index 1845 // Flatten the string. If someone wants to get a char at an index
1817 // in a cons string, it is likely that more indices will be 1846 // in a cons string, it is likely that more indices will be
1847 Object* flat;
1848 { TryAllocation t = subject->TryFlatten();
1849 if (!t->ToObject(&flat)) return t;
1850 }
1818 // accessed. 1851 // accessed.
1819 Object* flat = subject->TryFlatten();
1820 if (flat->IsFailure()) return flat;
1821 subject = String::cast(flat); 1852 subject = String::cast(flat);
1822 1853
1823 if (i >= static_cast<uint32_t>(subject->length())) { 1854 if (i >= static_cast<uint32_t>(subject->length())) {
1824 return Heap::nan_value(); 1855 return Heap::nan_value();
1825 } 1856 }
1826 1857
1827 return Smi::FromInt(subject->Get(i)); 1858 return Smi::FromInt(subject->Get(i));
1828 } 1859 }
1829 1860
1830 1861
(...skipping 1670 matching lines...) Expand 10 before | Expand all | Expand 10 after
3501 RUNTIME_ASSERT(!obj->IsNull()); 3532 RUNTIME_ASSERT(!obj->IsNull());
3502 LookupResult result; 3533 LookupResult result;
3503 obj->LocalLookupRealNamedProperty(name, &result); 3534 obj->LocalLookupRealNamedProperty(name, &result);
3504 3535
3505 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked); 3536 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked);
3506 // If an existing property is either FIELD, NORMAL or CONSTANT_FUNCTION 3537 // If an existing property is either FIELD, NORMAL or CONSTANT_FUNCTION
3507 // delete it to avoid running into trouble in DefineAccessor, which 3538 // delete it to avoid running into trouble in DefineAccessor, which
3508 // handles this incorrectly if the property is readonly (does nothing) 3539 // handles this incorrectly if the property is readonly (does nothing)
3509 if (result.IsProperty() && 3540 if (result.IsProperty() &&
3510 (result.type() == FIELD || result.type() == NORMAL 3541 (result.type() == FIELD || result.type() == NORMAL
3542 Object* ok;
3543 { TryAllocation t = obj->DeleteProperty(name, JSObject::NORMAL_DELETION);
3544 if (!t->ToObject(&ok)) return t;
3545 }
3511 || result.type() == CONSTANT_FUNCTION)) { 3546 || result.type() == CONSTANT_FUNCTION)) {
3512 Object* ok = obj->DeleteProperty(name, JSObject::NORMAL_DELETION);
3513 if (ok->IsFailure()) return ok;
3514 } 3547 }
3515 return obj->DefineAccessor(name, flag_setter->value() == 0, fun, attr); 3548 return obj->DefineAccessor(name, flag_setter->value() == 0, fun, attr);
3516 } 3549 }
3517 3550
3518 static Object* Runtime_DefineOrRedefineDataProperty(Arguments args) { 3551 static Object* Runtime_DefineOrRedefineDataProperty(Arguments args) {
3519 ASSERT(args.length() == 4); 3552 ASSERT(args.length() == 4);
3520 HandleScope scope; 3553 HandleScope scope;
3521 CONVERT_ARG_CHECKED(JSObject, js_object, 0); 3554 CONVERT_ARG_CHECKED(JSObject, js_object, 0);
3522 CONVERT_ARG_CHECKED(String, name, 1); 3555 CONVERT_ARG_CHECKED(String, name, 1);
3523 Handle<Object> obj_value = args.at<Object>(2); 3556 Handle<Object> obj_value = args.at<Object>(2);
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after
4378 ASSERT(String::kMaxLength < 0x7fffffff - 6); // Cannot overflow. 4411 ASSERT(String::kMaxLength < 0x7fffffff - 6); // Cannot overflow.
4379 if (escaped_length > String::kMaxLength) { 4412 if (escaped_length > String::kMaxLength) {
4380 Top::context()->mark_out_of_memory(); 4413 Top::context()->mark_out_of_memory();
4381 return Failure::OutOfMemoryException(); 4414 return Failure::OutOfMemoryException();
4382 } 4415 }
4383 } 4416 }
4384 } 4417 }
4385 // No length change implies no change. Return original string if no change. 4418 // No length change implies no change. Return original string if no change.
4386 if (escaped_length == length) { 4419 if (escaped_length == length) {
4387 return source; 4420 return source;
4421 Object* o;
4422 { TryAllocation t = Heap::AllocateRawAsciiString(escaped_length);
4423 if (!t->ToObject(&o)) return t;
4388 } 4424 }
4389 Object* o = Heap::AllocateRawAsciiString(escaped_length); 4425 }
4390 if (o->IsFailure()) return o;
4391 String* destination = String::cast(o); 4426 String* destination = String::cast(o);
4392 int dest_position = 0; 4427 int dest_position = 0;
4393 4428
4394 Access<StringInputBuffer> buffer(&runtime_string_input_buffer); 4429 Access<StringInputBuffer> buffer(&runtime_string_input_buffer);
4395 buffer->Rewind(); 4430 buffer->Rewind();
4396 while (buffer->has_more()) { 4431 while (buffer->has_more()) {
4397 uint16_t chr = buffer->GetNext(); 4432 uint16_t chr = buffer->GetNext();
4398 if (chr >= 256) { 4433 if (chr >= 256) {
4399 destination->Set(dest_position, '%'); 4434 destination->Set(dest_position, '%');
4400 destination->Set(dest_position+1, 'u'); 4435 destination->Set(dest_position+1, 'u');
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
4685 const int length = s->length(); 4720 const int length = s->length();
4686 // Assume that the string is not empty; we need this assumption later 4721 // Assume that the string is not empty; we need this assumption later
4687 if (length == 0) return s; 4722 if (length == 0) return s;
4688 4723
4689 // Simpler handling of ascii strings. 4724 // Simpler handling of ascii strings.
4690 // 4725 //
4691 // NOTE: This assumes that the upper/lower case of an ascii 4726 // NOTE: This assumes that the upper/lower case of an ascii
4692 // character is also ascii. This is currently the case, but it 4727 // character is also ascii. This is currently the case, but it
4693 // might break in the future if we implement more context and locale 4728 // might break in the future if we implement more context and locale
4694 // dependent upper/lower conversions. 4729 // dependent upper/lower conversions.
4730 Object* o;
4731 { TryAllocation t = Heap::AllocateRawAsciiString(length);
4732 if (!t->ToObject(&o)) return t;
4733 }
4695 if (s->IsSeqAsciiString()) { 4734 if (s->IsSeqAsciiString()) {
4696 Object* o = Heap::AllocateRawAsciiString(length);
4697 if (o->IsFailure()) return o;
4698 SeqAsciiString* result = SeqAsciiString::cast(o); 4735 SeqAsciiString* result = SeqAsciiString::cast(o);
4699 bool has_changed_character = ConvertTraits::ConvertAscii( 4736 bool has_changed_character = ConvertTraits::ConvertAscii(
4700 result->GetChars(), SeqAsciiString::cast(s)->GetChars(), length); 4737 result->GetChars(), SeqAsciiString::cast(s)->GetChars(), length);
4701 return has_changed_character ? result : s; 4738 return has_changed_character ? result : s;
4702 } 4739 }
4703 4740
4704 Object* answer = ConvertCaseHelper(s, length, length, mapping); 4741 Object* answer = ConvertCaseHelper(s, length, length, mapping);
4705 if (answer->IsSmi()) { 4742 if (answer->IsSmi()) {
4706 // Retry with correct length. 4743 // Retry with correct length.
4707 answer = ConvertCaseHelper(s, Smi::cast(answer)->value(), length, mapping); 4744 answer = ConvertCaseHelper(s, Smi::cast(answer)->value(), length, mapping);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
4902 // For example, "foo" => ["f", "o", "o"]. 4939 // For example, "foo" => ["f", "o", "o"].
4903 static Object* Runtime_StringToArray(Arguments args) { 4940 static Object* Runtime_StringToArray(Arguments args) {
4904 HandleScope scope; 4941 HandleScope scope;
4905 ASSERT(args.length() == 1); 4942 ASSERT(args.length() == 1);
4906 CONVERT_ARG_CHECKED(String, s, 0); 4943 CONVERT_ARG_CHECKED(String, s, 0);
4907 4944
4908 s->TryFlatten(); 4945 s->TryFlatten();
4909 const int length = s->length(); 4946 const int length = s->length();
4910 4947
4911 Handle<FixedArray> elements; 4948 Handle<FixedArray> elements;
4949 Object* obj;
4950 { TryAllocation t = Heap::AllocateUninitializedFixedArray(length);
4951 if (!t->ToObject(&obj)) return t;
4952 }
4912 if (s->IsFlat() && s->IsAsciiRepresentation()) { 4953 if (s->IsFlat() && s->IsAsciiRepresentation()) {
4913 Object* obj = Heap::AllocateUninitializedFixedArray(length);
4914 if (obj->IsFailure()) return obj;
4915 elements = Handle<FixedArray>(FixedArray::cast(obj)); 4954 elements = Handle<FixedArray>(FixedArray::cast(obj));
4916 4955
4917 Vector<const char> chars = s->ToAsciiVector(); 4956 Vector<const char> chars = s->ToAsciiVector();
4918 // Note, this will initialize all elements (not only the prefix) 4957 // Note, this will initialize all elements (not only the prefix)
4919 // to prevent GC from seeing partially initialized array. 4958 // to prevent GC from seeing partially initialized array.
4920 int num_copied_from_cache = CopyCachedAsciiCharsToArray(chars.start(), 4959 int num_copied_from_cache = CopyCachedAsciiCharsToArray(chars.start(),
4921 *elements, 4960 *elements,
4922 length); 4961 length);
4923 4962
4924 for (int i = num_copied_from_cache; i < length; ++i) { 4963 for (int i = num_copied_from_cache; i < length; ++i) {
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
5256 if (increment > String::kMaxLength - position) { 5295 if (increment > String::kMaxLength - position) {
5257 Top::context()->mark_out_of_memory(); 5296 Top::context()->mark_out_of_memory();
5258 return Failure::OutOfMemoryException(); 5297 return Failure::OutOfMemoryException();
5259 } 5298 }
5260 position += increment; 5299 position += increment;
5261 } 5300 }
5262 5301
5263 int length = position; 5302 int length = position;
5264 Object* object; 5303 Object* object;
5265 5304
5305 { TryAllocation t = Heap::AllocateRawAsciiString(length);
5306 if (!t->ToObject(&object)) return t;
5307 }
5266 if (ascii) { 5308 if (ascii) {
5267 object = Heap::AllocateRawAsciiString(length);
5268 if (object->IsFailure()) return object;
5269 SeqAsciiString* answer = SeqAsciiString::cast(object); 5309 SeqAsciiString* answer = SeqAsciiString::cast(object);
5270 StringBuilderConcatHelper(special, 5310 StringBuilderConcatHelper(special,
5271 answer->GetChars(), 5311 answer->GetChars(),
5272 fixed_array, 5312 fixed_array,
5273 array_length); 5313 array_length);
5274 return answer; 5314 return answer;
5315 { TryAllocation t = Heap::AllocateRawTwoByteString(length);
5316 if (!t->ToObject(&object)) return t;
5317 }
5275 } else { 5318 } else {
5276 object = Heap::AllocateRawTwoByteString(length);
5277 if (object->IsFailure()) return object;
5278 SeqTwoByteString* answer = SeqTwoByteString::cast(object); 5319 SeqTwoByteString* answer = SeqTwoByteString::cast(object);
5279 StringBuilderConcatHelper(special, 5320 StringBuilderConcatHelper(special,
5280 answer->GetChars(), 5321 answer->GetChars(),
5281 fixed_array, 5322 fixed_array,
5282 array_length); 5323 array_length);
5283 return answer; 5324 return answer;
5284 } 5325 }
5285 } 5326 }
5286 5327
5287 5328
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
5538 if (y->length() == 0) { 5579 if (y->length() == 0) {
5539 if (x->length() == 0) return Smi::FromInt(EQUAL); 5580 if (x->length() == 0) return Smi::FromInt(EQUAL);
5540 return Smi::FromInt(GREATER); 5581 return Smi::FromInt(GREATER);
5541 } else if (x->length() == 0) { 5582 } else if (x->length() == 0) {
5542 return Smi::FromInt(LESS); 5583 return Smi::FromInt(LESS);
5543 } 5584 }
5544 5585
5545 int d = x->Get(0) - y->Get(0); 5586 int d = x->Get(0) - y->Get(0);
5546 if (d < 0) return Smi::FromInt(LESS); 5587 if (d < 0) return Smi::FromInt(LESS);
5547 else if (d > 0) return Smi::FromInt(GREATER); 5588 else if (d > 0) return Smi::FromInt(GREATER);
5589 Object* obj;
5590 { TryAllocation t = Heap::PrepareForCompare(x);
5591 if (!t->ToObject(&obj)) return t;
5592 }
5548 5593
5549 Object* obj = Heap::PrepareForCompare(x); 5594 { TryAllocation t = Heap::PrepareForCompare(y);
5550 if (obj->IsFailure()) return obj; 5595 if (!t->ToObject(&obj)) return t;
5551 obj = Heap::PrepareForCompare(y); 5596 }
5552 if (obj->IsFailure()) return obj;
5553 5597
5554 return (x->IsFlat() && y->IsFlat()) ? FlatStringCompare(x, y) 5598 return (x->IsFlat() && y->IsFlat()) ? FlatStringCompare(x, y)
5555 : StringInputBufferCompare(x, y); 5599 : StringInputBufferCompare(x, y);
5556 } 5600 }
5557 5601
5558 5602
5559 static Object* Runtime_Math_acos(Arguments args) { 5603 static Object* Runtime_Math_acos(Arguments args) {
5560 NoHandleAllocation ha; 5604 NoHandleAllocation ha;
5561 ASSERT(args.length() == 1); 5605 ASSERT(args.length() == 1);
5562 Counters::math_acos.Increment(); 5606 Counters::math_acos.Increment();
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
6178 } 6222 }
6179 6223
6180 6224
6181 static Object* Runtime_NewArgumentsFast(Arguments args) { 6225 static Object* Runtime_NewArgumentsFast(Arguments args) {
6182 NoHandleAllocation ha; 6226 NoHandleAllocation ha;
6183 ASSERT(args.length() == 3); 6227 ASSERT(args.length() == 3);
6184 6228
6185 JSFunction* callee = JSFunction::cast(args[0]); 6229 JSFunction* callee = JSFunction::cast(args[0]);
6186 Object** parameters = reinterpret_cast<Object**>(args[1]); 6230 Object** parameters = reinterpret_cast<Object**>(args[1]);
6187 const int length = Smi::cast(args[2])->value(); 6231 const int length = Smi::cast(args[2])->value();
6232 Object* result;
6233 { TryAllocation t = Heap::AllocateArgumentsObject(callee, length);
6234 if (!t->ToObject(&result)) return t;
6235 }
6188 6236
6189 Object* result = Heap::AllocateArgumentsObject(callee, length);
6190 if (result->IsFailure()) return result;
6191 // Allocate the elements if needed. 6237 // Allocate the elements if needed.
6192 if (length > 0) { 6238 if (length > 0) {
6239 Object* obj;
6240 { TryAllocation t = Heap::AllocateRawFixedArray(length);
6241 if (!t->ToObject(&obj)) return t;
6242 }
6193 // Allocate the fixed array. 6243 // Allocate the fixed array.
6194 Object* obj = Heap::AllocateRawFixedArray(length);
6195 if (obj->IsFailure()) return obj;
6196 6244
6197 AssertNoAllocation no_gc; 6245 AssertNoAllocation no_gc;
6198 FixedArray* array = reinterpret_cast<FixedArray*>(obj); 6246 FixedArray* array = reinterpret_cast<FixedArray*>(obj);
6199 array->set_map(Heap::fixed_array_map()); 6247 array->set_map(Heap::fixed_array_map());
6200 array->set_length(length); 6248 array->set_length(length);
6201 6249
6202 WriteBarrierMode mode = array->GetWriteBarrierMode(no_gc); 6250 WriteBarrierMode mode = array->GetWriteBarrierMode(no_gc);
6203 for (int i = 0; i < length; i++) { 6251 for (int i = 0; i < length; i++) {
6204 array->set(i, *--parameters, mode); 6252 array->set(i, *--parameters, mode);
6205 } 6253 }
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
6396 RUNTIME_ASSERT(!args[0]->IsJSFunction()); 6444 RUNTIME_ASSERT(!args[0]->IsJSFunction());
6397 return *Execution::GetConstructorDelegate(args.at<Object>(0)); 6445 return *Execution::GetConstructorDelegate(args.at<Object>(0));
6398 } 6446 }
6399 6447
6400 6448
6401 static Object* Runtime_NewContext(Arguments args) { 6449 static Object* Runtime_NewContext(Arguments args) {
6402 NoHandleAllocation ha; 6450 NoHandleAllocation ha;
6403 ASSERT(args.length() == 1); 6451 ASSERT(args.length() == 1);
6404 6452
6405 CONVERT_CHECKED(JSFunction, function, args[0]); 6453 CONVERT_CHECKED(JSFunction, function, args[0]);
6454 Object* result;
6455 { TryAllocation t = Heap::AllocateFunctionContext(length, function);
6456 if (!t->ToObject(&result)) return t;
6457 }
6406 int length = function->shared()->scope_info()->NumberOfContextSlots(); 6458 int length = function->shared()->scope_info()->NumberOfContextSlots();
6407 Object* result = Heap::AllocateFunctionContext(length, function);
6408 if (result->IsFailure()) return result;
6409 6459
6410 Top::set_context(Context::cast(result)); 6460 Top::set_context(Context::cast(result));
6411 6461
6412 return result; // non-failure 6462 return result; // non-failure
6413 } 6463 }
6414 6464
6415 static Object* PushContextHelper(Object* object, bool is_catch_context) { 6465 static Object* PushContextHelper(Object* object, bool is_catch_context) {
6416 // Convert the object to a proper JavaScript object. 6466 // Convert the object to a proper JavaScript object.
6417 Object* js_object = object; 6467 Object* js_object = object;
6418 if (!js_object->IsJSObject()) { 6468 if (!js_object->IsJSObject()) {
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
7102 // false otherwise. 7152 // false otherwise.
7103 static Object* Runtime_PushIfAbsent(Arguments args) { 7153 static Object* Runtime_PushIfAbsent(Arguments args) {
7104 ASSERT(args.length() == 2); 7154 ASSERT(args.length() == 2);
7105 CONVERT_CHECKED(JSArray, array, args[0]); 7155 CONVERT_CHECKED(JSArray, array, args[0]);
7106 CONVERT_CHECKED(JSArray, element, args[1]); 7156 CONVERT_CHECKED(JSArray, element, args[1]);
7107 RUNTIME_ASSERT(array->HasFastElements()); 7157 RUNTIME_ASSERT(array->HasFastElements());
7108 int length = Smi::cast(array->length())->value(); 7158 int length = Smi::cast(array->length())->value();
7109 FixedArray* elements = FixedArray::cast(array->elements()); 7159 FixedArray* elements = FixedArray::cast(array->elements());
7110 for (int i = 0; i < length; i++) { 7160 for (int i = 0; i < length; i++) {
7111 if (elements->get(i) == element) return Heap::false_value(); 7161 if (elements->get(i) == element) return Heap::false_value();
7162 Object* obj;
7163 { TryAllocation t = array->SetFastElement(length, element);
7164 if (!t->ToObject(&obj)) return t;
7112 } 7165 }
7113 Object* obj = array->SetFastElement(length, element); 7166 }
7114 if (obj->IsFailure()) return obj;
7115 return Heap::true_value(); 7167 return Heap::true_value();
7116 } 7168 }
7117 7169
7118 7170
7119 /** 7171 /**
7120 * A simple visitor visits every element of Array's. 7172 * A simple visitor visits every element of Array's.
7121 * The backend storage can be a fixed array for fast elements case, 7173 * The backend storage can be a fixed array for fast elements case,
7122 * or a dictionary for sparse array. Since Dictionary is a subtype 7174 * or a dictionary for sparse array. Since Dictionary is a subtype
7123 * of FixedArray, the class can be used by both fast and slow cases. 7175 * of FixedArray, the class can be used by both fast and slow cases.
7124 * The second parameter of the constructor, fast_elements, specifies 7176 * The second parameter of the constructor, fast_elements, specifies
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
7551 Object* new_map; 7603 Object* new_map;
7552 if (new_elements->map() == Heap::fixed_array_map() || 7604 if (new_elements->map() == Heap::fixed_array_map() ||
7553 new_elements->map() == Heap::fixed_cow_array_map()) { 7605 new_elements->map() == Heap::fixed_cow_array_map()) {
7554 new_map = to->map()->GetFastElementsMap(); 7606 new_map = to->map()->GetFastElementsMap();
7555 } else { 7607 } else {
7556 new_map = to->map()->GetSlowElementsMap(); 7608 new_map = to->map()->GetSlowElementsMap();
7557 } 7609 }
7558 if (new_map->IsFailure()) return new_map; 7610 if (new_map->IsFailure()) return new_map;
7559 to->set_map(Map::cast(new_map)); 7611 to->set_map(Map::cast(new_map));
7560 to->set_elements(new_elements); 7612 to->set_elements(new_elements);
7613 Object* obj;
7614 { TryAllocation t = from->ResetElements();
7615 if (!t->ToObject(&obj)) return t;
7616 }
7561 to->set_length(from->length()); 7617 to->set_length(from->length());
7562 Object* obj = from->ResetElements();
7563 if (obj->IsFailure()) return obj;
7564 from->set_length(Smi::FromInt(0)); 7618 from->set_length(Smi::FromInt(0));
7565 return to; 7619 return to;
7566 } 7620 }
7567 7621
7568 7622
7569 // How many elements does this object/array have? 7623 // How many elements does this object/array have?
7570 static Object* Runtime_EstimateNumberOfElements(Arguments args) { 7624 static Object* Runtime_EstimateNumberOfElements(Arguments args) {
7571 ASSERT(args.length() == 1); 7625 ASSERT(args.length() == 1);
7572 CONVERT_CHECKED(JSObject, object, args[0]); 7626 CONVERT_CHECKED(JSObject, object, args[0]);
7573 HeapObject* elements = object->elements(); 7627 HeapObject* elements = object->elements();
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
7838 // local variables using handles when required for later use. 7892 // local variables using handles when required for later use.
7839 PropertyType result_type = result.type(); 7893 PropertyType result_type = result.type();
7840 Handle<Object> result_callback_obj; 7894 Handle<Object> result_callback_obj;
7841 if (result_type == CALLBACKS) { 7895 if (result_type == CALLBACKS) {
7842 result_callback_obj = Handle<Object>(result.GetCallbackObject()); 7896 result_callback_obj = Handle<Object>(result.GetCallbackObject());
7843 } 7897 }
7844 Smi* property_details = result.GetPropertyDetails().AsSmi(); 7898 Smi* property_details = result.GetPropertyDetails().AsSmi();
7845 // DebugLookupResultValue can cause GC so details from LookupResult needs 7899 // DebugLookupResultValue can cause GC so details from LookupResult needs
7846 // to be copied to handles before this. 7900 // to be copied to handles before this.
7847 bool caught_exception = false; 7901 bool caught_exception = false;
7848 Object* raw_value = DebugLookupResultValue(*obj, *name, &result, 7902 Object* raw_value;
7849 &caught_exception); 7903 { TryAllocation t = DebugLookupResultValue(*obj, *name, &result,
7850 if (raw_value->IsFailure()) return raw_value; 7904 &caught_exception);
7905 if (!t->ToObject(&raw_value)) return t;
7906 }
7851 Handle<Object> value(raw_value); 7907 Handle<Object> value(raw_value);
7852 7908
7853 // If the callback object is a fixed array then it contains JavaScript 7909 // If the callback object is a fixed array then it contains JavaScript
7854 // getter and/or setter. 7910 // getter and/or setter.
7855 bool hasJavaScriptAccessors = result_type == CALLBACKS && 7911 bool hasJavaScriptAccessors = result_type == CALLBACKS &&
7856 result_callback_obj->IsFixedArray(); 7912 result_callback_obj->IsFixedArray();
7857 Handle<FixedArray> details = 7913 Handle<FixedArray> details =
7858 Factory::NewFixedArray(hasJavaScriptAccessors ? 5 : 2); 7914 Factory::NewFixedArray(hasJavaScriptAccessors ? 5 : 2);
7859 details->set(0, *value); 7915 details->set(0, *value);
7860 details->set(1, property_details); 7916 details->set(1, property_details);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
7962 } 8018 }
7963 8019
7964 return Heap::true_value(); 8020 return Heap::true_value();
7965 } 8021 }
7966 8022
7967 8023
7968 static Object* Runtime_GetFrameCount(Arguments args) { 8024 static Object* Runtime_GetFrameCount(Arguments args) {
7969 HandleScope scope; 8025 HandleScope scope;
7970 ASSERT(args.length() == 1); 8026 ASSERT(args.length() == 1);
7971 8027
8028 Object* result;
8029 { TryAllocation t = Runtime_CheckExecutionState(args);
8030 if (!t->ToObject(&result)) return t;
8031 }
7972 // Check arguments. 8032 // Check arguments.
7973 Object* result = Runtime_CheckExecutionState(args);
7974 if (result->IsFailure()) return result;
7975 8033
7976 // Count all frames which are relevant to debugging stack trace. 8034 // Count all frames which are relevant to debugging stack trace.
7977 int n = 0; 8035 int n = 0;
7978 StackFrame::Id id = Debug::break_frame_id(); 8036 StackFrame::Id id = Debug::break_frame_id();
7979 if (id == StackFrame::NO_ID) { 8037 if (id == StackFrame::NO_ID) {
7980 // If there is no JavaScript stack frame count is 0. 8038 // If there is no JavaScript stack frame count is 0.
7981 return Smi::FromInt(0); 8039 return Smi::FromInt(0);
7982 } 8040 }
7983 for (JavaScriptFrameIterator it(id); !it.done(); it.Advance()) n++; 8041 for (JavaScriptFrameIterator it(id); !it.done(); it.Advance()) n++;
7984 return Smi::FromInt(n); 8042 return Smi::FromInt(n);
(...skipping 25 matching lines...) Expand all
8010 // 6: Constructor call 8068 // 6: Constructor call
8011 // 7: Is at return 8069 // 7: Is at return
8012 // 8: Debugger frame 8070 // 8: Debugger frame
8013 // Arguments name, value 8071 // Arguments name, value
8014 // Locals name, value 8072 // Locals name, value
8015 // Return value if any 8073 // Return value if any
8016 static Object* Runtime_GetFrameDetails(Arguments args) { 8074 static Object* Runtime_GetFrameDetails(Arguments args) {
8017 HandleScope scope; 8075 HandleScope scope;
8018 ASSERT(args.length() == 2); 8076 ASSERT(args.length() == 2);
8019 8077
8078 Object* check;
8079 { TryAllocation t = Runtime_CheckExecutionState(args);
8080 if (!t->ToObject(&check)) return t;
8081 }
8020 // Check arguments. 8082 // Check arguments.
8021 Object* check = Runtime_CheckExecutionState(args);
8022 if (check->IsFailure()) return check;
8023 CONVERT_NUMBER_CHECKED(int, index, Int32, args[1]); 8083 CONVERT_NUMBER_CHECKED(int, index, Int32, args[1]);
8024 8084
8025 // Find the relevant frame with the requested index. 8085 // Find the relevant frame with the requested index.
8026 StackFrame::Id id = Debug::break_frame_id(); 8086 StackFrame::Id id = Debug::break_frame_id();
8027 if (id == StackFrame::NO_ID) { 8087 if (id == StackFrame::NO_ID) {
8028 // If there are no JavaScript stack frames return undefined. 8088 // If there are no JavaScript stack frames return undefined.
8029 return Heap::undefined_value(); 8089 return Heap::undefined_value();
8030 } 8090 }
8031 int count = 0; 8091 int count = 0;
8032 JavaScriptFrameIterator it(id); 8092 JavaScriptFrameIterator it(id);
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
8551 bool at_local_; 8611 bool at_local_;
8552 8612
8553 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopeIterator); 8613 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopeIterator);
8554 }; 8614 };
8555 8615
8556 8616
8557 static Object* Runtime_GetScopeCount(Arguments args) { 8617 static Object* Runtime_GetScopeCount(Arguments args) {
8558 HandleScope scope; 8618 HandleScope scope;
8559 ASSERT(args.length() == 2); 8619 ASSERT(args.length() == 2);
8560 8620
8621 Object* check;
8622 { TryAllocation t = Runtime_CheckExecutionState(args);
8623 if (!t->ToObject(&check)) return t;
8624 }
8561 // Check arguments. 8625 // Check arguments.
8562 Object* check = Runtime_CheckExecutionState(args);
8563 if (check->IsFailure()) return check;
8564 CONVERT_CHECKED(Smi, wrapped_id, args[1]); 8626 CONVERT_CHECKED(Smi, wrapped_id, args[1]);
8565 8627
8566 // Get the frame where the debugging is performed. 8628 // Get the frame where the debugging is performed.
8567 StackFrame::Id id = UnwrapFrameId(wrapped_id); 8629 StackFrame::Id id = UnwrapFrameId(wrapped_id);
8568 JavaScriptFrameIterator it(id); 8630 JavaScriptFrameIterator it(id);
8569 JavaScriptFrame* frame = it.frame(); 8631 JavaScriptFrame* frame = it.frame();
8570 8632
8571 // Count the visible scopes. 8633 // Count the visible scopes.
8572 int n = 0; 8634 int n = 0;
8573 for (ScopeIterator it(frame); !it.Done(); it.Next()) { 8635 for (ScopeIterator it(frame); !it.Done(); it.Next()) {
(...skipping 13 matching lines...) Expand all
8587 // args[1]: number: frame index 8649 // args[1]: number: frame index
8588 // args[2]: number: scope index 8650 // args[2]: number: scope index
8589 // 8651 //
8590 // The array returned contains the following information: 8652 // The array returned contains the following information:
8591 // 0: Scope type 8653 // 0: Scope type
8592 // 1: Scope object 8654 // 1: Scope object
8593 static Object* Runtime_GetScopeDetails(Arguments args) { 8655 static Object* Runtime_GetScopeDetails(Arguments args) {
8594 HandleScope scope; 8656 HandleScope scope;
8595 ASSERT(args.length() == 3); 8657 ASSERT(args.length() == 3);
8596 8658
8659 Object* check;
8660 { TryAllocation t = Runtime_CheckExecutionState(args);
8661 if (!t->ToObject(&check)) return t;
8662 }
8597 // Check arguments. 8663 // Check arguments.
8598 Object* check = Runtime_CheckExecutionState(args);
8599 if (check->IsFailure()) return check;
8600 CONVERT_CHECKED(Smi, wrapped_id, args[1]); 8664 CONVERT_CHECKED(Smi, wrapped_id, args[1]);
8601 CONVERT_NUMBER_CHECKED(int, index, Int32, args[2]); 8665 CONVERT_NUMBER_CHECKED(int, index, Int32, args[2]);
8602 8666
8603 // Get the frame where the debugging is performed. 8667 // Get the frame where the debugging is performed.
8604 StackFrame::Id id = UnwrapFrameId(wrapped_id); 8668 StackFrame::Id id = UnwrapFrameId(wrapped_id);
8605 JavaScriptFrameIterator frame_it(id); 8669 JavaScriptFrameIterator frame_it(id);
8606 JavaScriptFrame* frame = frame_it.frame(); 8670 JavaScriptFrame* frame = frame_it.frame();
8607 8671
8608 // Find the requested scope. 8672 // Find the requested scope.
8609 int n = 0; 8673 int n = 0;
(...skipping 29 matching lines...) Expand all
8639 for (ScopeIterator it(frame); !it.Done(); it.Next()) { 8703 for (ScopeIterator it(frame); !it.Done(); it.Next()) {
8640 it.DebugPrint(); 8704 it.DebugPrint();
8641 } 8705 }
8642 #endif 8706 #endif
8643 return Heap::undefined_value(); 8707 return Heap::undefined_value();
8644 } 8708 }
8645 8709
8646 8710
8647 static Object* Runtime_GetCFrames(Arguments args) { 8711 static Object* Runtime_GetCFrames(Arguments args) {
8648 HandleScope scope; 8712 HandleScope scope;
8713 Object* result;
8714 { TryAllocation t = Runtime_CheckExecutionState(args);
8715 if (!t->ToObject(&result)) return t;
8716 }
8649 ASSERT(args.length() == 1); 8717 ASSERT(args.length() == 1);
8650 Object* result = Runtime_CheckExecutionState(args);
8651 if (result->IsFailure()) return result;
8652 8718
8653 #if V8_HOST_ARCH_64_BIT 8719 #if V8_HOST_ARCH_64_BIT
8654 UNIMPLEMENTED(); 8720 UNIMPLEMENTED();
8655 return Heap::undefined_value(); 8721 return Heap::undefined_value();
8656 #else 8722 #else
8657 8723
8658 static const int kMaxCFramesSize = 200; 8724 static const int kMaxCFramesSize = 200;
8659 ScopedVector<OS::StackFrame> frames(kMaxCFramesSize); 8725 ScopedVector<OS::StackFrame> frames(kMaxCFramesSize);
8660 int frames_count = OS::StackWalk(frames); 8726 int frames_count = OS::StackWalk(frames);
8661 if (frames_count == OS::kStackWalkError) { 8727 if (frames_count == OS::kStackWalkError) {
(...skipping 26 matching lines...) Expand all
8688 } 8754 }
8689 return *Factory::NewJSArrayWithElements(frames_array); 8755 return *Factory::NewJSArrayWithElements(frames_array);
8690 #endif // V8_HOST_ARCH_64_BIT 8756 #endif // V8_HOST_ARCH_64_BIT
8691 } 8757 }
8692 8758
8693 8759
8694 static Object* Runtime_GetThreadCount(Arguments args) { 8760 static Object* Runtime_GetThreadCount(Arguments args) {
8695 HandleScope scope; 8761 HandleScope scope;
8696 ASSERT(args.length() == 1); 8762 ASSERT(args.length() == 1);
8697 8763
8764 Object* result;
8765 { TryAllocation t = Runtime_CheckExecutionState(args);
8766 if (!t->ToObject(&result)) return t;
8767 }
8698 // Check arguments. 8768 // Check arguments.
8699 Object* result = Runtime_CheckExecutionState(args);
8700 if (result->IsFailure()) return result;
8701 8769
8702 // Count all archived V8 threads. 8770 // Count all archived V8 threads.
8703 int n = 0; 8771 int n = 0;
8704 for (ThreadState* thread = ThreadState::FirstInUse(); 8772 for (ThreadState* thread = ThreadState::FirstInUse();
8705 thread != NULL; 8773 thread != NULL;
8706 thread = thread->Next()) { 8774 thread = thread->Next()) {
8707 n++; 8775 n++;
8708 } 8776 }
8709 8777
8710 // Total number of threads is current thread and archived threads. 8778 // Total number of threads is current thread and archived threads.
8711 return Smi::FromInt(n + 1); 8779 return Smi::FromInt(n + 1);
8712 } 8780 }
8713 8781
8714 8782
8715 static const int kThreadDetailsCurrentThreadIndex = 0; 8783 static const int kThreadDetailsCurrentThreadIndex = 0;
8716 static const int kThreadDetailsThreadIdIndex = 1; 8784 static const int kThreadDetailsThreadIdIndex = 1;
8717 static const int kThreadDetailsSize = 2; 8785 static const int kThreadDetailsSize = 2;
8718 8786
8719 // Return an array with thread details 8787 // Return an array with thread details
8720 // args[0]: number: break id 8788 // args[0]: number: break id
8721 // args[1]: number: thread index 8789 // args[1]: number: thread index
8722 // 8790 //
8723 // The array returned contains the following information: 8791 // The array returned contains the following information:
8724 // 0: Is current thread? 8792 // 0: Is current thread?
8725 // 1: Thread id 8793 // 1: Thread id
8726 static Object* Runtime_GetThreadDetails(Arguments args) { 8794 static Object* Runtime_GetThreadDetails(Arguments args) {
8727 HandleScope scope; 8795 HandleScope scope;
8728 ASSERT(args.length() == 2); 8796 ASSERT(args.length() == 2);
8729 8797
8798 Object* check;
8799 { TryAllocation t = Runtime_CheckExecutionState(args);
8800 if (!t->ToObject(&check)) return t;
8801 }
8730 // Check arguments. 8802 // Check arguments.
8731 Object* check = Runtime_CheckExecutionState(args);
8732 if (check->IsFailure()) return check;
8733 CONVERT_NUMBER_CHECKED(int, index, Int32, args[1]); 8803 CONVERT_NUMBER_CHECKED(int, index, Int32, args[1]);
8734 8804
8735 // Allocate array for result. 8805 // Allocate array for result.
8736 Handle<FixedArray> details = Factory::NewFixedArray(kThreadDetailsSize); 8806 Handle<FixedArray> details = Factory::NewFixedArray(kThreadDetailsSize);
8737 8807
8738 // Thread index 0 is current thread. 8808 // Thread index 0 is current thread.
8739 if (index == 0) { 8809 if (index == 0) {
8740 // Fill the details. 8810 // Fill the details.
8741 details->set(kThreadDetailsCurrentThreadIndex, Heap::true_value()); 8811 details->set(kThreadDetailsCurrentThreadIndex, Heap::true_value());
8742 details->set(kThreadDetailsThreadIdIndex, 8812 details->set(kThreadDetailsThreadIdIndex,
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
8972 9042
8973 9043
8974 // Prepare for stepping 9044 // Prepare for stepping
8975 // args[0]: break id for checking execution state 9045 // args[0]: break id for checking execution state
8976 // args[1]: step action from the enumeration StepAction 9046 // args[1]: step action from the enumeration StepAction
8977 // args[2]: number of times to perform the step, for step out it is the number 9047 // args[2]: number of times to perform the step, for step out it is the number
8978 // of frames to step down. 9048 // of frames to step down.
8979 static Object* Runtime_PrepareStep(Arguments args) { 9049 static Object* Runtime_PrepareStep(Arguments args) {
8980 HandleScope scope; 9050 HandleScope scope;
8981 ASSERT(args.length() == 3); 9051 ASSERT(args.length() == 3);
9052 Object* check;
9053 { TryAllocation t = Runtime_CheckExecutionState(args);
9054 if (!t->ToObject(&check)) return t;
9055 }
8982 // Check arguments. 9056 // Check arguments.
8983 Object* check = Runtime_CheckExecutionState(args);
8984 if (check->IsFailure()) return check;
8985 if (!args[1]->IsNumber() || !args[2]->IsNumber()) { 9057 if (!args[1]->IsNumber() || !args[2]->IsNumber()) {
8986 return Top::Throw(Heap::illegal_argument_symbol()); 9058 return Top::Throw(Heap::illegal_argument_symbol());
8987 } 9059 }
8988 9060
8989 // Get the step action and check validity. 9061 // Get the step action and check validity.
8990 StepAction step_action = static_cast<StepAction>(NumberToInt32(args[1])); 9062 StepAction step_action = static_cast<StepAction>(NumberToInt32(args[1]));
8991 if (step_action != StepIn && 9063 if (step_action != StepIn &&
8992 step_action != StepNext && 9064 step_action != StepNext &&
8993 step_action != StepOut && 9065 step_action != StepOut &&
8994 step_action != StepInMin && 9066 step_action != StepInMin &&
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
9087 // function is created as well to be used as the closure for the context. 9159 // function is created as well to be used as the closure for the context.
9088 // This function and the context acts as replacements for the function on the 9160 // This function and the context acts as replacements for the function on the
9089 // stack frame presenting the same view of the values of parameters and 9161 // stack frame presenting the same view of the values of parameters and
9090 // local variables as if the piece of JavaScript was evaluated at the point 9162 // local variables as if the piece of JavaScript was evaluated at the point
9091 // where the function on the stack frame is currently stopped. 9163 // where the function on the stack frame is currently stopped.
9092 static Object* Runtime_DebugEvaluate(Arguments args) { 9164 static Object* Runtime_DebugEvaluate(Arguments args) {
9093 HandleScope scope; 9165 HandleScope scope;
9094 9166
9095 // Check the execution state and decode arguments frame and source to be 9167 // Check the execution state and decode arguments frame and source to be
9096 // evaluated. 9168 // evaluated.
9169 Object* check_result;
9170 { TryAllocation t = Runtime_CheckExecutionState(args);
9171 if (!t->ToObject(&check_result)) return t;
9172 }
9097 ASSERT(args.length() == 4); 9173 ASSERT(args.length() == 4);
9098 Object* check_result = Runtime_CheckExecutionState(args);
9099 if (check_result->IsFailure()) return check_result;
9100 CONVERT_CHECKED(Smi, wrapped_id, args[1]); 9174 CONVERT_CHECKED(Smi, wrapped_id, args[1]);
9101 CONVERT_ARG_CHECKED(String, source, 2); 9175 CONVERT_ARG_CHECKED(String, source, 2);
9102 CONVERT_BOOLEAN_CHECKED(disable_break, args[3]); 9176 CONVERT_BOOLEAN_CHECKED(disable_break, args[3]);
9103 9177
9104 // Handle the processing of break. 9178 // Handle the processing of break.
9105 DisableBreak disable_break_save(disable_break); 9179 DisableBreak disable_break_save(disable_break);
9106 9180
9107 // Get the frame where the debugging is performed. 9181 // Get the frame where the debugging is performed.
9108 StackFrame::Id id = UnwrapFrameId(wrapped_id); 9182 StackFrame::Id id = UnwrapFrameId(wrapped_id);
9109 JavaScriptFrameIterator it(id); 9183 JavaScriptFrameIterator it(id);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
9198 9272
9199 return *result; 9273 return *result;
9200 } 9274 }
9201 9275
9202 9276
9203 static Object* Runtime_DebugEvaluateGlobal(Arguments args) { 9277 static Object* Runtime_DebugEvaluateGlobal(Arguments args) {
9204 HandleScope scope; 9278 HandleScope scope;
9205 9279
9206 // Check the execution state and decode arguments frame and source to be 9280 // Check the execution state and decode arguments frame and source to be
9207 // evaluated. 9281 // evaluated.
9282 Object* check_result;
9283 { TryAllocation t = Runtime_CheckExecutionState(args);
9284 if (!t->ToObject(&check_result)) return t;
9285 }
9208 ASSERT(args.length() == 3); 9286 ASSERT(args.length() == 3);
9209 Object* check_result = Runtime_CheckExecutionState(args);
9210 if (check_result->IsFailure()) return check_result;
9211 CONVERT_ARG_CHECKED(String, source, 1); 9287 CONVERT_ARG_CHECKED(String, source, 1);
9212 CONVERT_BOOLEAN_CHECKED(disable_break, args[2]); 9288 CONVERT_BOOLEAN_CHECKED(disable_break, args[2]);
9213 9289
9214 // Handle the processing of break. 9290 // Handle the processing of break.
9215 DisableBreak disable_break_save(disable_break); 9291 DisableBreak disable_break_save(disable_break);
9216 9292
9217 // Enter the top context from before the debugger was invoked. 9293 // Enter the top context from before the debugger was invoked.
9218 SaveContext save; 9294 SaveContext save;
9219 SaveContext* top = &save; 9295 SaveContext* top = &save;
9220 while (top != NULL && *top->context() == *Debug::debug_context()) { 9296 while (top != NULL && *top->context() == *Debug::debug_context()) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
9368 JSObject* arguments_boilerplate = 9444 JSObject* arguments_boilerplate =
9369 Top::context()->global_context()->arguments_boilerplate(); 9445 Top::context()->global_context()->arguments_boilerplate();
9370 JSFunction* arguments_function = 9446 JSFunction* arguments_function =
9371 JSFunction::cast(arguments_boilerplate->map()->constructor()); 9447 JSFunction::cast(arguments_boilerplate->map()->constructor());
9372 9448
9373 // Get the number of referencing objects. 9449 // Get the number of referencing objects.
9374 int count; 9450 int count;
9375 count = DebugReferencedBy(target, instance_filter, max_references, 9451 count = DebugReferencedBy(target, instance_filter, max_references,
9376 NULL, 0, arguments_function); 9452 NULL, 0, arguments_function);
9377 9453
9454 Object* object;
9455 { TryAllocation t = Heap::AllocateFixedArray(count);
9456 if (!t->ToObject(&object)) return t;
9457 }
9378 // Allocate an array to hold the result. 9458 // Allocate an array to hold the result.
9379 Object* object = Heap::AllocateFixedArray(count);
9380 if (object->IsFailure()) return object;
9381 FixedArray* instances = FixedArray::cast(object); 9459 FixedArray* instances = FixedArray::cast(object);
9382 9460
9383 // Fill the referencing objects. 9461 // Fill the referencing objects.
9384 count = DebugReferencedBy(target, instance_filter, max_references, 9462 count = DebugReferencedBy(target, instance_filter, max_references,
9385 instances, count, arguments_function); 9463 instances, count, arguments_function);
9386 9464
9387 // Return result as JS array. 9465 // Return result as JS array.
9388 Object* result = 9466 Object* result =
9389 Heap::AllocateJSObject( 9467 Heap::AllocateJSObject(
9390 Top::context()->global_context()->array_function()); 9468 Top::context()->global_context()->array_function());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
9434 9512
9435 // Check parameters. 9513 // Check parameters.
9436 CONVERT_CHECKED(JSFunction, constructor, args[0]); 9514 CONVERT_CHECKED(JSFunction, constructor, args[0]);
9437 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]); 9515 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]);
9438 RUNTIME_ASSERT(max_references >= 0); 9516 RUNTIME_ASSERT(max_references >= 0);
9439 9517
9440 // Get the number of referencing objects. 9518 // Get the number of referencing objects.
9441 int count; 9519 int count;
9442 count = DebugConstructedBy(constructor, max_references, NULL, 0); 9520 count = DebugConstructedBy(constructor, max_references, NULL, 0);
9443 9521
9522 Object* object;
9523 { TryAllocation t = Heap::AllocateFixedArray(count);
9524 if (!t->ToObject(&object)) return t;
9525 }
9444 // Allocate an array to hold the result. 9526 // Allocate an array to hold the result.
9445 Object* object = Heap::AllocateFixedArray(count);
9446 if (object->IsFailure()) return object;
9447 FixedArray* instances = FixedArray::cast(object); 9527 FixedArray* instances = FixedArray::cast(object);
9448 9528
9449 // Fill the referencing objects. 9529 // Fill the referencing objects.
9450 count = DebugConstructedBy(constructor, max_references, instances, count); 9530 count = DebugConstructedBy(constructor, max_references, instances, count);
9451 9531
9452 // Return result as JS array. 9532 // Return result as JS array.
9453 Object* result = 9533 Object* result =
9454 Heap::AllocateJSObject( 9534 Heap::AllocateJSObject(
9455 Top::context()->global_context()->array_function()); 9535 Top::context()->global_context()->array_function());
9456 if (!result->IsFailure()) JSArray::cast(result)->SetContent(instances); 9536 if (!result->IsFailure()) JSArray::cast(result)->SetContent(instances);
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
10111 Runtime::Function kIntrinsicFunctions[] = { 10191 Runtime::Function kIntrinsicFunctions[] = {
10112 RUNTIME_FUNCTION_LIST(F) 10192 RUNTIME_FUNCTION_LIST(F)
10113 INLINE_FUNCTION_LIST(I) 10193 INLINE_FUNCTION_LIST(I)
10114 INLINE_RUNTIME_FUNCTION_LIST(I) 10194 INLINE_RUNTIME_FUNCTION_LIST(I)
10115 }; 10195 };
10116 10196
10117 10197
10118 Object* Runtime::InitializeIntrinsicFunctionNames(Object* dictionary) { 10198 Object* Runtime::InitializeIntrinsicFunctionNames(Object* dictionary) {
10119 ASSERT(dictionary != NULL); 10199 ASSERT(dictionary != NULL);
10120 ASSERT(StringDictionary::cast(dictionary)->NumberOfElements() == 0); 10200 ASSERT(StringDictionary::cast(dictionary)->NumberOfElements() == 0);
10201 Object* name_symbol;
10202 { TryAllocation t = Heap::LookupAsciiSymbol(kIntrinsicFunctions[i].name);
10203 if (!t->ToObject(&name_symbol)) return t;
10204 }
10121 for (int i = 0; i < kNumFunctions; ++i) { 10205 for (int i = 0; i < kNumFunctions; ++i) {
10122 Object* name_symbol = Heap::LookupAsciiSymbol(kIntrinsicFunctions[i].name);
10123 if (name_symbol->IsFailure()) return name_symbol;
10124 StringDictionary* string_dictionary = StringDictionary::cast(dictionary); 10206 StringDictionary* string_dictionary = StringDictionary::cast(dictionary);
10125 dictionary = string_dictionary->Add(String::cast(name_symbol), 10207 dictionary = string_dictionary->Add(String::cast(name_symbol),
10126 Smi::FromInt(i), 10208 Smi::FromInt(i),
10127 PropertyDetails(NONE, NORMAL)); 10209 PropertyDetails(NONE, NORMAL));
10128 // Non-recoverable failure. Calling code must restart heap initialization. 10210 // Non-recoverable failure. Calling code must restart heap initialization.
10129 if (dictionary->IsFailure()) return dictionary; 10211 if (dictionary->IsFailure()) return dictionary;
10130 } 10212 }
10131 return dictionary; 10213 return dictionary;
10132 } 10214 }
10133 10215
(...skipping 23 matching lines...) Expand all
10157 } else { 10239 } else {
10158 // Handle last resort GC and make sure to allow future allocations 10240 // Handle last resort GC and make sure to allow future allocations
10159 // to grow the heap without causing GCs (if possible). 10241 // to grow the heap without causing GCs (if possible).
10160 Counters::gc_last_resort_from_js.Increment(); 10242 Counters::gc_last_resort_from_js.Increment();
10161 Heap::CollectAllGarbage(false); 10243 Heap::CollectAllGarbage(false);
10162 } 10244 }
10163 } 10245 }
10164 10246
10165 10247
10166 } } // namespace v8::internal 10248 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/property.h ('k') | src/stub-cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698