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

Side by Side Diff: src/runtime.cc

Issue 5861006: Change Object.defineProperty to accept undefined as getters and setters and t... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years 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 | « src/objects.cc ('k') | src/v8natives.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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 3482 matching lines...) Expand 10 before | Expand all | Expand 10 after
3493 args.at<Object>(1)); 3493 args.at<Object>(1));
3494 } 3494 }
3495 3495
3496 3496
3497 static MaybeObject* Runtime_DefineOrRedefineAccessorProperty(Arguments args) { 3497 static MaybeObject* Runtime_DefineOrRedefineAccessorProperty(Arguments args) {
3498 ASSERT(args.length() == 5); 3498 ASSERT(args.length() == 5);
3499 HandleScope scope; 3499 HandleScope scope;
3500 CONVERT_ARG_CHECKED(JSObject, obj, 0); 3500 CONVERT_ARG_CHECKED(JSObject, obj, 0);
3501 CONVERT_CHECKED(String, name, args[1]); 3501 CONVERT_CHECKED(String, name, args[1]);
3502 CONVERT_CHECKED(Smi, flag_setter, args[2]); 3502 CONVERT_CHECKED(Smi, flag_setter, args[2]);
3503 CONVERT_CHECKED(JSFunction, fun, args[3]); 3503 Object* fun = args[3];
3504 RUNTIME_ASSERT(fun->IsJSFunction() || fun->IsUndefined());
3504 CONVERT_CHECKED(Smi, flag_attr, args[4]); 3505 CONVERT_CHECKED(Smi, flag_attr, args[4]);
3505 int unchecked = flag_attr->value(); 3506 int unchecked = flag_attr->value();
3506 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); 3507 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
3507 RUNTIME_ASSERT(!obj->IsNull()); 3508 RUNTIME_ASSERT(!obj->IsNull());
3508 LookupResult result; 3509 LookupResult result;
3509 obj->LocalLookupRealNamedProperty(name, &result); 3510 obj->LocalLookupRealNamedProperty(name, &result);
3510 3511
3511 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked); 3512 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked);
3512 // If an existing property is either FIELD, NORMAL or CONSTANT_FUNCTION 3513 // If an existing property is either FIELD, NORMAL or CONSTANT_FUNCTION
3513 // delete it to avoid running into trouble in DefineAccessor, which 3514 // delete it to avoid running into trouble in DefineAccessor, which
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3549 // Normalize the elements to enable attributes on the property. 3550 // Normalize the elements to enable attributes on the property.
3550 NormalizeElements(js_object); 3551 NormalizeElements(js_object);
3551 Handle<NumberDictionary> dictionary(js_object->element_dictionary()); 3552 Handle<NumberDictionary> dictionary(js_object->element_dictionary());
3552 // Make sure that we never go back to fast case. 3553 // Make sure that we never go back to fast case.
3553 dictionary->set_requires_slow_elements(); 3554 dictionary->set_requires_slow_elements();
3554 PropertyDetails details = PropertyDetails(attr, NORMAL); 3555 PropertyDetails details = PropertyDetails(attr, NORMAL);
3555 NumberDictionarySet(dictionary, index, obj_value, details); 3556 NumberDictionarySet(dictionary, index, obj_value, details);
3556 } 3557 }
3557 3558
3558 LookupResult result; 3559 LookupResult result;
3559 js_object->LocalLookupRealNamedProperty(*name, &result); 3560 js_object->LookupRealNamedProperty(*name, &result);
3560 3561
3561 // Take special care when attributes are different and there is already 3562 // Take special care when attributes are different and there is already
3562 // a property. For simplicity we normalize the property which enables us 3563 // a property. For simplicity we normalize the property which enables us
3563 // to not worry about changing the instance_descriptor and creating a new 3564 // to not worry about changing the instance_descriptor and creating a new
3564 // map. The current version of SetObjectProperty does not handle attributes 3565 // map. The current version of SetObjectProperty does not handle attributes
3565 // correctly in the case where a property is a field and is reset with 3566 // correctly in the case where a property is a field and is reset with
3566 // new attributes. 3567 // new attributes.
3567 if (result.IsProperty() && attr != result.GetAttributes()) { 3568 if (result.IsProperty() &&
3569 (attr != result.GetAttributes() || result.type() == CALLBACKS)) {
3568 // New attributes - normalize to avoid writing to instance descriptor 3570 // New attributes - normalize to avoid writing to instance descriptor
3569 NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0); 3571 NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0);
3570 // Use IgnoreAttributes version since a readonly property may be 3572 // Use IgnoreAttributes version since a readonly property may be
3571 // overridden and SetProperty does not allow this. 3573 // overridden and SetProperty does not allow this.
3572 return js_object->IgnoreAttributesAndSetLocalProperty(*name, 3574 return js_object->IgnoreAttributesAndSetLocalProperty(*name,
3573 *obj_value, 3575 *obj_value,
3574 attr); 3576 attr);
3575 } 3577 }
3576 3578
3577 return Runtime::SetObjectProperty(js_object, name, obj_value, attr); 3579 return Runtime::SetObjectProperty(js_object, name, obj_value, attr);
(...skipping 7216 matching lines...) Expand 10 before | Expand all | Expand 10 after
10794 } else { 10796 } else {
10795 // Handle last resort GC and make sure to allow future allocations 10797 // Handle last resort GC and make sure to allow future allocations
10796 // to grow the heap without causing GCs (if possible). 10798 // to grow the heap without causing GCs (if possible).
10797 Counters::gc_last_resort_from_js.Increment(); 10799 Counters::gc_last_resort_from_js.Increment();
10798 Heap::CollectAllGarbage(false); 10800 Heap::CollectAllGarbage(false);
10799 } 10801 }
10800 } 10802 }
10801 10803
10802 10804
10803 } } // namespace v8::internal 10805 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | src/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698