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

Side by Side Diff: src/runtime.cc

Issue 572005: Added extra tests to the DefineOrRedefineAccessorProperty and ... (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 | test/mjsunit/object-define-property.js » ('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 2880 matching lines...) Expand 10 before | Expand all | Expand 10 after
2891 static Object* Runtime_DefineOrRedefineAccessorProperty(Arguments args) { 2891 static Object* Runtime_DefineOrRedefineAccessorProperty(Arguments args) {
2892 ASSERT(args.length() == 5); 2892 ASSERT(args.length() == 5);
2893 HandleScope scope; 2893 HandleScope scope;
2894 Handle<JSObject> obj = args.at<JSObject>(0); 2894 Handle<JSObject> obj = args.at<JSObject>(0);
2895 CONVERT_CHECKED(String, name, args[1]); 2895 CONVERT_CHECKED(String, name, args[1]);
2896 CONVERT_CHECKED(Smi, flag_setter, args[2]); 2896 CONVERT_CHECKED(Smi, flag_setter, args[2]);
2897 CONVERT_CHECKED(JSFunction, fun, args[3]); 2897 CONVERT_CHECKED(JSFunction, fun, args[3]);
2898 CONVERT_CHECKED(Smi, flag_attr, args[4]); 2898 CONVERT_CHECKED(Smi, flag_attr, args[4]);
2899 int unchecked = flag_attr->value(); 2899 int unchecked = flag_attr->value();
2900 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); 2900 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
2901 2901 RUNTIME_ASSERT(!obj->IsNull());
2902 LookupResult result; 2902 LookupResult result;
2903 obj->LocalLookupRealNamedProperty(name, &result); 2903 obj->LocalLookupRealNamedProperty(name, &result);
2904 2904
2905 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked); 2905 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked);
2906 // If an existing property is either FIELD, NORMAL or CONSTANT_FUNCTION 2906 // If an existing property is either FIELD, NORMAL or CONSTANT_FUNCTION
2907 // delete it to avoid running into trouble in DefineAccessor, which 2907 // delete it to avoid running into trouble in DefineAccessor, which
2908 // handles this incorrectly if the property is readonly (does nothing) 2908 // handles this incorrectly if the property is readonly (does nothing)
2909 if (result.IsValid() && 2909 if (result.IsValid() &&
2910 (result.type() == FIELD || result.type() == NORMAL 2910 (result.type() == FIELD || result.type() == NORMAL
2911 || result.type() == CONSTANT_FUNCTION)) { 2911 || result.type() == CONSTANT_FUNCTION)) {
2912 obj->DeleteProperty(name, JSObject::NORMAL_DELETION); 2912 obj->DeleteProperty(name, JSObject::NORMAL_DELETION);
2913 } 2913 }
2914 return obj->DefineAccessor(name, flag_setter->value() == 0, fun, attr); 2914 return obj->DefineAccessor(name, flag_setter->value() == 0, fun, attr);
2915 } 2915 }
2916 2916
2917 static Object* Runtime_DefineOrRedefineDataProperty(Arguments args) { 2917 static Object* Runtime_DefineOrRedefineDataProperty(Arguments args) {
2918 ASSERT(args.length() == 4); 2918 ASSERT(args.length() == 4);
2919 HandleScope scope; 2919 HandleScope scope;
2920 Handle<Object> obj = args.at<Object>(0); 2920 CONVERT_ARG_CHECKED(JSObject, js_object, 0);
2921 Handle<Object> name = args.at<Object>(1); 2921 CONVERT_ARG_CHECKED(String, name, 1);
2922 Handle<Object> obj_value = args.at<Object>(2); 2922 Handle<Object> obj_value = args.at<Object>(2);
2923 Handle<JSObject> js_object = Handle<JSObject>::cast(obj); 2923
2924 Handle<String> key_string = Handle<String>::cast(name);
2925
2926 CONVERT_CHECKED(Smi, flag, args[3]); 2924 CONVERT_CHECKED(Smi, flag, args[3]);
2927 int unchecked = flag->value(); 2925 int unchecked = flag->value();
2928 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); 2926 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
2929 2927
2930 LookupResult result; 2928 LookupResult result;
2931 js_object->LocalLookupRealNamedProperty(*key_string, &result); 2929 js_object->LocalLookupRealNamedProperty(*name, &result);
2932 2930
2933 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked); 2931 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked);
2934 2932
2935 // Take special care when attributes are different and there is already 2933 // Take special care when attributes are different and there is already
2936 // a property. For simplicity we normalize the property which enables us 2934 // a property. For simplicity we normalize the property which enables us
2937 // to not worry about changing the instance_descriptor and creating a new 2935 // to not worry about changing the instance_descriptor and creating a new
2938 // map. The current version of SetObjectProperty does not handle attributes 2936 // map. The current version of SetObjectProperty does not handle attributes
2939 // correctly in the case where a property is a field and is reset with 2937 // correctly in the case where a property is a field and is reset with
2940 // new attributes. 2938 // new attributes.
2941 if (result.IsProperty() && attr != result.GetAttributes()) { 2939 if (result.IsProperty() && attr != result.GetAttributes()) {
2942 PropertyDetails details = PropertyDetails(attr, NORMAL); 2940 PropertyDetails details = PropertyDetails(attr, NORMAL);
2943 // New attributes - normalize to avoid writing to instance descriptor 2941 // New attributes - normalize to avoid writing to instance descriptor
2944 js_object->NormalizeProperties(KEEP_INOBJECT_PROPERTIES, 0); 2942 js_object->NormalizeProperties(KEEP_INOBJECT_PROPERTIES, 0);
2945 return js_object->SetNormalizedProperty(*key_string, *obj_value, details); 2943 return js_object->SetNormalizedProperty(*name, *obj_value, details);
2946 } 2944 }
2947 2945
2948 return Runtime::SetObjectProperty(js_object, name, obj_value, attr); 2946 return Runtime::SetObjectProperty(js_object, name, obj_value, attr);
2949 } 2947 }
2950 2948
2951 2949
2952 Object* Runtime::SetObjectProperty(Handle<Object> object, 2950 Object* Runtime::SetObjectProperty(Handle<Object> object,
2953 Handle<Object> key, 2951 Handle<Object> key,
2954 Handle<Object> value, 2952 Handle<Object> value,
2955 PropertyAttributes attr) { 2953 PropertyAttributes attr) {
(...skipping 5287 matching lines...) Expand 10 before | Expand all | Expand 10 after
8243 } else { 8241 } else {
8244 // Handle last resort GC and make sure to allow future allocations 8242 // Handle last resort GC and make sure to allow future allocations
8245 // to grow the heap without causing GCs (if possible). 8243 // to grow the heap without causing GCs (if possible).
8246 Counters::gc_last_resort_from_js.Increment(); 8244 Counters::gc_last_resort_from_js.Increment();
8247 Heap::CollectAllGarbage(false); 8245 Heap::CollectAllGarbage(false);
8248 } 8246 }
8249 } 8247 }
8250 8248
8251 8249
8252 } } // namespace v8::internal 8250 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/object-define-property.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698