OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 3854 matching lines...) Loading... |
3865 | 3865 |
3866 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked); | 3866 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked); |
3867 // If an existing property is either FIELD, NORMAL or CONSTANT_FUNCTION | 3867 // If an existing property is either FIELD, NORMAL or CONSTANT_FUNCTION |
3868 // delete it to avoid running into trouble in DefineAccessor, which | 3868 // delete it to avoid running into trouble in DefineAccessor, which |
3869 // handles this incorrectly if the property is readonly (does nothing) | 3869 // handles this incorrectly if the property is readonly (does nothing) |
3870 if (result.IsProperty() && | 3870 if (result.IsProperty() && |
3871 (result.type() == FIELD || result.type() == NORMAL | 3871 (result.type() == FIELD || result.type() == NORMAL |
3872 || result.type() == CONSTANT_FUNCTION)) { | 3872 || result.type() == CONSTANT_FUNCTION)) { |
3873 Object* ok; | 3873 Object* ok; |
3874 { MaybeObject* maybe_ok = | 3874 { MaybeObject* maybe_ok = |
3875 obj->DeleteProperty(name, JSObject::NORMAL_DELETION); | 3875 obj->DeleteProperty(name, JSReceiver::NORMAL_DELETION); |
3876 if (!maybe_ok->ToObject(&ok)) return maybe_ok; | 3876 if (!maybe_ok->ToObject(&ok)) return maybe_ok; |
3877 } | 3877 } |
3878 } | 3878 } |
3879 return obj->DefineAccessor(name, flag_setter->value() == 0, fun, attr); | 3879 return obj->DefineAccessor(name, flag_setter->value() == 0, fun, attr); |
3880 } | 3880 } |
3881 | 3881 |
3882 // Implements part of 8.12.9 DefineOwnProperty. | 3882 // Implements part of 8.12.9 DefineOwnProperty. |
3883 // There are 3 cases that lead here: | 3883 // There are 3 cases that lead here: |
3884 // Step 4a - define a new data property. | 3884 // Step 4a - define a new data property. |
3885 // Steps 9b & 12 - replace an existing accessor property with a data property. | 3885 // Steps 9b & 12 - replace an existing accessor property with a data property. |
(...skipping 233 matching lines...) Loading... |
4119 | 4119 |
4120 if (name->AsArrayIndex(&index)) { | 4120 if (name->AsArrayIndex(&index)) { |
4121 return js_object->SetElement(index, *value, kNonStrictMode, true); | 4121 return js_object->SetElement(index, *value, kNonStrictMode, true); |
4122 } else { | 4122 } else { |
4123 return js_object->SetLocalPropertyIgnoreAttributes(*name, *value, attr); | 4123 return js_object->SetLocalPropertyIgnoreAttributes(*name, *value, attr); |
4124 } | 4124 } |
4125 } | 4125 } |
4126 | 4126 |
4127 | 4127 |
4128 MaybeObject* Runtime::ForceDeleteObjectProperty(Isolate* isolate, | 4128 MaybeObject* Runtime::ForceDeleteObjectProperty(Isolate* isolate, |
4129 Handle<JSObject> js_object, | 4129 Handle<JSReceiver> receiver, |
4130 Handle<Object> key) { | 4130 Handle<Object> key) { |
4131 HandleScope scope(isolate); | 4131 HandleScope scope(isolate); |
4132 | 4132 |
4133 // Check if the given key is an array index. | 4133 // Check if the given key is an array index. |
4134 uint32_t index; | 4134 uint32_t index; |
4135 if (key->ToArrayIndex(&index)) { | 4135 if (receiver->IsJSObject() && key->ToArrayIndex(&index)) { |
4136 // In Firefox/SpiderMonkey, Safari and Opera you can access the | 4136 // In Firefox/SpiderMonkey, Safari and Opera you can access the |
4137 // characters of a string using [] notation. In the case of a | 4137 // characters of a string using [] notation. In the case of a |
4138 // String object we just need to redirect the deletion to the | 4138 // String object we just need to redirect the deletion to the |
4139 // underlying string if the index is in range. Since the | 4139 // underlying string if the index is in range. Since the |
4140 // underlying string does nothing with the deletion, we can ignore | 4140 // underlying string does nothing with the deletion, we can ignore |
4141 // such deletions. | 4141 // such deletions. |
4142 if (js_object->IsStringObjectWithCharacterAt(index)) { | 4142 if (receiver->IsStringObjectWithCharacterAt(index)) { |
4143 return isolate->heap()->true_value(); | 4143 return isolate->heap()->true_value(); |
4144 } | 4144 } |
4145 | 4145 |
4146 return js_object->DeleteElement(index, JSObject::FORCE_DELETION); | 4146 return JSObject::cast(*receiver)->DeleteElement( |
| 4147 index, JSReceiver::FORCE_DELETION); |
4147 } | 4148 } |
4148 | 4149 |
4149 Handle<String> key_string; | 4150 Handle<String> key_string; |
4150 if (key->IsString()) { | 4151 if (key->IsString()) { |
4151 key_string = Handle<String>::cast(key); | 4152 key_string = Handle<String>::cast(key); |
4152 } else { | 4153 } else { |
4153 // Call-back into JavaScript to convert the key to a string. | 4154 // Call-back into JavaScript to convert the key to a string. |
4154 bool has_pending_exception = false; | 4155 bool has_pending_exception = false; |
4155 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); | 4156 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); |
4156 if (has_pending_exception) return Failure::Exception(); | 4157 if (has_pending_exception) return Failure::Exception(); |
4157 key_string = Handle<String>::cast(converted); | 4158 key_string = Handle<String>::cast(converted); |
4158 } | 4159 } |
4159 | 4160 |
4160 key_string->TryFlatten(); | 4161 key_string->TryFlatten(); |
4161 return js_object->DeleteProperty(*key_string, JSObject::FORCE_DELETION); | 4162 return receiver->DeleteProperty(*key_string, JSReceiver::FORCE_DELETION); |
4162 } | 4163 } |
4163 | 4164 |
4164 | 4165 |
4165 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetProperty) { | 4166 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetProperty) { |
4166 NoHandleAllocation ha; | 4167 NoHandleAllocation ha; |
4167 RUNTIME_ASSERT(args.length() == 4 || args.length() == 5); | 4168 RUNTIME_ASSERT(args.length() == 4 || args.length() == 5); |
4168 | 4169 |
4169 Handle<Object> object = args.at<Object>(0); | 4170 Handle<Object> object = args.at<Object>(0); |
4170 Handle<Object> key = args.at<Object>(1); | 4171 Handle<Object> key = args.at<Object>(1); |
4171 Handle<Object> value = args.at<Object>(2); | 4172 Handle<Object> value = args.at<Object>(2); |
(...skipping 58 matching lines...) Loading... |
4230 | 4231 |
4231 return object-> | 4232 return object-> |
4232 SetLocalPropertyIgnoreAttributes(name, args[2], attributes); | 4233 SetLocalPropertyIgnoreAttributes(name, args[2], attributes); |
4233 } | 4234 } |
4234 | 4235 |
4235 | 4236 |
4236 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteProperty) { | 4237 RUNTIME_FUNCTION(MaybeObject*, Runtime_DeleteProperty) { |
4237 NoHandleAllocation ha; | 4238 NoHandleAllocation ha; |
4238 ASSERT(args.length() == 3); | 4239 ASSERT(args.length() == 3); |
4239 | 4240 |
4240 CONVERT_CHECKED(JSObject, object, args[0]); | 4241 CONVERT_CHECKED(JSReceiver, object, args[0]); |
4241 CONVERT_CHECKED(String, key, args[1]); | 4242 CONVERT_CHECKED(String, key, args[1]); |
4242 CONVERT_SMI_ARG_CHECKED(strict, 2); | 4243 CONVERT_SMI_ARG_CHECKED(strict, 2); |
4243 return object->DeleteProperty(key, (strict == kStrictMode) | 4244 return object->DeleteProperty(key, (strict == kStrictMode) |
4244 ? JSObject::STRICT_DELETION | 4245 ? JSReceiver::STRICT_DELETION |
4245 : JSObject::NORMAL_DELETION); | 4246 : JSReceiver::NORMAL_DELETION); |
4246 } | 4247 } |
4247 | 4248 |
4248 | 4249 |
4249 static Object* HasLocalPropertyImplementation(Isolate* isolate, | 4250 static Object* HasLocalPropertyImplementation(Isolate* isolate, |
4250 Handle<JSObject> object, | 4251 Handle<JSObject> object, |
4251 Handle<String> key) { | 4252 Handle<String> key) { |
4252 if (object->HasLocalProperty(*key)) return isolate->heap()->true_value(); | 4253 if (object->HasLocalProperty(*key)) return isolate->heap()->true_value(); |
4253 // Handle hidden prototypes. If there's a hidden prototype above this thing | 4254 // Handle hidden prototypes. If there's a hidden prototype above this thing |
4254 // then we have to check it for properties, because they are supposed to | 4255 // then we have to check it for properties, because they are supposed to |
4255 // look like they are on this object. | 4256 // look like they are on this object. |
(...skipping 3935 matching lines...) Loading... |
8191 | 8192 |
8192 // The slot was found in a JSObject, either a context extension object, | 8193 // The slot was found in a JSObject, either a context extension object, |
8193 // the global object, or an arguments object. Try to delete it | 8194 // the global object, or an arguments object. Try to delete it |
8194 // (respecting DONT_DELETE). For consistency with V8's usual behavior, | 8195 // (respecting DONT_DELETE). For consistency with V8's usual behavior, |
8195 // which allows deleting all parameters in functions that mention | 8196 // which allows deleting all parameters in functions that mention |
8196 // 'arguments', we do this even for the case of slots found on an | 8197 // 'arguments', we do this even for the case of slots found on an |
8197 // arguments object. The slot was found on an arguments object if the | 8198 // arguments object. The slot was found on an arguments object if the |
8198 // index is non-negative. | 8199 // index is non-negative. |
8199 Handle<JSObject> object = Handle<JSObject>::cast(holder); | 8200 Handle<JSObject> object = Handle<JSObject>::cast(holder); |
8200 if (index >= 0) { | 8201 if (index >= 0) { |
8201 return object->DeleteElement(index, JSObject::NORMAL_DELETION); | 8202 return object->DeleteElement(index, JSReceiver::NORMAL_DELETION); |
8202 } else { | 8203 } else { |
8203 return object->DeleteProperty(*name, JSObject::NORMAL_DELETION); | 8204 return object->DeleteProperty(*name, JSReceiver::NORMAL_DELETION); |
8204 } | 8205 } |
8205 } | 8206 } |
8206 | 8207 |
8207 | 8208 |
8208 // A mechanism to return a pair of Object pointers in registers (if possible). | 8209 // A mechanism to return a pair of Object pointers in registers (if possible). |
8209 // How this is achieved is calling convention-dependent. | 8210 // How this is achieved is calling convention-dependent. |
8210 // All currently supported x86 compiles uses calling conventions that are cdecl | 8211 // All currently supported x86 compiles uses calling conventions that are cdecl |
8211 // variants where a 64-bit value is returned in two 32-bit registers | 8212 // variants where a 64-bit value is returned in two 32-bit registers |
8212 // (edx:eax on ia32, r1:r0 on ARM). | 8213 // (edx:eax on ia32, r1:r0 on ARM). |
8213 // In AMD-64 calling convention a struct of two pointers is returned in rdx:rax. | 8214 // In AMD-64 calling convention a struct of two pointers is returned in rdx:rax. |
(...skipping 4396 matching lines...) Loading... |
12610 } else { | 12611 } else { |
12611 // Handle last resort GC and make sure to allow future allocations | 12612 // Handle last resort GC and make sure to allow future allocations |
12612 // to grow the heap without causing GCs (if possible). | 12613 // to grow the heap without causing GCs (if possible). |
12613 isolate->counters()->gc_last_resort_from_js()->Increment(); | 12614 isolate->counters()->gc_last_resort_from_js()->Increment(); |
12614 isolate->heap()->CollectAllGarbage(false); | 12615 isolate->heap()->CollectAllGarbage(false); |
12615 } | 12616 } |
12616 } | 12617 } |
12617 | 12618 |
12618 | 12619 |
12619 } } // namespace v8::internal | 12620 } } // namespace v8::internal |
OLD | NEW |