OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 3880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3891 } | 3891 } |
3892 | 3892 |
3893 if (object->IsString() || object->IsNumber() || object->IsBoolean()) { | 3893 if (object->IsString() || object->IsNumber() || object->IsBoolean()) { |
3894 return object->GetPrototype(isolate)->GetElement(index); | 3894 return object->GetPrototype(isolate)->GetElement(index); |
3895 } | 3895 } |
3896 | 3896 |
3897 return object->GetElement(index); | 3897 return object->GetElement(index); |
3898 } | 3898 } |
3899 | 3899 |
3900 | 3900 |
| 3901 MaybeObject* Runtime::HasObjectProperty(Isolate* isolate, |
| 3902 Handle<JSReceiver> object, |
| 3903 Handle<Object> key) { |
| 3904 HandleScope scope(isolate); |
| 3905 |
| 3906 // Check if the given key is an array index. |
| 3907 uint32_t index; |
| 3908 if (key->ToArrayIndex(&index)) { |
| 3909 return isolate->heap()->ToBoolean(object->HasElement(index)); |
| 3910 } |
| 3911 |
| 3912 // Convert the key to a name - possibly by calling back into JavaScript. |
| 3913 Handle<Name> name; |
| 3914 if (key->IsName()) { |
| 3915 name = Handle<Name>::cast(key); |
| 3916 } else { |
| 3917 bool has_pending_exception = false; |
| 3918 Handle<Object> converted = |
| 3919 Execution::ToString(key, &has_pending_exception); |
| 3920 if (has_pending_exception) return Failure::Exception(); |
| 3921 name = Handle<Name>::cast(converted); |
| 3922 } |
| 3923 |
| 3924 return isolate->heap()->ToBoolean(object->HasProperty(*name)); |
| 3925 } |
| 3926 |
| 3927 |
3901 MaybeObject* Runtime::GetObjectProperty(Isolate* isolate, | 3928 MaybeObject* Runtime::GetObjectProperty(Isolate* isolate, |
3902 Handle<Object> object, | 3929 Handle<Object> object, |
3903 Handle<Object> key) { | 3930 Handle<Object> key) { |
3904 HandleScope scope(isolate); | 3931 HandleScope scope(isolate); |
3905 | 3932 |
3906 if (object->IsUndefined() || object->IsNull()) { | 3933 if (object->IsUndefined() || object->IsNull()) { |
3907 Handle<Object> args[2] = { key, object }; | 3934 Handle<Object> args[2] = { key, object }; |
3908 Handle<Object> error = | 3935 Handle<Object> error = |
3909 isolate->factory()->NewTypeError("non_object_property_load", | 3936 isolate->factory()->NewTypeError("non_object_property_load", |
3910 HandleVector(args, 2)); | 3937 HandleVector(args, 2)); |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4316 | 4343 |
4317 if (name->AsArrayIndex(&index)) { | 4344 if (name->AsArrayIndex(&index)) { |
4318 return js_object->SetElement( | 4345 return js_object->SetElement( |
4319 index, *value, attr, kNonStrictMode, false, DEFINE_PROPERTY); | 4346 index, *value, attr, kNonStrictMode, false, DEFINE_PROPERTY); |
4320 } else { | 4347 } else { |
4321 return js_object->SetLocalPropertyIgnoreAttributes(*name, *value, attr); | 4348 return js_object->SetLocalPropertyIgnoreAttributes(*name, *value, attr); |
4322 } | 4349 } |
4323 } | 4350 } |
4324 | 4351 |
4325 | 4352 |
4326 MaybeObject* Runtime::ForceDeleteObjectProperty(Isolate* isolate, | 4353 MaybeObject* Runtime::DeleteObjectProperty(Isolate* isolate, |
4327 Handle<JSReceiver> receiver, | 4354 Handle<JSReceiver> receiver, |
4328 Handle<Object> key) { | 4355 Handle<Object> key, |
| 4356 JSReceiver::DeleteMode mode) { |
4329 HandleScope scope(isolate); | 4357 HandleScope scope(isolate); |
4330 | 4358 |
4331 // Check if the given key is an array index. | 4359 // Check if the given key is an array index. |
4332 uint32_t index; | 4360 uint32_t index; |
4333 if (key->ToArrayIndex(&index)) { | 4361 if (key->ToArrayIndex(&index)) { |
4334 // In Firefox/SpiderMonkey, Safari and Opera you can access the | 4362 // In Firefox/SpiderMonkey, Safari and Opera you can access the |
4335 // characters of a string using [] notation. In the case of a | 4363 // characters of a string using [] notation. In the case of a |
4336 // String object we just need to redirect the deletion to the | 4364 // String object we just need to redirect the deletion to the |
4337 // underlying string if the index is in range. Since the | 4365 // underlying string if the index is in range. Since the |
4338 // underlying string does nothing with the deletion, we can ignore | 4366 // underlying string does nothing with the deletion, we can ignore |
4339 // such deletions. | 4367 // such deletions. |
4340 if (receiver->IsStringObjectWithCharacterAt(index)) { | 4368 if (receiver->IsStringObjectWithCharacterAt(index)) { |
4341 return isolate->heap()->true_value(); | 4369 return isolate->heap()->true_value(); |
4342 } | 4370 } |
4343 | 4371 |
4344 return receiver->DeleteElement(index, JSReceiver::FORCE_DELETION); | 4372 return receiver->DeleteElement(index, mode); |
4345 } | 4373 } |
4346 | 4374 |
4347 Handle<Name> name; | 4375 Handle<Name> name; |
4348 if (key->IsName()) { | 4376 if (key->IsName()) { |
4349 name = Handle<Name>::cast(key); | 4377 name = Handle<Name>::cast(key); |
4350 } else { | 4378 } else { |
4351 // Call-back into JavaScript to convert the key to a string. | 4379 // Call-back into JavaScript to convert the key to a string. |
4352 bool has_pending_exception = false; | 4380 bool has_pending_exception = false; |
4353 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); | 4381 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); |
4354 if (has_pending_exception) return Failure::Exception(); | 4382 if (has_pending_exception) return Failure::Exception(); |
4355 name = Handle<String>::cast(converted); | 4383 name = Handle<String>::cast(converted); |
4356 } | 4384 } |
4357 | 4385 |
4358 if (name->IsString()) Handle<String>::cast(name)->TryFlatten(); | 4386 if (name->IsString()) Handle<String>::cast(name)->TryFlatten(); |
4359 return receiver->DeleteProperty(*name, JSReceiver::FORCE_DELETION); | 4387 return receiver->DeleteProperty(*name, mode); |
4360 } | 4388 } |
4361 | 4389 |
4362 | 4390 |
4363 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetProperty) { | 4391 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetProperty) { |
4364 NoHandleAllocation ha(isolate); | 4392 NoHandleAllocation ha(isolate); |
4365 RUNTIME_ASSERT(args.length() == 4 || args.length() == 5); | 4393 RUNTIME_ASSERT(args.length() == 4 || args.length() == 5); |
4366 | 4394 |
4367 Handle<Object> object = args.at<Object>(0); | 4395 Handle<Object> object = args.at<Object>(0); |
4368 Handle<Object> key = args.at<Object>(1); | 4396 Handle<Object> key = args.at<Object>(1); |
4369 Handle<Object> value = args.at<Object>(2); | 4397 Handle<Object> value = args.at<Object>(2); |
(...skipping 8629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12999 // Handle last resort GC and make sure to allow future allocations | 13027 // Handle last resort GC and make sure to allow future allocations |
13000 // to grow the heap without causing GCs (if possible). | 13028 // to grow the heap without causing GCs (if possible). |
13001 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13029 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13002 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13030 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13003 "Runtime::PerformGC"); | 13031 "Runtime::PerformGC"); |
13004 } | 13032 } |
13005 } | 13033 } |
13006 | 13034 |
13007 | 13035 |
13008 } } // namespace v8::internal | 13036 } } // namespace v8::internal |
OLD | NEW |