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

Side by Side Diff: src/runtime.cc

Issue 3398014: Fix possible evaluation order problems. (Closed)
Patch Set: fixed more places Created 10 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
« src/bootstrapper.cc ('K') | « src/objects.cc ('k') | no next file » | 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 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 elms->set(IS_ACCESSOR_INDEX, Heap::false_value()); 671 elms->set(IS_ACCESSOR_INDEX, Heap::false_value());
672 elms->set(VALUE_INDEX, dictionary->ValueAt(entry)); 672 elms->set(VALUE_INDEX, dictionary->ValueAt(entry));
673 elms->set(WRITABLE_INDEX, Heap::ToBoolean(!details.IsReadOnly())); 673 elms->set(WRITABLE_INDEX, Heap::ToBoolean(!details.IsReadOnly()));
674 elms->set(ENUMERABLE_INDEX, Heap::ToBoolean(!details.IsDontEnum())); 674 elms->set(ENUMERABLE_INDEX, Heap::ToBoolean(!details.IsDontEnum()));
675 elms->set(CONFIGURABLE_INDEX, Heap::ToBoolean(!details.IsDontDelete())); 675 elms->set(CONFIGURABLE_INDEX, Heap::ToBoolean(!details.IsDontDelete()));
676 return *desc; 676 return *desc;
677 } else { 677 } else {
678 // Elements that are stored as array elements always has: 678 // Elements that are stored as array elements always has:
679 // writable: true, configurable: true, enumerable: true. 679 // writable: true, configurable: true, enumerable: true.
680 elms->set(IS_ACCESSOR_INDEX, Heap::false_value()); 680 elms->set(IS_ACCESSOR_INDEX, Heap::false_value());
681 elms->set(VALUE_INDEX, obj->GetElement(index)); 681 Object* element = obj->GetElement(index);
682 elms->set(VALUE_INDEX, element);
682 elms->set(WRITABLE_INDEX, Heap::true_value()); 683 elms->set(WRITABLE_INDEX, Heap::true_value());
683 elms->set(ENUMERABLE_INDEX, Heap::true_value()); 684 elms->set(ENUMERABLE_INDEX, Heap::true_value());
684 elms->set(CONFIGURABLE_INDEX, Heap::true_value()); 685 elms->set(CONFIGURABLE_INDEX, Heap::true_value());
685 return *desc; 686 return *desc;
686 } 687 }
687 } 688 }
688 689
689 // Use recursive implementation to also traverse hidden prototypes 690 // Use recursive implementation to also traverse hidden prototypes
690 GetOwnPropertyImplementation(obj, name, &result); 691 GetOwnPropertyImplementation(obj, name, &result);
691 692
(...skipping 2138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2830 match = RegExpImpl::Exec(regexp, subject, index, regexp_info); 2831 match = RegExpImpl::Exec(regexp, subject, index, regexp_info);
2831 if (match.is_null()) { 2832 if (match.is_null()) {
2832 return Failure::Exception(); 2833 return Failure::Exception();
2833 } 2834 }
2834 } while (!match->IsNull()); 2835 } while (!match->IsNull());
2835 int matches = offsets.length() / 2; 2836 int matches = offsets.length() / 2;
2836 Handle<FixedArray> elements = Factory::NewFixedArray(matches); 2837 Handle<FixedArray> elements = Factory::NewFixedArray(matches);
2837 for (int i = 0; i < matches ; i++) { 2838 for (int i = 0; i < matches ; i++) {
2838 int from = offsets.at(i * 2); 2839 int from = offsets.at(i * 2);
2839 int to = offsets.at(i * 2 + 1); 2840 int to = offsets.at(i * 2 + 1);
2840 elements->set(i, *Factory::NewSubString(subject, from, to)); 2841 Handle<String> match = Factory::NewSubString(subject, from, to);
2842 elements->set(i, *match);
2841 } 2843 }
2842 Handle<JSArray> result = Factory::NewJSArrayWithElements(elements); 2844 Handle<JSArray> result = Factory::NewJSArrayWithElements(elements);
2843 result->set_length(Smi::FromInt(matches)); 2845 result->set_length(Smi::FromInt(matches));
2844 return *result; 2846 return *result;
2845 } 2847 }
2846 2848
2847 2849
2848 // Two smis before and after the match, for very long strings. 2850 // Two smis before and after the match, for very long strings.
2849 const int kMaxBuilderEntriesPerRegExpMatch = 5; 2851 const int kMaxBuilderEntriesPerRegExpMatch = 5;
2850 2852
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
3098 match_start); 3100 match_start);
3099 } 3101 }
3100 match_end = register_vector[1]; 3102 match_end = register_vector[1];
3101 3103
3102 { 3104 {
3103 // Avoid accumulating new handles inside loop. 3105 // Avoid accumulating new handles inside loop.
3104 HandleScope temp_scope; 3106 HandleScope temp_scope;
3105 // Arguments array to replace function is match, captures, index and 3107 // Arguments array to replace function is match, captures, index and
3106 // subject, i.e., 3 + capture count in total. 3108 // subject, i.e., 3 + capture count in total.
3107 Handle<FixedArray> elements = Factory::NewFixedArray(3 + capture_count); 3109 Handle<FixedArray> elements = Factory::NewFixedArray(3 + capture_count);
3108 elements->set(0, *Factory::NewSubString(subject, 3110 Handle<String> match = Factory::NewSubString(subject,
3109 match_start, 3111 match_start,
3110 match_end)); 3112 match_end);
3113 elements->set(0, *match);
3111 for (int i = 1; i <= capture_count; i++) { 3114 for (int i = 1; i <= capture_count; i++) {
3112 int start = register_vector[i * 2]; 3115 int start = register_vector[i * 2];
3113 if (start >= 0) { 3116 if (start >= 0) {
3114 int end = register_vector[i * 2 + 1]; 3117 int end = register_vector[i * 2 + 1];
3115 ASSERT(start <= end); 3118 ASSERT(start <= end);
3116 Handle<String> substring = Factory::NewSubString(subject, 3119 Handle<String> substring = Factory::NewSubString(subject,
3117 start, 3120 start,
3118 end); 3121 end);
3119 elements->set(i, *substring); 3122 elements->set(i, *substring);
3120 } else { 3123 } else {
(...skipping 1825 matching lines...) Expand 10 before | Expand all | Expand 10 after
4946 elements = Handle<FixedArray>(FixedArray::cast(obj)); 4949 elements = Handle<FixedArray>(FixedArray::cast(obj));
4947 4950
4948 Vector<const char> chars = s->ToAsciiVector(); 4951 Vector<const char> chars = s->ToAsciiVector();
4949 // Note, this will initialize all elements (not only the prefix) 4952 // Note, this will initialize all elements (not only the prefix)
4950 // to prevent GC from seeing partially initialized array. 4953 // to prevent GC from seeing partially initialized array.
4951 int num_copied_from_cache = CopyCachedAsciiCharsToArray(chars.start(), 4954 int num_copied_from_cache = CopyCachedAsciiCharsToArray(chars.start(),
4952 *elements, 4955 *elements,
4953 length); 4956 length);
4954 4957
4955 for (int i = num_copied_from_cache; i < length; ++i) { 4958 for (int i = num_copied_from_cache; i < length; ++i) {
4956 elements->set(i, *LookupSingleCharacterStringFromCode(chars[i])); 4959 Handle<Object> str = LookupSingleCharacterStringFromCode(chars[i]);
4960 elements->set(i, *str);
4957 } 4961 }
4958 } else { 4962 } else {
4959 elements = Factory::NewFixedArray(length); 4963 elements = Factory::NewFixedArray(length);
4960 for (int i = 0; i < length; ++i) { 4964 for (int i = 0; i < length; ++i) {
4961 elements->set(i, *LookupSingleCharacterStringFromCode(s->Get(i))); 4965 Handle<Object> str = LookupSingleCharacterStringFromCode(s->Get(i));
4966 elements->set(i, *str);
4962 } 4967 }
4963 } 4968 }
4964 4969
4965 #ifdef DEBUG 4970 #ifdef DEBUG
4966 for (int i = 0; i < length; ++i) { 4971 for (int i = 0; i < length; ++i) {
4967 ASSERT(String::cast(elements->get(i))->length() == 1); 4972 ASSERT(String::cast(elements->get(i))->length() == 1);
4968 } 4973 }
4969 #endif 4974 #endif
4970 4975
4971 return *Factory::NewJSArrayWithElements(elements); 4976 return *Factory::NewJSArrayWithElements(elements);
(...skipping 2847 matching lines...) Expand 10 before | Expand all | Expand 10 after
7819 if (obj->IsJSGlobalProxy()) { 7824 if (obj->IsJSGlobalProxy()) {
7820 obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype())); 7825 obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype()));
7821 } 7826 }
7822 7827
7823 7828
7824 // Check if the name is trivially convertible to an index and get the element 7829 // Check if the name is trivially convertible to an index and get the element
7825 // if so. 7830 // if so.
7826 uint32_t index; 7831 uint32_t index;
7827 if (name->AsArrayIndex(&index)) { 7832 if (name->AsArrayIndex(&index)) {
7828 Handle<FixedArray> details = Factory::NewFixedArray(2); 7833 Handle<FixedArray> details = Factory::NewFixedArray(2);
7829 details->set(0, Runtime::GetElementOrCharAt(obj, index)); 7834 Object* element_or_char = Runtime::GetElementOrCharAt(obj, index);
7835 details->set(0, element_or_char);
7830 details->set(1, PropertyDetails(NONE, NORMAL).AsSmi()); 7836 details->set(1, PropertyDetails(NONE, NORMAL).AsSmi());
7831 return *Factory::NewJSArrayWithElements(details); 7837 return *Factory::NewJSArrayWithElements(details);
7832 } 7838 }
7833 7839
7834 // Find the number of objects making up this. 7840 // Find the number of objects making up this.
7835 int length = LocalPrototypeChainLength(*obj); 7841 int length = LocalPrototypeChainLength(*obj);
7836 7842
7837 // Try local lookup on each of the objects. 7843 // Try local lookup on each of the objects.
7838 Handle<JSObject> jsproto = obj; 7844 Handle<JSObject> jsproto = obj;
7839 for (int i = 0; i < length; i++) { 7845 for (int i = 0; i < length; i++) {
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
8621 if (it.Done()) { 8627 if (it.Done()) {
8622 return Heap::undefined_value(); 8628 return Heap::undefined_value();
8623 } 8629 }
8624 8630
8625 // Calculate the size of the result. 8631 // Calculate the size of the result.
8626 int details_size = kScopeDetailsSize; 8632 int details_size = kScopeDetailsSize;
8627 Handle<FixedArray> details = Factory::NewFixedArray(details_size); 8633 Handle<FixedArray> details = Factory::NewFixedArray(details_size);
8628 8634
8629 // Fill in scope details. 8635 // Fill in scope details.
8630 details->set(kScopeDetailsTypeIndex, Smi::FromInt(it.Type())); 8636 details->set(kScopeDetailsTypeIndex, Smi::FromInt(it.Type()));
8631 details->set(kScopeDetailsObjectIndex, *it.ScopeObject()); 8637 Handle<JSObject> scope_object = it.ScopeObject();
8638 details->set(kScopeDetailsObjectIndex, *scope_object);
8632 8639
8633 return *Factory::NewJSArrayWithElements(details); 8640 return *Factory::NewJSArrayWithElements(details);
8634 } 8641 }
8635 8642
8636 8643
8637 static Object* Runtime_DebugPrintScopes(Arguments args) { 8644 static Object* Runtime_DebugPrintScopes(Arguments args) {
8638 HandleScope scope; 8645 HandleScope scope;
8639 ASSERT(args.length() == 0); 8646 ASSERT(args.length() == 0);
8640 8647
8641 #ifdef DEBUG 8648 #ifdef DEBUG
(...skipping 24 matching lines...) Expand all
8666 int frames_count = OS::StackWalk(frames); 8673 int frames_count = OS::StackWalk(frames);
8667 if (frames_count == OS::kStackWalkError) { 8674 if (frames_count == OS::kStackWalkError) {
8668 return Heap::undefined_value(); 8675 return Heap::undefined_value();
8669 } 8676 }
8670 8677
8671 Handle<String> address_str = Factory::LookupAsciiSymbol("address"); 8678 Handle<String> address_str = Factory::LookupAsciiSymbol("address");
8672 Handle<String> text_str = Factory::LookupAsciiSymbol("text"); 8679 Handle<String> text_str = Factory::LookupAsciiSymbol("text");
8673 Handle<FixedArray> frames_array = Factory::NewFixedArray(frames_count); 8680 Handle<FixedArray> frames_array = Factory::NewFixedArray(frames_count);
8674 for (int i = 0; i < frames_count; i++) { 8681 for (int i = 0; i < frames_count; i++) {
8675 Handle<JSObject> frame_value = Factory::NewJSObject(Top::object_function()); 8682 Handle<JSObject> frame_value = Factory::NewJSObject(Top::object_function());
8676 frame_value->SetProperty( 8683 Handle<Object> frame_address =
8677 *address_str, 8684 Factory::NewNumberFromInt(reinterpret_cast<int>(frames[i].address));
8678 *Factory::NewNumberFromInt(reinterpret_cast<int>(frames[i].address)), 8685
8679 NONE); 8686 frame_value->SetProperty(*address_str, *frame_address, NONE);
8680 8687
8681 // Get the stack walk text for this frame. 8688 // Get the stack walk text for this frame.
8682 Handle<String> frame_text; 8689 Handle<String> frame_text;
8683 int frame_text_length = StrLength(frames[i].text); 8690 int frame_text_length = StrLength(frames[i].text);
8684 if (frame_text_length > 0) { 8691 if (frame_text_length > 0) {
8685 Vector<const char> str(frames[i].text, frame_text_length); 8692 Vector<const char> str(frames[i].text, frame_text_length);
8686 frame_text = Factory::NewStringFromAscii(str); 8693 frame_text = Factory::NewStringFromAscii(str);
8687 } 8694 }
8688 8695
8689 if (!frame_text.is_null()) { 8696 if (!frame_text.is_null()) {
(...skipping 1473 matching lines...) Expand 10 before | Expand all | Expand 10 after
10163 } else { 10170 } else {
10164 // Handle last resort GC and make sure to allow future allocations 10171 // Handle last resort GC and make sure to allow future allocations
10165 // to grow the heap without causing GCs (if possible). 10172 // to grow the heap without causing GCs (if possible).
10166 Counters::gc_last_resort_from_js.Increment(); 10173 Counters::gc_last_resort_from_js.Increment();
10167 Heap::CollectAllGarbage(false); 10174 Heap::CollectAllGarbage(false);
10168 } 10175 }
10169 } 10176 }
10170 10177
10171 10178
10172 } } // namespace v8::internal 10179 } } // namespace v8::internal
OLDNEW
« src/bootstrapper.cc ('K') | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698