Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: src/runtime/runtime-object.cc

Issue 958053003: Removed funky Maybe constructor and made fields private. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | src/runtime/runtime-scopes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/v8.h" 5 #include "src/v8.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.h" 9 #include "src/debug.h"
10 #include "src/runtime/runtime.h" 10 #include "src/runtime/runtime.h"
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 PropertyAttributes attrs; 361 PropertyAttributes attrs;
362 uint32_t index = 0; 362 uint32_t index = 0;
363 Handle<Object> value; 363 Handle<Object> value;
364 MaybeHandle<AccessorPair> maybe_accessors; 364 MaybeHandle<AccessorPair> maybe_accessors;
365 // TODO(verwaest): Unify once indexed properties can be handled by the 365 // TODO(verwaest): Unify once indexed properties can be handled by the
366 // LookupIterator. 366 // LookupIterator.
367 if (name->AsArrayIndex(&index)) { 367 if (name->AsArrayIndex(&index)) {
368 // Get attributes. 368 // Get attributes.
369 Maybe<PropertyAttributes> maybe = 369 Maybe<PropertyAttributes> maybe =
370 JSReceiver::GetOwnElementAttribute(obj, index); 370 JSReceiver::GetOwnElementAttribute(obj, index);
371 if (!maybe.has_value) return MaybeHandle<Object>(); 371 if (!maybe.IsJust()) return MaybeHandle<Object>();
372 attrs = maybe.value; 372 attrs = maybe.FromJust();
373 if (attrs == ABSENT) return factory->undefined_value(); 373 if (attrs == ABSENT) return factory->undefined_value();
374 374
375 // Get AccessorPair if present. 375 // Get AccessorPair if present.
376 maybe_accessors = JSObject::GetOwnElementAccessorPair(obj, index); 376 maybe_accessors = JSObject::GetOwnElementAccessorPair(obj, index);
377 377
378 // Get value if not an AccessorPair. 378 // Get value if not an AccessorPair.
379 if (maybe_accessors.is_null()) { 379 if (maybe_accessors.is_null()) {
380 ASSIGN_RETURN_ON_EXCEPTION( 380 ASSIGN_RETURN_ON_EXCEPTION(
381 isolate, value, Runtime::GetElementOrCharAt(isolate, obj, index), 381 isolate, value, Runtime::GetElementOrCharAt(isolate, obj, index),
382 Object); 382 Object);
383 } 383 }
384 } else { 384 } else {
385 // Get attributes. 385 // Get attributes.
386 LookupIterator it(obj, name, LookupIterator::HIDDEN); 386 LookupIterator it(obj, name, LookupIterator::HIDDEN);
387 Maybe<PropertyAttributes> maybe = JSObject::GetPropertyAttributes(&it); 387 Maybe<PropertyAttributes> maybe = JSObject::GetPropertyAttributes(&it);
388 if (!maybe.has_value) return MaybeHandle<Object>(); 388 if (!maybe.IsJust()) return MaybeHandle<Object>();
389 attrs = maybe.value; 389 attrs = maybe.FromJust();
390 if (attrs == ABSENT) return factory->undefined_value(); 390 if (attrs == ABSENT) return factory->undefined_value();
391 391
392 // Get AccessorPair if present. 392 // Get AccessorPair if present.
393 if (it.state() == LookupIterator::ACCESSOR && 393 if (it.state() == LookupIterator::ACCESSOR &&
394 it.GetAccessors()->IsAccessorPair()) { 394 it.GetAccessors()->IsAccessorPair()) {
395 maybe_accessors = Handle<AccessorPair>::cast(it.GetAccessors()); 395 maybe_accessors = Handle<AccessorPair>::cast(it.GetAccessors());
396 } 396 }
397 397
398 // Get value if not an AccessorPair. 398 // Get value if not an AccessorPair.
399 if (maybe_accessors.is_null()) { 399 if (maybe_accessors.is_null()) {
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); 660 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
661 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); 661 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1);
662 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); 662 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
663 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); 663 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3);
664 664
665 #ifdef DEBUG 665 #ifdef DEBUG
666 uint32_t index = 0; 666 uint32_t index = 0;
667 DCHECK(!key->ToArrayIndex(&index)); 667 DCHECK(!key->ToArrayIndex(&index));
668 LookupIterator it(object, key, LookupIterator::OWN_SKIP_INTERCEPTOR); 668 LookupIterator it(object, key, LookupIterator::OWN_SKIP_INTERCEPTOR);
669 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); 669 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
670 if (!maybe.has_value) return isolate->heap()->exception(); 670 if (!maybe.IsJust()) return isolate->heap()->exception();
671 RUNTIME_ASSERT(!it.IsFound()); 671 RUNTIME_ASSERT(!it.IsFound());
672 #endif 672 #endif
673 673
674 Handle<Object> result; 674 Handle<Object> result;
675 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 675 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
676 isolate, result, 676 isolate, result,
677 JSObject::SetOwnPropertyIgnoreAttributes(object, key, value, attrs)); 677 JSObject::SetOwnPropertyIgnoreAttributes(object, key, value, attrs));
678 return *result; 678 return *result;
679 } 679 }
680 680
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 729 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
730 isolate, result, JSReceiver::DeleteProperty(object, key, language_mode)); 730 isolate, result, JSReceiver::DeleteProperty(object, key, language_mode));
731 return *result; 731 return *result;
732 } 732 }
733 733
734 734
735 static Object* HasOwnPropertyImplementation(Isolate* isolate, 735 static Object* HasOwnPropertyImplementation(Isolate* isolate,
736 Handle<JSObject> object, 736 Handle<JSObject> object,
737 Handle<Name> key) { 737 Handle<Name> key) {
738 Maybe<bool> maybe = JSReceiver::HasOwnProperty(object, key); 738 Maybe<bool> maybe = JSReceiver::HasOwnProperty(object, key);
739 if (!maybe.has_value) return isolate->heap()->exception(); 739 if (!maybe.IsJust()) return isolate->heap()->exception();
740 if (maybe.value) return isolate->heap()->true_value(); 740 if (maybe.FromJust()) return isolate->heap()->true_value();
741 // Handle hidden prototypes. If there's a hidden prototype above this thing 741 // Handle hidden prototypes. If there's a hidden prototype above this thing
742 // then we have to check it for properties, because they are supposed to 742 // then we have to check it for properties, because they are supposed to
743 // look like they are on this object. 743 // look like they are on this object.
744 PrototypeIterator iter(isolate, object); 744 PrototypeIterator iter(isolate, object);
745 if (!iter.IsAtEnd() && 745 if (!iter.IsAtEnd() &&
746 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)) 746 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter))
747 ->map() 747 ->map()
748 ->is_hidden_prototype()) { 748 ->is_hidden_prototype()) {
749 // TODO(verwaest): The recursion is not necessary for keys that are array 749 // TODO(verwaest): The recursion is not necessary for keys that are array
750 // indices. Removing this. 750 // indices. Removing this.
(...skipping 20 matching lines...) Expand all
771 Handle<JSObject> js_obj = Handle<JSObject>::cast(object); 771 Handle<JSObject> js_obj = Handle<JSObject>::cast(object);
772 // Fast case: either the key is a real named property or it is not 772 // Fast case: either the key is a real named property or it is not
773 // an array index and there are no interceptors or hidden 773 // an array index and there are no interceptors or hidden
774 // prototypes. 774 // prototypes.
775 Maybe<bool> maybe = Nothing<bool>(); 775 Maybe<bool> maybe = Nothing<bool>();
776 if (key_is_array_index) { 776 if (key_is_array_index) {
777 maybe = JSObject::HasOwnElement(js_obj, index); 777 maybe = JSObject::HasOwnElement(js_obj, index);
778 } else { 778 } else {
779 maybe = JSObject::HasRealNamedProperty(js_obj, key); 779 maybe = JSObject::HasRealNamedProperty(js_obj, key);
780 } 780 }
781 if (!maybe.has_value) return isolate->heap()->exception(); 781 if (!maybe.IsJust()) return isolate->heap()->exception();
782 DCHECK(!isolate->has_pending_exception()); 782 DCHECK(!isolate->has_pending_exception());
783 if (maybe.value) { 783 if (maybe.FromJust()) {
784 return isolate->heap()->true_value(); 784 return isolate->heap()->true_value();
785 } 785 }
786 Map* map = js_obj->map(); 786 Map* map = js_obj->map();
787 if (!key_is_array_index && !map->has_named_interceptor() && 787 if (!key_is_array_index && !map->has_named_interceptor() &&
788 !HeapObject::cast(map->prototype())->map()->is_hidden_prototype()) { 788 !HeapObject::cast(map->prototype())->map()->is_hidden_prototype()) {
789 return isolate->heap()->false_value(); 789 return isolate->heap()->false_value();
790 } 790 }
791 // Slow case. 791 // Slow case.
792 return HasOwnPropertyImplementation(isolate, Handle<JSObject>(js_obj), 792 return HasOwnPropertyImplementation(isolate, Handle<JSObject>(js_obj),
793 Handle<Name>(key)); 793 Handle<Name>(key));
794 } else if (object->IsString() && key_is_array_index) { 794 } else if (object->IsString() && key_is_array_index) {
795 // Well, there is one exception: Handle [] on strings. 795 // Well, there is one exception: Handle [] on strings.
796 Handle<String> string = Handle<String>::cast(object); 796 Handle<String> string = Handle<String>::cast(object);
797 if (index < static_cast<uint32_t>(string->length())) { 797 if (index < static_cast<uint32_t>(string->length())) {
798 return isolate->heap()->true_value(); 798 return isolate->heap()->true_value();
799 } 799 }
800 } 800 }
801 return isolate->heap()->false_value(); 801 return isolate->heap()->false_value();
802 } 802 }
803 803
804 804
805 RUNTIME_FUNCTION(Runtime_HasProperty) { 805 RUNTIME_FUNCTION(Runtime_HasProperty) {
806 HandleScope scope(isolate); 806 HandleScope scope(isolate);
807 DCHECK(args.length() == 2); 807 DCHECK(args.length() == 2);
808 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0); 808 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0);
809 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); 809 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1);
810 810
811 Maybe<bool> maybe = JSReceiver::HasProperty(receiver, key); 811 Maybe<bool> maybe = JSReceiver::HasProperty(receiver, key);
812 if (!maybe.has_value) return isolate->heap()->exception(); 812 if (!maybe.IsJust()) return isolate->heap()->exception();
813 return isolate->heap()->ToBoolean(maybe.value); 813 return isolate->heap()->ToBoolean(maybe.FromJust());
814 } 814 }
815 815
816 816
817 RUNTIME_FUNCTION(Runtime_HasElement) { 817 RUNTIME_FUNCTION(Runtime_HasElement) {
818 HandleScope scope(isolate); 818 HandleScope scope(isolate);
819 DCHECK(args.length() == 2); 819 DCHECK(args.length() == 2);
820 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0); 820 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0);
821 CONVERT_SMI_ARG_CHECKED(index, 1); 821 CONVERT_SMI_ARG_CHECKED(index, 1);
822 822
823 Maybe<bool> maybe = JSReceiver::HasElement(receiver, index); 823 Maybe<bool> maybe = JSReceiver::HasElement(receiver, index);
824 if (!maybe.has_value) return isolate->heap()->exception(); 824 if (!maybe.IsJust()) return isolate->heap()->exception();
825 return isolate->heap()->ToBoolean(maybe.value); 825 return isolate->heap()->ToBoolean(maybe.FromJust());
826 } 826 }
827 827
828 828
829 RUNTIME_FUNCTION(Runtime_IsPropertyEnumerable) { 829 RUNTIME_FUNCTION(Runtime_IsPropertyEnumerable) {
830 HandleScope scope(isolate); 830 HandleScope scope(isolate);
831 DCHECK(args.length() == 2); 831 DCHECK(args.length() == 2);
832 832
833 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); 833 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
834 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); 834 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1);
835 835
836 Maybe<PropertyAttributes> maybe = 836 Maybe<PropertyAttributes> maybe =
837 JSReceiver::GetOwnPropertyAttributes(object, key); 837 JSReceiver::GetOwnPropertyAttributes(object, key);
838 if (!maybe.has_value) return isolate->heap()->exception(); 838 if (!maybe.IsJust()) return isolate->heap()->exception();
839 if (maybe.value == ABSENT) maybe.value = DONT_ENUM; 839 if (maybe.FromJust() == ABSENT) maybe = Just(DONT_ENUM);
840 return isolate->heap()->ToBoolean((maybe.value & DONT_ENUM) == 0); 840 return isolate->heap()->ToBoolean((maybe.FromJust() & DONT_ENUM) == 0);
841 } 841 }
842 842
843 843
844 RUNTIME_FUNCTION(Runtime_GetPropertyNames) { 844 RUNTIME_FUNCTION(Runtime_GetPropertyNames) {
845 HandleScope scope(isolate); 845 HandleScope scope(isolate);
846 DCHECK(args.length() == 1); 846 DCHECK(args.length() == 1);
847 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0); 847 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0);
848 Handle<JSArray> result; 848 Handle<JSArray> result;
849 849
850 isolate->counters()->for_in()->Increment(); 850 isolate->counters()->for_in()->Increment();
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); 1571 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3);
1572 1572
1573 RETURN_FAILURE_ON_EXCEPTION( 1573 RETURN_FAILURE_ON_EXCEPTION(
1574 isolate, 1574 isolate,
1575 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(), 1575 JSObject::DefineAccessor(object, name, isolate->factory()->null_value(),
1576 setter, attrs)); 1576 setter, attrs));
1577 return isolate->heap()->undefined_value(); 1577 return isolate->heap()->undefined_value();
1578 } 1578 }
1579 } 1579 }
1580 } // namespace v8::internal 1580 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | src/runtime/runtime-scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698