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

Side by Side Diff: src/runtime.cc

Issue 651025: Removed asserts on attributes when setting elements. Will file a bug on not h... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 10 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 | « no previous file | 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 2942 matching lines...) Expand 10 before | Expand all | Expand 10 after
2953 } 2953 }
2954 2954
2955 // If the object isn't a JavaScript object, we ignore the store. 2955 // If the object isn't a JavaScript object, we ignore the store.
2956 if (!object->IsJSObject()) return *value; 2956 if (!object->IsJSObject()) return *value;
2957 2957
2958 Handle<JSObject> js_object = Handle<JSObject>::cast(object); 2958 Handle<JSObject> js_object = Handle<JSObject>::cast(object);
2959 2959
2960 // Check if the given key is an array index. 2960 // Check if the given key is an array index.
2961 uint32_t index; 2961 uint32_t index;
2962 if (Array::IndexFromObject(*key, &index)) { 2962 if (Array::IndexFromObject(*key, &index)) {
2963 ASSERT(attr == NONE);
2964
2965 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters 2963 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters
2966 // of a string using [] notation. We need to support this too in 2964 // of a string using [] notation. We need to support this too in
2967 // JavaScript. 2965 // JavaScript.
2968 // In the case of a String object we just need to redirect the assignment to 2966 // In the case of a String object we just need to redirect the assignment to
2969 // the underlying string if the index is in range. Since the underlying 2967 // the underlying string if the index is in range. Since the underlying
2970 // string does nothing with the assignment then we can ignore such 2968 // string does nothing with the assignment then we can ignore such
2971 // assignments. 2969 // assignments.
2972 if (js_object->IsStringObjectWithCharacterAt(index)) { 2970 if (js_object->IsStringObjectWithCharacterAt(index)) {
2973 return *value; 2971 return *value;
2974 } 2972 }
2975 2973
2976 Handle<Object> result = SetElement(js_object, index, value); 2974 Handle<Object> result = SetElement(js_object, index, value);
2977 if (result.is_null()) return Failure::Exception(); 2975 if (result.is_null()) return Failure::Exception();
2978 return *value; 2976 return *value;
2979 } 2977 }
2980 2978
2981 if (key->IsString()) { 2979 if (key->IsString()) {
2982 Handle<Object> result; 2980 Handle<Object> result;
2983 if (Handle<String>::cast(key)->AsArrayIndex(&index)) { 2981 if (Handle<String>::cast(key)->AsArrayIndex(&index)) {
2984 ASSERT(attr == NONE);
2985 result = SetElement(js_object, index, value); 2982 result = SetElement(js_object, index, value);
2986 } else { 2983 } else {
2987 Handle<String> key_string = Handle<String>::cast(key); 2984 Handle<String> key_string = Handle<String>::cast(key);
2988 key_string->TryFlattenIfNotFlat(); 2985 key_string->TryFlattenIfNotFlat();
2989 result = SetProperty(js_object, key_string, value, attr); 2986 result = SetProperty(js_object, key_string, value, attr);
2990 } 2987 }
2991 if (result.is_null()) return Failure::Exception(); 2988 if (result.is_null()) return Failure::Exception();
2992 return *value; 2989 return *value;
2993 } 2990 }
2994 2991
2995 // Call-back into JavaScript to convert the key to a string. 2992 // Call-back into JavaScript to convert the key to a string.
2996 bool has_pending_exception = false; 2993 bool has_pending_exception = false;
2997 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); 2994 Handle<Object> converted = Execution::ToString(key, &has_pending_exception);
2998 if (has_pending_exception) return Failure::Exception(); 2995 if (has_pending_exception) return Failure::Exception();
2999 Handle<String> name = Handle<String>::cast(converted); 2996 Handle<String> name = Handle<String>::cast(converted);
3000 2997
3001 if (name->AsArrayIndex(&index)) { 2998 if (name->AsArrayIndex(&index)) {
3002 ASSERT(attr == NONE);
3003 return js_object->SetElement(index, *value); 2999 return js_object->SetElement(index, *value);
3004 } else { 3000 } else {
3005 return js_object->SetProperty(*name, *value, attr); 3001 return js_object->SetProperty(*name, *value, attr);
3006 } 3002 }
3007 } 3003 }
3008 3004
3009 3005
3010 Object* Runtime::ForceSetObjectProperty(Handle<JSObject> js_object, 3006 Object* Runtime::ForceSetObjectProperty(Handle<JSObject> js_object,
3011 Handle<Object> key, 3007 Handle<Object> key,
3012 Handle<Object> value, 3008 Handle<Object> value,
3013 PropertyAttributes attr) { 3009 PropertyAttributes attr) {
3014 HandleScope scope; 3010 HandleScope scope;
3015 3011
3016 // Check if the given key is an array index. 3012 // Check if the given key is an array index.
3017 uint32_t index; 3013 uint32_t index;
3018 if (Array::IndexFromObject(*key, &index)) { 3014 if (Array::IndexFromObject(*key, &index)) {
3019 ASSERT(attr == NONE);
3020
3021 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters 3015 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters
3022 // of a string using [] notation. We need to support this too in 3016 // of a string using [] notation. We need to support this too in
3023 // JavaScript. 3017 // JavaScript.
3024 // In the case of a String object we just need to redirect the assignment to 3018 // In the case of a String object we just need to redirect the assignment to
3025 // the underlying string if the index is in range. Since the underlying 3019 // the underlying string if the index is in range. Since the underlying
3026 // string does nothing with the assignment then we can ignore such 3020 // string does nothing with the assignment then we can ignore such
3027 // assignments. 3021 // assignments.
3028 if (js_object->IsStringObjectWithCharacterAt(index)) { 3022 if (js_object->IsStringObjectWithCharacterAt(index)) {
3029 return *value; 3023 return *value;
3030 } 3024 }
3031 3025
3032 return js_object->SetElement(index, *value); 3026 return js_object->SetElement(index, *value);
3033 } 3027 }
3034 3028
3035 if (key->IsString()) { 3029 if (key->IsString()) {
3036 if (Handle<String>::cast(key)->AsArrayIndex(&index)) { 3030 if (Handle<String>::cast(key)->AsArrayIndex(&index)) {
3037 ASSERT(attr == NONE);
3038 return js_object->SetElement(index, *value); 3031 return js_object->SetElement(index, *value);
3039 } else { 3032 } else {
3040 Handle<String> key_string = Handle<String>::cast(key); 3033 Handle<String> key_string = Handle<String>::cast(key);
3041 key_string->TryFlattenIfNotFlat(); 3034 key_string->TryFlattenIfNotFlat();
3042 return js_object->IgnoreAttributesAndSetLocalProperty(*key_string, 3035 return js_object->IgnoreAttributesAndSetLocalProperty(*key_string,
3043 *value, 3036 *value,
3044 attr); 3037 attr);
3045 } 3038 }
3046 } 3039 }
3047 3040
3048 // Call-back into JavaScript to convert the key to a string. 3041 // Call-back into JavaScript to convert the key to a string.
3049 bool has_pending_exception = false; 3042 bool has_pending_exception = false;
3050 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); 3043 Handle<Object> converted = Execution::ToString(key, &has_pending_exception);
3051 if (has_pending_exception) return Failure::Exception(); 3044 if (has_pending_exception) return Failure::Exception();
3052 Handle<String> name = Handle<String>::cast(converted); 3045 Handle<String> name = Handle<String>::cast(converted);
3053 3046
3054 if (name->AsArrayIndex(&index)) { 3047 if (name->AsArrayIndex(&index)) {
3055 ASSERT(attr == NONE);
3056 return js_object->SetElement(index, *value); 3048 return js_object->SetElement(index, *value);
3057 } else { 3049 } else {
3058 return js_object->IgnoreAttributesAndSetLocalProperty(*name, *value, attr); 3050 return js_object->IgnoreAttributesAndSetLocalProperty(*name, *value, attr);
3059 } 3051 }
3060 } 3052 }
3061 3053
3062 3054
3063 Object* Runtime::ForceDeleteObjectProperty(Handle<JSObject> js_object, 3055 Object* Runtime::ForceDeleteObjectProperty(Handle<JSObject> js_object,
3064 Handle<Object> key) { 3056 Handle<Object> key) {
3065 HandleScope scope; 3057 HandleScope scope;
(...skipping 5116 matching lines...) Expand 10 before | Expand all | Expand 10 after
8182 } else { 8174 } else {
8183 // Handle last resort GC and make sure to allow future allocations 8175 // Handle last resort GC and make sure to allow future allocations
8184 // to grow the heap without causing GCs (if possible). 8176 // to grow the heap without causing GCs (if possible).
8185 Counters::gc_last_resort_from_js.Increment(); 8177 Counters::gc_last_resort_from_js.Increment();
8186 Heap::CollectAllGarbage(false); 8178 Heap::CollectAllGarbage(false);
8187 } 8179 }
8188 } 8180 }
8189 8181
8190 8182
8191 } } // namespace v8::internal 8183 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698