| 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 4175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4186 HandleScope scope(isolate); | 4186 HandleScope scope(isolate); |
| 4187 | 4187 |
| 4188 if (object->IsUndefined() || object->IsNull()) { | 4188 if (object->IsUndefined() || object->IsNull()) { |
| 4189 Handle<Object> args[2] = { key, object }; | 4189 Handle<Object> args[2] = { key, object }; |
| 4190 Handle<Object> error = | 4190 Handle<Object> error = |
| 4191 isolate->factory()->NewTypeError("non_object_property_store", | 4191 isolate->factory()->NewTypeError("non_object_property_store", |
| 4192 HandleVector(args, 2)); | 4192 HandleVector(args, 2)); |
| 4193 return isolate->Throw(*error); | 4193 return isolate->Throw(*error); |
| 4194 } | 4194 } |
| 4195 | 4195 |
| 4196 if (object->IsJSProxy()) { |
| 4197 bool has_pending_exception = false; |
| 4198 Handle<Object> name = Execution::ToString(key, &has_pending_exception); |
| 4199 if (has_pending_exception) return Failure::Exception(); |
| 4200 return JSProxy::cast(*object)->SetProperty( |
| 4201 String::cast(*name), *value, attr, strict_mode); |
| 4202 } |
| 4203 |
| 4196 // If the object isn't a JavaScript object, we ignore the store. | 4204 // If the object isn't a JavaScript object, we ignore the store. |
| 4197 if (!object->IsJSObject()) return *value; | 4205 if (!object->IsJSObject()) return *value; |
| 4198 | 4206 |
| 4199 Handle<JSObject> js_object = Handle<JSObject>::cast(object); | 4207 Handle<JSObject> js_object = Handle<JSObject>::cast(object); |
| 4200 | 4208 |
| 4201 // Check if the given key is an array index. | 4209 // Check if the given key is an array index. |
| 4202 uint32_t index; | 4210 uint32_t index; |
| 4203 if (key->ToArrayIndex(&index)) { | 4211 if (key->ToArrayIndex(&index)) { |
| 4204 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters | 4212 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters |
| 4205 // of a string using [] notation. We need to support this too in | 4213 // of a string using [] notation. We need to support this too in |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4305 } | 4313 } |
| 4306 | 4314 |
| 4307 | 4315 |
| 4308 MaybeObject* Runtime::ForceDeleteObjectProperty(Isolate* isolate, | 4316 MaybeObject* Runtime::ForceDeleteObjectProperty(Isolate* isolate, |
| 4309 Handle<JSReceiver> receiver, | 4317 Handle<JSReceiver> receiver, |
| 4310 Handle<Object> key) { | 4318 Handle<Object> key) { |
| 4311 HandleScope scope(isolate); | 4319 HandleScope scope(isolate); |
| 4312 | 4320 |
| 4313 // Check if the given key is an array index. | 4321 // Check if the given key is an array index. |
| 4314 uint32_t index; | 4322 uint32_t index; |
| 4315 if (receiver->IsJSObject() && key->ToArrayIndex(&index)) { | 4323 if (key->ToArrayIndex(&index)) { |
| 4316 // In Firefox/SpiderMonkey, Safari and Opera you can access the | 4324 // In Firefox/SpiderMonkey, Safari and Opera you can access the |
| 4317 // characters of a string using [] notation. In the case of a | 4325 // characters of a string using [] notation. In the case of a |
| 4318 // String object we just need to redirect the deletion to the | 4326 // String object we just need to redirect the deletion to the |
| 4319 // underlying string if the index is in range. Since the | 4327 // underlying string if the index is in range. Since the |
| 4320 // underlying string does nothing with the deletion, we can ignore | 4328 // underlying string does nothing with the deletion, we can ignore |
| 4321 // such deletions. | 4329 // such deletions. |
| 4322 if (receiver->IsStringObjectWithCharacterAt(index)) { | 4330 if (receiver->IsStringObjectWithCharacterAt(index)) { |
| 4323 return isolate->heap()->true_value(); | 4331 return isolate->heap()->true_value(); |
| 4324 } | 4332 } |
| 4325 | 4333 |
| 4326 return JSObject::cast(*receiver)->DeleteElement( | 4334 return receiver->DeleteElement(index, JSReceiver::FORCE_DELETION); |
| 4327 index, JSReceiver::FORCE_DELETION); | |
| 4328 } | 4335 } |
| 4329 | 4336 |
| 4330 Handle<String> key_string; | 4337 Handle<String> key_string; |
| 4331 if (key->IsString()) { | 4338 if (key->IsString()) { |
| 4332 key_string = Handle<String>::cast(key); | 4339 key_string = Handle<String>::cast(key); |
| 4333 } else { | 4340 } else { |
| 4334 // Call-back into JavaScript to convert the key to a string. | 4341 // Call-back into JavaScript to convert the key to a string. |
| 4335 bool has_pending_exception = false; | 4342 bool has_pending_exception = false; |
| 4336 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); | 4343 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); |
| 4337 if (has_pending_exception) return Failure::Exception(); | 4344 if (has_pending_exception) return Failure::Exception(); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4479 return isolate->heap()->true_value(); | 4486 return isolate->heap()->true_value(); |
| 4480 } | 4487 } |
| 4481 } | 4488 } |
| 4482 return isolate->heap()->false_value(); | 4489 return isolate->heap()->false_value(); |
| 4483 } | 4490 } |
| 4484 | 4491 |
| 4485 | 4492 |
| 4486 RUNTIME_FUNCTION(MaybeObject*, Runtime_HasProperty) { | 4493 RUNTIME_FUNCTION(MaybeObject*, Runtime_HasProperty) { |
| 4487 NoHandleAllocation na; | 4494 NoHandleAllocation na; |
| 4488 ASSERT(args.length() == 2); | 4495 ASSERT(args.length() == 2); |
| 4496 CONVERT_CHECKED(JSReceiver, receiver, args[0]); |
| 4497 CONVERT_CHECKED(String, key, args[1]); |
| 4489 | 4498 |
| 4490 // Only JS receivers can have properties. | 4499 bool result = receiver->HasProperty(key); |
| 4491 if (args[0]->IsJSReceiver()) { | 4500 if (isolate->has_pending_exception()) return Failure::Exception(); |
| 4492 JSReceiver* receiver = JSReceiver::cast(args[0]); | 4501 return isolate->heap()->ToBoolean(result); |
| 4493 CONVERT_CHECKED(String, key, args[1]); | |
| 4494 bool result = receiver->HasProperty(key); | |
| 4495 if (isolate->has_pending_exception()) return Failure::Exception(); | |
| 4496 return isolate->heap()->ToBoolean(result); | |
| 4497 } | |
| 4498 return isolate->heap()->false_value(); | |
| 4499 } | 4502 } |
| 4500 | 4503 |
| 4501 | 4504 |
| 4502 RUNTIME_FUNCTION(MaybeObject*, Runtime_HasElement) { | 4505 RUNTIME_FUNCTION(MaybeObject*, Runtime_HasElement) { |
| 4503 NoHandleAllocation na; | 4506 NoHandleAllocation na; |
| 4504 ASSERT(args.length() == 2); | 4507 ASSERT(args.length() == 2); |
| 4508 CONVERT_CHECKED(JSReceiver, receiver, args[0]); |
| 4509 CONVERT_CHECKED(Smi, index, args[1]); |
| 4505 | 4510 |
| 4506 // Only JS objects can have elements. | 4511 bool result = receiver->HasElement(index->value()); |
| 4507 if (args[0]->IsJSObject()) { | 4512 if (isolate->has_pending_exception()) return Failure::Exception(); |
| 4508 JSObject* object = JSObject::cast(args[0]); | 4513 return isolate->heap()->ToBoolean(result); |
| 4509 CONVERT_CHECKED(Smi, index_obj, args[1]); | |
| 4510 uint32_t index = index_obj->value(); | |
| 4511 if (object->HasElement(index)) return isolate->heap()->true_value(); | |
| 4512 } | |
| 4513 return isolate->heap()->false_value(); | |
| 4514 } | 4514 } |
| 4515 | 4515 |
| 4516 | 4516 |
| 4517 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsPropertyEnumerable) { | 4517 RUNTIME_FUNCTION(MaybeObject*, Runtime_IsPropertyEnumerable) { |
| 4518 NoHandleAllocation ha; | 4518 NoHandleAllocation ha; |
| 4519 ASSERT(args.length() == 2); | 4519 ASSERT(args.length() == 2); |
| 4520 | 4520 |
| 4521 CONVERT_CHECKED(JSObject, object, args[0]); | 4521 CONVERT_CHECKED(JSObject, object, args[0]); |
| 4522 CONVERT_CHECKED(String, key, args[1]); | 4522 CONVERT_CHECKED(String, key, args[1]); |
| 4523 | 4523 |
| (...skipping 8353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12877 } else { | 12877 } else { |
| 12878 // Handle last resort GC and make sure to allow future allocations | 12878 // Handle last resort GC and make sure to allow future allocations |
| 12879 // to grow the heap without causing GCs (if possible). | 12879 // to grow the heap without causing GCs (if possible). |
| 12880 isolate->counters()->gc_last_resort_from_js()->Increment(); | 12880 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 12881 isolate->heap()->CollectAllGarbage(false); | 12881 isolate->heap()->CollectAllGarbage(false); |
| 12882 } | 12882 } |
| 12883 } | 12883 } |
| 12884 | 12884 |
| 12885 | 12885 |
| 12886 } } // namespace v8::internal | 12886 } } // namespace v8::internal |
| OLD | NEW |