OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 | 525 |
526 RUNTIME_FUNCTION(Runtime_DeleteProperty_Strict) { | 526 RUNTIME_FUNCTION(Runtime_DeleteProperty_Strict) { |
527 HandleScope scope(isolate); | 527 HandleScope scope(isolate); |
528 DCHECK_EQ(2, args.length()); | 528 DCHECK_EQ(2, args.length()); |
529 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 529 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
530 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 530 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
531 return DeleteProperty(isolate, object, key, STRICT); | 531 return DeleteProperty(isolate, object, key, STRICT); |
532 } | 532 } |
533 | 533 |
534 | 534 |
535 static Object* HasOwnPropertyImplementation(Isolate* isolate, | |
536 Handle<JSObject> object, | |
537 Handle<Name> key) { | |
538 Maybe<bool> maybe = JSReceiver::HasOwnProperty(object, key); | |
539 if (!maybe.IsJust()) return isolate->heap()->exception(); | |
540 if (maybe.FromJust()) return isolate->heap()->true_value(); | |
541 // Handle hidden prototypes. If there's a hidden prototype above this thing | |
542 // then we have to check it for properties, because they are supposed to | |
543 // look like they are on this object. | |
544 if (object->map()->has_hidden_prototype()) { | |
545 PrototypeIterator iter(isolate, object); | |
546 DCHECK(!iter.IsAtEnd()); | |
547 | |
548 // TODO(verwaest): The recursion is not necessary for keys that are array | |
549 // indices. Removing this. | |
550 // Casting to JSObject is fine because JSProxies are never used as | |
551 // hidden prototypes. | |
552 return HasOwnPropertyImplementation( | |
553 isolate, PrototypeIterator::GetCurrent<JSObject>(iter), key); | |
554 } | |
555 RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate); | |
556 return isolate->heap()->false_value(); | |
557 } | |
558 | |
559 | |
560 RUNTIME_FUNCTION(Runtime_HasOwnProperty) { | |
561 HandleScope scope(isolate); | |
562 DCHECK(args.length() == 2); | |
563 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0) | |
564 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); | |
565 | |
566 uint32_t index; | |
567 const bool key_is_array_index = key->AsArrayIndex(&index); | |
568 | |
569 // Only JS objects can have properties. | |
570 if (object->IsJSObject()) { | |
571 Handle<JSObject> js_obj = Handle<JSObject>::cast(object); | |
572 // Fast case: either the key is a real named property or it is not | |
573 // an array index and there are no interceptors or hidden | |
574 // prototypes. | |
575 // TODO(jkummerow): Make JSReceiver::HasOwnProperty fast enough to | |
576 // handle all cases directly (without this custom fast path). | |
577 Maybe<bool> maybe = Nothing<bool>(); | |
578 if (key_is_array_index) { | |
579 LookupIterator it(js_obj->GetIsolate(), js_obj, index, | |
580 LookupIterator::HIDDEN); | |
581 maybe = JSReceiver::HasProperty(&it); | |
582 } else { | |
583 maybe = JSObject::HasRealNamedProperty(js_obj, key); | |
584 } | |
585 if (!maybe.IsJust()) return isolate->heap()->exception(); | |
586 DCHECK(!isolate->has_pending_exception()); | |
587 if (maybe.FromJust()) { | |
588 return isolate->heap()->true_value(); | |
589 } | |
590 Map* map = js_obj->map(); | |
591 if (!key_is_array_index && !map->has_named_interceptor() && | |
592 !map->has_hidden_prototype()) { | |
593 return isolate->heap()->false_value(); | |
594 } | |
595 // Slow case. | |
596 return HasOwnPropertyImplementation(isolate, Handle<JSObject>(js_obj), | |
597 Handle<Name>(key)); | |
598 } else if (object->IsString() && key_is_array_index) { | |
599 // Well, there is one exception: Handle [] on strings. | |
600 Handle<String> string = Handle<String>::cast(object); | |
601 if (index < static_cast<uint32_t>(string->length())) { | |
602 return isolate->heap()->true_value(); | |
603 } | |
604 } else if (object->IsJSProxy()) { | |
605 Maybe<bool> result = | |
606 JSReceiver::HasOwnProperty(Handle<JSProxy>::cast(object), key); | |
607 if (!result.IsJust()) return isolate->heap()->exception(); | |
608 return isolate->heap()->ToBoolean(result.FromJust()); | |
609 } | |
610 return isolate->heap()->false_value(); | |
611 } | |
612 | |
613 | |
614 // ES6 section 12.9.3, operator in. | 535 // ES6 section 12.9.3, operator in. |
615 RUNTIME_FUNCTION(Runtime_HasProperty) { | 536 RUNTIME_FUNCTION(Runtime_HasProperty) { |
616 HandleScope scope(isolate); | 537 HandleScope scope(isolate); |
617 DCHECK_EQ(2, args.length()); | 538 DCHECK_EQ(2, args.length()); |
618 CONVERT_ARG_HANDLE_CHECKED(Object, key, 0); | 539 CONVERT_ARG_HANDLE_CHECKED(Object, key, 0); |
619 CONVERT_ARG_HANDLE_CHECKED(Object, object, 1); | 540 CONVERT_ARG_HANDLE_CHECKED(Object, object, 1); |
620 | 541 |
621 // Check that {object} is actually a receiver. | 542 // Check that {object} is actually a receiver. |
622 if (!object->IsJSReceiver()) { | 543 if (!object->IsJSReceiver()) { |
623 THROW_NEW_ERROR_RETURN_FAILURE( | 544 THROW_NEW_ERROR_RETURN_FAILURE( |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 DCHECK(args.length() == 2); | 1131 DCHECK(args.length() == 2); |
1211 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); | 1132 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); |
1212 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); | 1133 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); |
1213 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1134 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1214 isolate, o, JSReceiver::DefineProperties(isolate, o, properties)); | 1135 isolate, o, JSReceiver::DefineProperties(isolate, o, properties)); |
1215 return *o; | 1136 return *o; |
1216 } | 1137 } |
1217 | 1138 |
1218 } // namespace internal | 1139 } // namespace internal |
1219 } // namespace v8 | 1140 } // namespace v8 |
OLD | NEW |