OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 3977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3988 // of a string using [] notation. We need to support this too in | 3988 // of a string using [] notation. We need to support this too in |
3989 // JavaScript. | 3989 // JavaScript. |
3990 // In the case of a String object we just need to redirect the assignment to | 3990 // In the case of a String object we just need to redirect the assignment to |
3991 // the underlying string if the index is in range. Since the underlying | 3991 // the underlying string if the index is in range. Since the underlying |
3992 // string does nothing with the assignment then we can ignore such | 3992 // string does nothing with the assignment then we can ignore such |
3993 // assignments. | 3993 // assignments. |
3994 if (js_object->IsStringObjectWithCharacterAt(index)) { | 3994 if (js_object->IsStringObjectWithCharacterAt(index)) { |
3995 return *value; | 3995 return *value; |
3996 } | 3996 } |
3997 | 3997 |
3998 // Special case for elements if any of the flags are true. | |
3999 // If elements are in fast case we always implicitly assume that: | |
4000 // DONT_DELETE: false, DONT_ENUM: false, READ_ONLY: false. | |
4001 if (((attr & (DONT_DELETE | DONT_ENUM | READ_ONLY)) != 0)) { | |
4002 // Normalize the elements to enable attributes on the property. | |
4003 NormalizeElements(js_object); | |
4004 Handle<NumberDictionary> dictionary(js_object->element_dictionary()); | |
4005 // Make sure that we never go back to fast case. | |
4006 dictionary->set_requires_slow_elements(); | |
4007 PropertyDetails details = PropertyDetails(attr, NORMAL); | |
4008 Handle<NumberDictionary> extended_dictionary = | |
4009 NumberDictionarySet(dictionary, index, value, details); | |
4010 if (*extended_dictionary != *dictionary) { | |
4011 js_object->set_elements(*extended_dictionary); | |
4012 } | |
4013 return *value; | |
4014 } | |
4015 | |
3998 Handle<Object> result = SetElement(js_object, index, value, strict_mode); | 4016 Handle<Object> result = SetElement(js_object, index, value, strict_mode); |
3999 if (result.is_null()) return Failure::Exception(); | 4017 if (result.is_null()) return Failure::Exception(); |
4000 return *value; | 4018 return *value; |
4001 } | 4019 } |
4002 | 4020 |
4003 if (key->IsString()) { | 4021 if (key->IsString()) { |
4004 Handle<Object> result; | 4022 Handle<Object> result; |
4005 if (Handle<String>::cast(key)->AsArrayIndex(&index)) { | 4023 if (Handle<String>::cast(key)->AsArrayIndex(&index)) { |
Erik Corry
2011/06/14 13:21:51
There's a ton of copied code here.
You could creat
Rico
2011/06/14 13:44:23
Done.
| |
4024 // Special case for elements if any of the flags are true. | |
4025 // If elements are in fast case we always implicitly assume that: | |
4026 // DONT_DELETE: false, DONT_ENUM: false, READ_ONLY: false. | |
4027 if (((attr & (DONT_DELETE | DONT_ENUM | READ_ONLY)) != 0)) { | |
4028 // Normalize the elements to enable attributes on the property. | |
4029 NormalizeElements(js_object); | |
4030 Handle<NumberDictionary> dictionary(js_object->element_dictionary()); | |
4031 // Make sure that we never go back to fast case. | |
4032 dictionary->set_requires_slow_elements(); | |
4033 PropertyDetails details = PropertyDetails(attr, NORMAL); | |
4034 Handle<NumberDictionary> extended_dictionary = | |
4035 NumberDictionarySet(dictionary, index, value, details); | |
4036 if (*extended_dictionary != *dictionary) { | |
4037 js_object->set_elements(*extended_dictionary); | |
4038 } | |
4039 return *value; | |
4040 } | |
4006 result = SetElement(js_object, index, value, strict_mode); | 4041 result = SetElement(js_object, index, value, strict_mode); |
4007 } else { | 4042 } else { |
4008 Handle<String> key_string = Handle<String>::cast(key); | 4043 Handle<String> key_string = Handle<String>::cast(key); |
4009 key_string->TryFlatten(); | 4044 key_string->TryFlatten(); |
4010 result = SetProperty(js_object, key_string, value, attr, strict_mode); | 4045 result = SetProperty(js_object, key_string, value, attr, strict_mode); |
4011 } | 4046 } |
4012 if (result.is_null()) return Failure::Exception(); | 4047 if (result.is_null()) return Failure::Exception(); |
4013 return *value; | 4048 return *value; |
4014 } | 4049 } |
4015 | 4050 |
(...skipping 8343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12359 } else { | 12394 } else { |
12360 // Handle last resort GC and make sure to allow future allocations | 12395 // Handle last resort GC and make sure to allow future allocations |
12361 // to grow the heap without causing GCs (if possible). | 12396 // to grow the heap without causing GCs (if possible). |
12362 isolate->counters()->gc_last_resort_from_js()->Increment(); | 12397 isolate->counters()->gc_last_resort_from_js()->Increment(); |
12363 isolate->heap()->CollectAllGarbage(false); | 12398 isolate->heap()->CollectAllGarbage(false); |
12364 } | 12399 } |
12365 } | 12400 } |
12366 | 12401 |
12367 | 12402 |
12368 } } // namespace v8::internal | 12403 } } // namespace v8::internal |
OLD | NEW |