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

Side by Side Diff: src/runtime.cc

Issue 7149015: Correctly set ReadOnly flag on indexed properties when using the API Set method (fixes issue 1470) (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 6 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 | test/cctest/test-api.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 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 3917 matching lines...) Expand 10 before | Expand all | Expand 10 after
3928 } 3928 }
3929 3929
3930 return Runtime::ForceSetObjectProperty(isolate, 3930 return Runtime::ForceSetObjectProperty(isolate,
3931 js_object, 3931 js_object,
3932 name, 3932 name,
3933 obj_value, 3933 obj_value,
3934 attr); 3934 attr);
3935 } 3935 }
3936 3936
3937 3937
3938 // Special case for elements if any of the flags are true.
3939 // If elements are in fast case we always implicitly assume that:
3940 // DONT_DELETE: false, DONT_ENUM: false, READ_ONLY: false.
3941 static MaybeObject* NormalizeObjectSetElement(Isolate* isolate,
3942 Handle<JSObject> js_object,
3943 uint32_t index,
3944 Handle<Object> value,
3945 PropertyAttributes attr) {
3946 // Normalize the elements to enable attributes on the property.
3947 NormalizeElements(js_object);
3948 Handle<NumberDictionary> dictionary(js_object->element_dictionary());
3949 // Make sure that we never go back to fast case.
3950 dictionary->set_requires_slow_elements();
3951 PropertyDetails details = PropertyDetails(attr, NORMAL);
3952 Handle<NumberDictionary> extended_dictionary =
3953 NumberDictionarySet(dictionary, index, value, details);
3954 if (*extended_dictionary != *dictionary) {
3955 js_object->set_elements(*extended_dictionary);
3956 }
3957 return *value;
3958 }
3959
3960
3938 MaybeObject* Runtime::SetObjectProperty(Isolate* isolate, 3961 MaybeObject* Runtime::SetObjectProperty(Isolate* isolate,
3939 Handle<Object> object, 3962 Handle<Object> object,
3940 Handle<Object> key, 3963 Handle<Object> key,
3941 Handle<Object> value, 3964 Handle<Object> value,
3942 PropertyAttributes attr, 3965 PropertyAttributes attr,
3943 StrictModeFlag strict_mode) { 3966 StrictModeFlag strict_mode) {
3944 HandleScope scope(isolate); 3967 HandleScope scope(isolate);
3945 3968
3946 if (object->IsUndefined() || object->IsNull()) { 3969 if (object->IsUndefined() || object->IsNull()) {
3947 Handle<Object> args[2] = { key, object }; 3970 Handle<Object> args[2] = { key, object };
(...skipping 15 matching lines...) Expand all
3963 // of a string using [] notation. We need to support this too in 3986 // of a string using [] notation. We need to support this too in
3964 // JavaScript. 3987 // JavaScript.
3965 // In the case of a String object we just need to redirect the assignment to 3988 // In the case of a String object we just need to redirect the assignment to
3966 // the underlying string if the index is in range. Since the underlying 3989 // the underlying string if the index is in range. Since the underlying
3967 // string does nothing with the assignment then we can ignore such 3990 // string does nothing with the assignment then we can ignore such
3968 // assignments. 3991 // assignments.
3969 if (js_object->IsStringObjectWithCharacterAt(index)) { 3992 if (js_object->IsStringObjectWithCharacterAt(index)) {
3970 return *value; 3993 return *value;
3971 } 3994 }
3972 3995
3996 if (((attr & (DONT_DELETE | DONT_ENUM | READ_ONLY)) != 0)) {
3997 return NormalizeObjectSetElement(isolate, js_object, index, value, attr);
3998 }
3999
3973 Handle<Object> result = SetElement(js_object, index, value, strict_mode); 4000 Handle<Object> result = SetElement(js_object, index, value, strict_mode);
3974 if (result.is_null()) return Failure::Exception(); 4001 if (result.is_null()) return Failure::Exception();
3975 return *value; 4002 return *value;
3976 } 4003 }
3977 4004
3978 if (key->IsString()) { 4005 if (key->IsString()) {
3979 Handle<Object> result; 4006 Handle<Object> result;
3980 if (Handle<String>::cast(key)->AsArrayIndex(&index)) { 4007 if (Handle<String>::cast(key)->AsArrayIndex(&index)) {
4008 if (((attr & (DONT_DELETE | DONT_ENUM | READ_ONLY)) != 0)) {
4009 return NormalizeObjectSetElement(isolate,
4010 js_object,
4011 index,
4012 value,
4013 attr);
4014 }
3981 result = SetElement(js_object, index, value, strict_mode); 4015 result = SetElement(js_object, index, value, strict_mode);
3982 } else { 4016 } else {
3983 Handle<String> key_string = Handle<String>::cast(key); 4017 Handle<String> key_string = Handle<String>::cast(key);
3984 key_string->TryFlatten(); 4018 key_string->TryFlatten();
3985 result = SetProperty(js_object, key_string, value, attr, strict_mode); 4019 result = SetProperty(js_object, key_string, value, attr, strict_mode);
3986 } 4020 }
3987 if (result.is_null()) return Failure::Exception(); 4021 if (result.is_null()) return Failure::Exception();
3988 return *value; 4022 return *value;
3989 } 4023 }
3990 4024
(...skipping 8349 matching lines...) Expand 10 before | Expand all | Expand 10 after
12340 } else { 12374 } else {
12341 // Handle last resort GC and make sure to allow future allocations 12375 // Handle last resort GC and make sure to allow future allocations
12342 // to grow the heap without causing GCs (if possible). 12376 // to grow the heap without causing GCs (if possible).
12343 isolate->counters()->gc_last_resort_from_js()->Increment(); 12377 isolate->counters()->gc_last_resort_from_js()->Increment();
12344 isolate->heap()->CollectAllGarbage(false); 12378 isolate->heap()->CollectAllGarbage(false);
12345 } 12379 }
12346 } 12380 }
12347 12381
12348 12382
12349 } } // namespace v8::internal 12383 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698