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

Side by Side Diff: src/runtime.cc

Issue 6286060: Fix bugs 992, 1083 and 1092 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments Created 9 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 | « 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 3584 matching lines...) Expand 10 before | Expand all | Expand 10 after
3595 Handle<Object> result = GetCharAt(str, index); 3595 Handle<Object> result = GetCharAt(str, index);
3596 return *result; 3596 return *result;
3597 } 3597 }
3598 } 3598 }
3599 3599
3600 // Fall back to GetObjectProperty. 3600 // Fall back to GetObjectProperty.
3601 return Runtime::GetObjectProperty(args.at<Object>(0), 3601 return Runtime::GetObjectProperty(args.at<Object>(0),
3602 args.at<Object>(1)); 3602 args.at<Object>(1));
3603 } 3603 }
3604 3604
3605 3605 // Implements part of 8.12.9 DefineOwnProperty.
3606 // There are 3 cases that lead here:
3607 // Step 4b - define a new accessor property.
3608 // Steps 9c & 12 - replace an existing data property with an accessor property.
3609 // Step 12 - update an existing accessor property with an accessor or generic
3610 // descriptor.
3606 static MaybeObject* Runtime_DefineOrRedefineAccessorProperty(Arguments args) { 3611 static MaybeObject* Runtime_DefineOrRedefineAccessorProperty(Arguments args) {
3607 ASSERT(args.length() == 5); 3612 ASSERT(args.length() == 5);
3608 HandleScope scope; 3613 HandleScope scope;
3609 CONVERT_ARG_CHECKED(JSObject, obj, 0); 3614 CONVERT_ARG_CHECKED(JSObject, obj, 0);
3610 CONVERT_CHECKED(String, name, args[1]); 3615 CONVERT_CHECKED(String, name, args[1]);
3611 CONVERT_CHECKED(Smi, flag_setter, args[2]); 3616 CONVERT_CHECKED(Smi, flag_setter, args[2]);
3612 Object* fun = args[3]; 3617 Object* fun = args[3];
3613 RUNTIME_ASSERT(fun->IsJSFunction() || fun->IsUndefined()); 3618 RUNTIME_ASSERT(fun->IsJSFunction() || fun->IsUndefined());
3614 CONVERT_CHECKED(Smi, flag_attr, args[4]); 3619 CONVERT_CHECKED(Smi, flag_attr, args[4]);
3615 int unchecked = flag_attr->value(); 3620 int unchecked = flag_attr->value();
(...skipping 11 matching lines...) Expand all
3627 || result.type() == CONSTANT_FUNCTION)) { 3632 || result.type() == CONSTANT_FUNCTION)) {
3628 Object* ok; 3633 Object* ok;
3629 { MaybeObject* maybe_ok = 3634 { MaybeObject* maybe_ok =
3630 obj->DeleteProperty(name, JSObject::NORMAL_DELETION); 3635 obj->DeleteProperty(name, JSObject::NORMAL_DELETION);
3631 if (!maybe_ok->ToObject(&ok)) return maybe_ok; 3636 if (!maybe_ok->ToObject(&ok)) return maybe_ok;
3632 } 3637 }
3633 } 3638 }
3634 return obj->DefineAccessor(name, flag_setter->value() == 0, fun, attr); 3639 return obj->DefineAccessor(name, flag_setter->value() == 0, fun, attr);
3635 } 3640 }
3636 3641
3642 // Implements part of 8.12.9 DefineOwnProperty.
3643 // There are 3 cases that lead here:
3644 // Step 4a - define a new data property.
3645 // Steps 9b & 12 - replace an existing accessor property with a data property.
3646 // Step 12 - update an existing data property with a data or generic
3647 // descriptor.
3637 static MaybeObject* Runtime_DefineOrRedefineDataProperty(Arguments args) { 3648 static MaybeObject* Runtime_DefineOrRedefineDataProperty(Arguments args) {
3638 ASSERT(args.length() == 4); 3649 ASSERT(args.length() == 4);
3639 HandleScope scope; 3650 HandleScope scope;
3640 CONVERT_ARG_CHECKED(JSObject, js_object, 0); 3651 CONVERT_ARG_CHECKED(JSObject, js_object, 0);
3641 CONVERT_ARG_CHECKED(String, name, 1); 3652 CONVERT_ARG_CHECKED(String, name, 1);
3642 Handle<Object> obj_value = args.at<Object>(2); 3653 Handle<Object> obj_value = args.at<Object>(2);
3643 3654
3644 CONVERT_CHECKED(Smi, flag, args[3]); 3655 CONVERT_CHECKED(Smi, flag, args[3]);
3645 int unchecked = flag->value(); 3656 int unchecked = flag->value();
3646 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); 3657 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
3647 3658
3648 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked); 3659 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked);
3649 3660
3650 // Check if this is an element. 3661 // Check if this is an element.
3651 uint32_t index; 3662 uint32_t index;
3652 bool is_element = name->AsArrayIndex(&index); 3663 bool is_element = name->AsArrayIndex(&index);
3653 3664
3654 // Special case for elements if any of the flags are true. 3665 // Special case for elements if any of the flags are true.
3655 // If elements are in fast case we always implicitly assume that: 3666 // If elements are in fast case we always implicitly assume that:
3656 // DONT_DELETE: false, DONT_ENUM: false, READ_ONLY: false. 3667 // DONT_DELETE: false, DONT_ENUM: false, READ_ONLY: false.
3657 if (((unchecked & (DONT_DELETE | DONT_ENUM | READ_ONLY)) != 0) && 3668 if (((unchecked & (DONT_DELETE | DONT_ENUM | READ_ONLY)) != 0) &&
3658 is_element) { 3669 is_element) {
3659 // Normalize the elements to enable attributes on the property. 3670 // Normalize the elements to enable attributes on the property.
3660 NormalizeElements(js_object); 3671 if (!js_object->IsJSGlobalProxy()) {
3672 NormalizeElements(js_object);
3673 }
3661 Handle<NumberDictionary> dictionary(js_object->element_dictionary()); 3674 Handle<NumberDictionary> dictionary(js_object->element_dictionary());
3662 // Make sure that we never go back to fast case. 3675 // Make sure that we never go back to fast case.
3663 dictionary->set_requires_slow_elements(); 3676 dictionary->set_requires_slow_elements();
3664 PropertyDetails details = PropertyDetails(attr, NORMAL); 3677 PropertyDetails details = PropertyDetails(attr, NORMAL);
3665 NumberDictionarySet(dictionary, index, obj_value, details); 3678 NumberDictionarySet(dictionary, index, obj_value, details);
3666 } 3679 }
3667 3680
3668 LookupResult result; 3681 LookupResult result;
3669 js_object->LookupRealNamedProperty(*name, &result); 3682 js_object->LookupRealNamedProperty(*name, &result);
3670 3683
3671 // Take special care when attributes are different and there is already 3684 // Take special care when attributes are different and there is already
3672 // a property. For simplicity we normalize the property which enables us 3685 // a property. For simplicity we normalize the property which enables us
3673 // to not worry about changing the instance_descriptor and creating a new 3686 // to not worry about changing the instance_descriptor and creating a new
3674 // map. The current version of SetObjectProperty does not handle attributes 3687 // map. The current version of SetObjectProperty does not handle attributes
3675 // correctly in the case where a property is a field and is reset with 3688 // correctly in the case where a property is a field and is reset with
3676 // new attributes. 3689 // new attributes.
3677 if (result.IsProperty() && 3690 if (result.IsProperty() &&
3678 (attr != result.GetAttributes() || result.type() == CALLBACKS)) { 3691 (attr != result.GetAttributes() || result.type() == CALLBACKS)) {
3679 // New attributes - normalize to avoid writing to instance descriptor 3692 // New attributes - normalize to avoid writing to instance descriptor
3680 NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0); 3693 if (!js_object->IsJSGlobalProxy()) {
3694 NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0);
3695 }
3681 // Use IgnoreAttributes version since a readonly property may be 3696 // Use IgnoreAttributes version since a readonly property may be
3682 // overridden and SetProperty does not allow this. 3697 // overridden and SetProperty does not allow this.
3683 return js_object->SetLocalPropertyIgnoreAttributes(*name, 3698 return js_object->SetLocalPropertyIgnoreAttributes(*name,
3684 *obj_value, 3699 *obj_value,
3685 attr); 3700 attr);
3686 } 3701 }
3687 3702
3688 return Runtime::SetObjectProperty(js_object, name, obj_value, attr); 3703 return Runtime::SetObjectProperty(js_object, name, obj_value, attr);
3689 } 3704 }
3690 3705
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
4266 } 4281 }
4267 return *object; 4282 return *object;
4268 } 4283 }
4269 4284
4270 4285
4271 static MaybeObject* Runtime_ToSlowProperties(Arguments args) { 4286 static MaybeObject* Runtime_ToSlowProperties(Arguments args) {
4272 HandleScope scope; 4287 HandleScope scope;
4273 4288
4274 ASSERT(args.length() == 1); 4289 ASSERT(args.length() == 1);
4275 Handle<Object> object = args.at<Object>(0); 4290 Handle<Object> object = args.at<Object>(0);
4276 if (object->IsJSObject()) { 4291 if (object->IsJSObject() && !object->IsJSGlobalProxy()) {
4277 Handle<JSObject> js_object = Handle<JSObject>::cast(object); 4292 Handle<JSObject> js_object = Handle<JSObject>::cast(object);
4278 NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0); 4293 NormalizeProperties(js_object, CLEAR_INOBJECT_PROPERTIES, 0);
4279 } 4294 }
4280 return *object; 4295 return *object;
4281 } 4296 }
4282 4297
4283 4298
4284 static MaybeObject* Runtime_ToBool(Arguments args) { 4299 static MaybeObject* Runtime_ToBool(Arguments args) {
4285 NoHandleAllocation ha; 4300 NoHandleAllocation ha;
4286 ASSERT(args.length() == 1); 4301 ASSERT(args.length() == 1);
(...skipping 6728 matching lines...) Expand 10 before | Expand all | Expand 10 after
11015 } else { 11030 } else {
11016 // Handle last resort GC and make sure to allow future allocations 11031 // Handle last resort GC and make sure to allow future allocations
11017 // to grow the heap without causing GCs (if possible). 11032 // to grow the heap without causing GCs (if possible).
11018 Counters::gc_last_resort_from_js.Increment(); 11033 Counters::gc_last_resort_from_js.Increment();
11019 Heap::CollectAllGarbage(false); 11034 Heap::CollectAllGarbage(false);
11020 } 11035 }
11021 } 11036 }
11022 11037
11023 11038
11024 } } // namespace v8::internal 11039 } } // 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