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

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
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 3496 matching lines...) Expand 10 before | Expand all | Expand 10 after
3507 // Fall back to GetObjectProperty. 3507 // Fall back to GetObjectProperty.
3508 return Runtime::GetObjectProperty(args.at<Object>(0), 3508 return Runtime::GetObjectProperty(args.at<Object>(0),
3509 args.at<Object>(1)); 3509 args.at<Object>(1));
3510 } 3510 }
3511 3511
3512 3512
3513 static MaybeObject* Runtime_DefineOrRedefineAccessorProperty(Arguments args) { 3513 static MaybeObject* Runtime_DefineOrRedefineAccessorProperty(Arguments args) {
3514 ASSERT(args.length() == 5); 3514 ASSERT(args.length() == 5);
3515 HandleScope scope; 3515 HandleScope scope;
3516 CONVERT_ARG_CHECKED(JSObject, obj, 0); 3516 CONVERT_ARG_CHECKED(JSObject, obj, 0);
3517 CONVERT_CHECKED(String, name, args[1]); 3517 CONVERT_CHECKED(String, name, args[1]);
Lasse Reichstein 2010/12/16 09:43:34 This argument is not stored in a handle, so why us
Rico 2010/12/16 12:17:55 Done.
3518 CONVERT_CHECKED(Smi, flag_setter, args[2]); 3518 CONVERT_CHECKED(Smi, flag_setter, args[2]);
3519 CONVERT_CHECKED(JSFunction, fun, args[3]); 3519 Handle<Object> fun = args.at<Object>(3);
3520 RUNTIME_ASSERT(fun->IsJSFunction() || fun->IsUndefined());
3520 CONVERT_CHECKED(Smi, flag_attr, args[4]); 3521 CONVERT_CHECKED(Smi, flag_attr, args[4]);
3521 int unchecked = flag_attr->value(); 3522 int unchecked = flag_attr->value();
3522 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); 3523 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
3523 RUNTIME_ASSERT(!obj->IsNull()); 3524 RUNTIME_ASSERT(!obj->IsNull());
3524 LookupResult result; 3525 LookupResult result;
3525 obj->LocalLookupRealNamedProperty(name, &result); 3526 obj->LocalLookupRealNamedProperty(name, &result);
3526 3527
3527 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked); 3528 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked);
3528 // If an existing property is either FIELD, NORMAL or CONSTANT_FUNCTION 3529 // If an existing property is either FIELD, NORMAL or CONSTANT_FUNCTION
3529 // delete it to avoid running into trouble in DefineAccessor, which 3530 // delete it to avoid running into trouble in DefineAccessor, which
3530 // handles this incorrectly if the property is readonly (does nothing) 3531 // handles this incorrectly if the property is readonly (does nothing)
3531 if (result.IsProperty() && 3532 if (result.IsProperty() &&
3532 (result.type() == FIELD || result.type() == NORMAL 3533 (result.type() == FIELD || result.type() == NORMAL
3533 || result.type() == CONSTANT_FUNCTION)) { 3534 || result.type() == CONSTANT_FUNCTION)) {
3534 Object* ok; 3535 Object* ok;
3535 { MaybeObject* maybe_ok = 3536 { MaybeObject* maybe_ok =
3536 obj->DeleteProperty(name, JSObject::NORMAL_DELETION); 3537 obj->DeleteProperty(name, JSObject::NORMAL_DELETION);
3537 if (!maybe_ok->ToObject(&ok)) return maybe_ok; 3538 if (!maybe_ok->ToObject(&ok)) return maybe_ok;
3538 } 3539 }
3539 } 3540 }
3540 return obj->DefineAccessor(name, flag_setter->value() == 0, fun, attr); 3541 return obj->DefineAccessor(name, flag_setter->value() == 0, *fun, attr);
3541 } 3542 }
3542 3543
3543 static MaybeObject* Runtime_DefineOrRedefineDataProperty(Arguments args) { 3544 static MaybeObject* Runtime_DefineOrRedefineDataProperty(Arguments args) {
3544 ASSERT(args.length() == 4); 3545 ASSERT(args.length() == 4);
3545 HandleScope scope; 3546 HandleScope scope;
3546 CONVERT_ARG_CHECKED(JSObject, js_object, 0); 3547 CONVERT_ARG_CHECKED(JSObject, js_object, 0);
3547 CONVERT_ARG_CHECKED(String, name, 1); 3548 CONVERT_ARG_CHECKED(String, name, 1);
3548 Handle<Object> obj_value = args.at<Object>(2); 3549 Handle<Object> obj_value = args.at<Object>(2);
3549 3550
3550 CONVERT_CHECKED(Smi, flag, args[3]); 3551 CONVERT_CHECKED(Smi, flag, args[3]);
(...skipping 14 matching lines...) Expand all
3565 // Normalize the elements to enable attributes on the property. 3566 // Normalize the elements to enable attributes on the property.
3566 NormalizeElements(js_object); 3567 NormalizeElements(js_object);
3567 Handle<NumberDictionary> dictionary(js_object->element_dictionary()); 3568 Handle<NumberDictionary> dictionary(js_object->element_dictionary());
3568 // Make sure that we never go back to fast case. 3569 // Make sure that we never go back to fast case.
3569 dictionary->set_requires_slow_elements(); 3570 dictionary->set_requires_slow_elements();
3570 PropertyDetails details = PropertyDetails(attr, NORMAL); 3571 PropertyDetails details = PropertyDetails(attr, NORMAL);
3571 NumberDictionarySet(dictionary, index, obj_value, details); 3572 NumberDictionarySet(dictionary, index, obj_value, details);
3572 } 3573 }
3573 3574
3574 LookupResult result; 3575 LookupResult result;
3575 js_object->LocalLookupRealNamedProperty(*name, &result); 3576 js_object->LookupRealNamedProperty(*name, &result);
3576 3577
3577 // Take special care when attributes are different and there is already 3578 // Take special care when attributes are different and there is already
3578 // a property. For simplicity we normalize the property which enables us 3579 // a property. For simplicity we normalize the property which enables us
3579 // to not worry about changing the instance_descriptor and creating a new 3580 // to not worry about changing the instance_descriptor and creating a new
3580 // map. The current version of SetObjectProperty does not handle attributes 3581 // map. The current version of SetObjectProperty does not handle attributes
3581 // correctly in the case where a property is a field and is reset with 3582 // correctly in the case where a property is a field and is reset with
3582 // new attributes. 3583 // new attributes.
3583 if (result.IsProperty() && attr != result.GetAttributes()) { 3584 if (result.IsProperty() &&
3585 (attr != result.GetAttributes() || result.type() == CALLBACKS)) {
3584 // New attributes - normalize to avoid writing to instance descriptor 3586 // New attributes - normalize to avoid writing to instance descriptor
3585 NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0); 3587 NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0);
3586 // Use IgnoreAttributes version since a readonly property may be 3588 // Use IgnoreAttributes version since a readonly property may be
3587 // overridden and SetProperty does not allow this. 3589 // overridden and SetProperty does not allow this.
3588 return js_object->IgnoreAttributesAndSetLocalProperty(*name, 3590 return js_object->IgnoreAttributesAndSetLocalProperty(*name,
3589 *obj_value, 3591 *obj_value,
3590 attr); 3592 attr);
3591 } 3593 }
3592 3594
3593 return Runtime::SetObjectProperty(js_object, name, obj_value, attr); 3595 return Runtime::SetObjectProperty(js_object, name, obj_value, attr);
(...skipping 7211 matching lines...) Expand 10 before | Expand all | Expand 10 after
10805 } else { 10807 } else {
10806 // Handle last resort GC and make sure to allow future allocations 10808 // Handle last resort GC and make sure to allow future allocations
10807 // to grow the heap without causing GCs (if possible). 10809 // to grow the heap without causing GCs (if possible).
10808 Counters::gc_last_resort_from_js.Increment(); 10810 Counters::gc_last_resort_from_js.Increment();
10809 Heap::CollectAllGarbage(false); 10811 Heap::CollectAllGarbage(false);
10810 } 10812 }
10811 } 10813 }
10812 10814
10813 10815
10814 } } // namespace v8::internal 10816 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | src/v8natives.js » ('j') | src/v8natives.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698