| OLD | NEW |
| 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 3764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3775 } | 3775 } |
| 3776 | 3776 |
| 3777 return Runtime::ForceSetObjectProperty(js_object, name, obj_value, attr); | 3777 return Runtime::ForceSetObjectProperty(js_object, name, obj_value, attr); |
| 3778 } | 3778 } |
| 3779 | 3779 |
| 3780 | 3780 |
| 3781 MaybeObject* Runtime::SetObjectProperty(Handle<Object> object, | 3781 MaybeObject* Runtime::SetObjectProperty(Handle<Object> object, |
| 3782 Handle<Object> key, | 3782 Handle<Object> key, |
| 3783 Handle<Object> value, | 3783 Handle<Object> value, |
| 3784 PropertyAttributes attr, | 3784 PropertyAttributes attr, |
| 3785 StrictModeFlag strict) { | 3785 StrictModeFlag strict_mode) { |
| 3786 HandleScope scope; | 3786 HandleScope scope; |
| 3787 | 3787 |
| 3788 if (object->IsUndefined() || object->IsNull()) { | 3788 if (object->IsUndefined() || object->IsNull()) { |
| 3789 Handle<Object> args[2] = { key, object }; | 3789 Handle<Object> args[2] = { key, object }; |
| 3790 Handle<Object> error = | 3790 Handle<Object> error = |
| 3791 Factory::NewTypeError("non_object_property_store", | 3791 Factory::NewTypeError("non_object_property_store", |
| 3792 HandleVector(args, 2)); | 3792 HandleVector(args, 2)); |
| 3793 return Top::Throw(*error); | 3793 return Top::Throw(*error); |
| 3794 } | 3794 } |
| 3795 | 3795 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3818 return *value; | 3818 return *value; |
| 3819 } | 3819 } |
| 3820 | 3820 |
| 3821 if (key->IsString()) { | 3821 if (key->IsString()) { |
| 3822 Handle<Object> result; | 3822 Handle<Object> result; |
| 3823 if (Handle<String>::cast(key)->AsArrayIndex(&index)) { | 3823 if (Handle<String>::cast(key)->AsArrayIndex(&index)) { |
| 3824 result = SetElement(js_object, index, value); | 3824 result = SetElement(js_object, index, value); |
| 3825 } else { | 3825 } else { |
| 3826 Handle<String> key_string = Handle<String>::cast(key); | 3826 Handle<String> key_string = Handle<String>::cast(key); |
| 3827 key_string->TryFlatten(); | 3827 key_string->TryFlatten(); |
| 3828 result = SetProperty(js_object, key_string, value, attr, strict); | 3828 result = SetProperty(js_object, key_string, value, attr, strict_mode); |
| 3829 } | 3829 } |
| 3830 if (result.is_null()) return Failure::Exception(); | 3830 if (result.is_null()) return Failure::Exception(); |
| 3831 return *value; | 3831 return *value; |
| 3832 } | 3832 } |
| 3833 | 3833 |
| 3834 // Call-back into JavaScript to convert the key to a string. | 3834 // Call-back into JavaScript to convert the key to a string. |
| 3835 bool has_pending_exception = false; | 3835 bool has_pending_exception = false; |
| 3836 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); | 3836 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); |
| 3837 if (has_pending_exception) return Failure::Exception(); | 3837 if (has_pending_exception) return Failure::Exception(); |
| 3838 Handle<String> name = Handle<String>::cast(converted); | 3838 Handle<String> name = Handle<String>::cast(converted); |
| 3839 | 3839 |
| 3840 if (name->AsArrayIndex(&index)) { | 3840 if (name->AsArrayIndex(&index)) { |
| 3841 // TODO(1220): Implement SetElement strict mode. | 3841 // TODO(1220): Implement SetElement strict mode. |
| 3842 return js_object->SetElement(index, *value); | 3842 return js_object->SetElement(index, *value); |
| 3843 } else { | 3843 } else { |
| 3844 return js_object->SetProperty(*name, *value, attr, strict); | 3844 return js_object->SetProperty(*name, *value, attr, strict_mode); |
| 3845 } | 3845 } |
| 3846 } | 3846 } |
| 3847 | 3847 |
| 3848 | 3848 |
| 3849 MaybeObject* Runtime::ForceSetObjectProperty(Handle<JSObject> js_object, | 3849 MaybeObject* Runtime::ForceSetObjectProperty(Handle<JSObject> js_object, |
| 3850 Handle<Object> key, | 3850 Handle<Object> key, |
| 3851 Handle<Object> value, | 3851 Handle<Object> value, |
| 3852 PropertyAttributes attr) { | 3852 PropertyAttributes attr) { |
| 3853 HandleScope scope; | 3853 HandleScope scope; |
| 3854 | 3854 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3938 Handle<Object> object = args.at<Object>(0); | 3938 Handle<Object> object = args.at<Object>(0); |
| 3939 Handle<Object> key = args.at<Object>(1); | 3939 Handle<Object> key = args.at<Object>(1); |
| 3940 Handle<Object> value = args.at<Object>(2); | 3940 Handle<Object> value = args.at<Object>(2); |
| 3941 CONVERT_SMI_CHECKED(unchecked_attributes, args[3]); | 3941 CONVERT_SMI_CHECKED(unchecked_attributes, args[3]); |
| 3942 RUNTIME_ASSERT( | 3942 RUNTIME_ASSERT( |
| 3943 (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); | 3943 (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); |
| 3944 // Compute attributes. | 3944 // Compute attributes. |
| 3945 PropertyAttributes attributes = | 3945 PropertyAttributes attributes = |
| 3946 static_cast<PropertyAttributes>(unchecked_attributes); | 3946 static_cast<PropertyAttributes>(unchecked_attributes); |
| 3947 | 3947 |
| 3948 StrictModeFlag strict = kNonStrictMode; | 3948 StrictModeFlag strict_mode = kNonStrictMode; |
| 3949 if (args.length() == 5) { | 3949 if (args.length() == 5) { |
| 3950 CONVERT_SMI_CHECKED(strict_unchecked, args[4]); | 3950 CONVERT_SMI_CHECKED(strict_unchecked, args[4]); |
| 3951 RUNTIME_ASSERT(strict_unchecked == kStrictMode || | 3951 RUNTIME_ASSERT(strict_unchecked == kStrictMode || |
| 3952 strict_unchecked == kNonStrictMode); | 3952 strict_unchecked == kNonStrictMode); |
| 3953 strict = static_cast<StrictModeFlag>(strict_unchecked); | 3953 strict_mode = static_cast<StrictModeFlag>(strict_unchecked); |
| 3954 } | 3954 } |
| 3955 | 3955 |
| 3956 return Runtime::SetObjectProperty(object, key, value, attributes, strict); | 3956 return Runtime::SetObjectProperty(object, |
| 3957 key, |
| 3958 value, |
| 3959 attributes, |
| 3960 strict_mode); |
| 3957 } | 3961 } |
| 3958 | 3962 |
| 3959 | 3963 |
| 3960 // Set a local property, even if it is READ_ONLY. If the property does not | 3964 // Set a local property, even if it is READ_ONLY. If the property does not |
| 3961 // exist, it will be added with attributes NONE. | 3965 // exist, it will be added with attributes NONE. |
| 3962 static MaybeObject* Runtime_IgnoreAttributesAndSetProperty(Arguments args) { | 3966 static MaybeObject* Runtime_IgnoreAttributesAndSetProperty(Arguments args) { |
| 3963 NoHandleAllocation ha; | 3967 NoHandleAllocation ha; |
| 3964 RUNTIME_ASSERT(args.length() == 3 || args.length() == 4); | 3968 RUNTIME_ASSERT(args.length() == 3 || args.length() == 4); |
| 3965 CONVERT_CHECKED(JSObject, object, args[0]); | 3969 CONVERT_CHECKED(JSObject, object, args[0]); |
| 3966 CONVERT_CHECKED(String, name, args[1]); | 3970 CONVERT_CHECKED(String, name, args[1]); |
| (...skipping 3569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7536 static MaybeObject* Runtime_StoreContextSlot(Arguments args) { | 7540 static MaybeObject* Runtime_StoreContextSlot(Arguments args) { |
| 7537 HandleScope scope; | 7541 HandleScope scope; |
| 7538 ASSERT(args.length() == 4); | 7542 ASSERT(args.length() == 4); |
| 7539 | 7543 |
| 7540 Handle<Object> value(args[0]); | 7544 Handle<Object> value(args[0]); |
| 7541 CONVERT_ARG_CHECKED(Context, context, 1); | 7545 CONVERT_ARG_CHECKED(Context, context, 1); |
| 7542 CONVERT_ARG_CHECKED(String, name, 2); | 7546 CONVERT_ARG_CHECKED(String, name, 2); |
| 7543 CONVERT_SMI_CHECKED(strict_unchecked, args[3]); | 7547 CONVERT_SMI_CHECKED(strict_unchecked, args[3]); |
| 7544 RUNTIME_ASSERT(strict_unchecked == kStrictMode || | 7548 RUNTIME_ASSERT(strict_unchecked == kStrictMode || |
| 7545 strict_unchecked == kNonStrictMode); | 7549 strict_unchecked == kNonStrictMode); |
| 7546 StrictModeFlag strict = static_cast<StrictModeFlag>(strict_unchecked); | 7550 StrictModeFlag strict_mode = static_cast<StrictModeFlag>(strict_unchecked); |
| 7547 | |
| 7548 | 7551 |
| 7549 int index; | 7552 int index; |
| 7550 PropertyAttributes attributes; | 7553 PropertyAttributes attributes; |
| 7551 ContextLookupFlags flags = FOLLOW_CHAINS; | 7554 ContextLookupFlags flags = FOLLOW_CHAINS; |
| 7552 Handle<Object> holder = context->Lookup(name, flags, &index, &attributes); | 7555 Handle<Object> holder = context->Lookup(name, flags, &index, &attributes); |
| 7553 | 7556 |
| 7554 if (index >= 0) { | 7557 if (index >= 0) { |
| 7555 if (holder->IsContext()) { | 7558 if (holder->IsContext()) { |
| 7556 // Ignore if read_only variable. | 7559 // Ignore if read_only variable. |
| 7557 if ((attributes & READ_ONLY) == 0) { | 7560 if ((attributes & READ_ONLY) == 0) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 7581 // The property was not found. It needs to be stored in the global context. | 7584 // The property was not found. It needs to be stored in the global context. |
| 7582 ASSERT(attributes == ABSENT); | 7585 ASSERT(attributes == ABSENT); |
| 7583 attributes = NONE; | 7586 attributes = NONE; |
| 7584 context_ext = Handle<JSObject>(Top::context()->global()); | 7587 context_ext = Handle<JSObject>(Top::context()->global()); |
| 7585 } | 7588 } |
| 7586 | 7589 |
| 7587 // Set the property, but ignore if read_only variable on the context | 7590 // Set the property, but ignore if read_only variable on the context |
| 7588 // extension object itself. | 7591 // extension object itself. |
| 7589 if ((attributes & READ_ONLY) == 0 || | 7592 if ((attributes & READ_ONLY) == 0 || |
| 7590 (context_ext->GetLocalPropertyAttribute(*name) == ABSENT)) { | 7593 (context_ext->GetLocalPropertyAttribute(*name) == ABSENT)) { |
| 7591 RETURN_IF_EMPTY_HANDLE(SetProperty(context_ext, name, value, NONE, strict)); | 7594 RETURN_IF_EMPTY_HANDLE( |
| 7592 } else if (strict == kStrictMode && (attributes & READ_ONLY) != 0) { | 7595 SetProperty(context_ext, name, value, NONE, strict_mode)); |
| 7596 } else if (strict_mode == kStrictMode && (attributes & READ_ONLY) != 0) { |
| 7593 // Setting read only property in strict mode. | 7597 // Setting read only property in strict mode. |
| 7594 Handle<Object> error = | 7598 Handle<Object> error = |
| 7595 Factory::NewTypeError("strict_cannot_assign", HandleVector(&name, 1)); | 7599 Factory::NewTypeError("strict_cannot_assign", HandleVector(&name, 1)); |
| 7596 return Top::Throw(*error); | 7600 return Top::Throw(*error); |
| 7597 } | 7601 } |
| 7598 return *value; | 7602 return *value; |
| 7599 } | 7603 } |
| 7600 | 7604 |
| 7601 | 7605 |
| 7602 static MaybeObject* Runtime_Throw(Arguments args) { | 7606 static MaybeObject* Runtime_Throw(Arguments args) { |
| 7603 HandleScope scope; | 7607 HandleScope scope; |
| 7604 ASSERT(args.length() == 1); | 7608 ASSERT(args.length() == 1); |
| 7605 | 7609 |
| (...skipping 3977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11583 } else { | 11587 } else { |
| 11584 // Handle last resort GC and make sure to allow future allocations | 11588 // Handle last resort GC and make sure to allow future allocations |
| 11585 // to grow the heap without causing GCs (if possible). | 11589 // to grow the heap without causing GCs (if possible). |
| 11586 Counters::gc_last_resort_from_js.Increment(); | 11590 Counters::gc_last_resort_from_js.Increment(); |
| 11587 Heap::CollectAllGarbage(false); | 11591 Heap::CollectAllGarbage(false); |
| 11588 } | 11592 } |
| 11589 } | 11593 } |
| 11590 | 11594 |
| 11591 | 11595 |
| 11592 } } // namespace v8::internal | 11596 } } // namespace v8::internal |
| OLD | NEW |