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

Side by Side Diff: src/accessors.cc

Issue 245963007: Clean up some uses of Failures and MaybeObjects. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: address comments Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/accessors.h ('k') | src/execution.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 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 template <class C> 66 template <class C>
67 static C* FindInstanceOf(Isolate* isolate, Object* obj) { 67 static C* FindInstanceOf(Isolate* isolate, Object* obj) {
68 for (Object* cur = obj; !cur->IsNull(); cur = cur->GetPrototype(isolate)) { 68 for (Object* cur = obj; !cur->IsNull(); cur = cur->GetPrototype(isolate)) {
69 if (Is<C>(cur)) return C::cast(cur); 69 if (Is<C>(cur)) return C::cast(cur);
70 } 70 }
71 return NULL; 71 return NULL;
72 } 72 }
73 73
74 74
75 // Entry point that never should be called. 75 // Entry point that never should be called.
76 MaybeObject* Accessors::IllegalSetter(Isolate* isolate, 76 Object* Accessors::IllegalSetter(Isolate* isolate,
77 JSObject*, 77 JSObject*,
78 Object*, 78 Object*,
79 void*) { 79 void*) {
80 UNREACHABLE(); 80 UNREACHABLE();
81 return NULL; 81 return NULL;
82 } 82 }
83 83
84 84
85 Object* Accessors::IllegalGetAccessor(Isolate* isolate, 85 Object* Accessors::IllegalGetAccessor(Isolate* isolate,
86 Object* object, 86 Object* object,
87 void*) { 87 void*) {
88 UNREACHABLE(); 88 UNREACHABLE();
89 return object; 89 return object;
90 } 90 }
91 91
92 92
93 MaybeObject* Accessors::ReadOnlySetAccessor(Isolate* isolate, 93 Object* Accessors::ReadOnlySetAccessor(Isolate* isolate,
94 JSObject*, 94 JSObject*,
95 Object* value, 95 Object* value,
96 void*) { 96 void*) {
97 // According to ECMA-262, section 8.6.2.2, page 28, setting 97 // According to ECMA-262, section 8.6.2.2, page 28, setting
98 // read-only properties must be silently ignored. 98 // read-only properties must be silently ignored.
99 return value; 99 return value;
100 } 100 }
101 101
102 102
103 static V8_INLINE bool CheckForName(Handle<String> name, 103 static V8_INLINE bool CheckForName(Handle<String> name,
104 Handle<String> property_name, 104 Handle<String> property_name,
105 int offset, 105 int offset,
106 int* object_offset) { 106 int* object_offset) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 bool Accessors::IsJSObjectFieldAccessor<HeapType>(Handle<HeapType> type, 167 bool Accessors::IsJSObjectFieldAccessor<HeapType>(Handle<HeapType> type,
168 Handle<String> name, 168 Handle<String> name,
169 int* object_offset); 169 int* object_offset);
170 170
171 171
172 // 172 //
173 // Accessors::ArrayLength 173 // Accessors::ArrayLength
174 // 174 //
175 175
176 176
177 MaybeObject* Accessors::ArrayGetLength(Isolate* isolate, 177 Object* Accessors::ArrayGetLength(Isolate* isolate,
178 Object* object, 178 Object* object,
179 void*) { 179 void*) {
180 // Traverse the prototype chain until we reach an array. 180 // Traverse the prototype chain until we reach an array.
181 JSArray* holder = FindInstanceOf<JSArray>(isolate, object); 181 JSArray* holder = FindInstanceOf<JSArray>(isolate, object);
182 return holder == NULL ? Smi::FromInt(0) : holder->length(); 182 return holder == NULL ? Smi::FromInt(0) : holder->length();
183 } 183 }
184 184
185 185
186 // The helper function will 'flatten' Number objects. 186 // The helper function will 'flatten' Number objects.
187 Handle<Object> Accessors::FlattenNumber(Isolate* isolate, 187 Handle<Object> Accessors::FlattenNumber(Isolate* isolate,
188 Handle<Object> value) { 188 Handle<Object> value) {
189 if (value->IsNumber() || !value->IsJSValue()) return value; 189 if (value->IsNumber() || !value->IsJSValue()) return value;
190 Handle<JSValue> wrapper = Handle<JSValue>::cast(value); 190 Handle<JSValue> wrapper = Handle<JSValue>::cast(value);
191 ASSERT(wrapper->GetIsolate()->context()->native_context()->number_function()-> 191 ASSERT(wrapper->GetIsolate()->context()->native_context()->number_function()->
192 has_initial_map()); 192 has_initial_map());
193 if (wrapper->map() == 193 if (wrapper->map() ==
194 isolate->context()->native_context()->number_function()->initial_map()) { 194 isolate->context()->native_context()->number_function()->initial_map()) {
195 return handle(wrapper->value(), isolate); 195 return handle(wrapper->value(), isolate);
196 } 196 }
197 197
198 return value; 198 return value;
199 } 199 }
200 200
201 201
202 MaybeObject* Accessors::ArraySetLength(Isolate* isolate, 202 Object* Accessors::ArraySetLength(Isolate* isolate,
203 JSObject* object_raw, 203 JSObject* object_raw,
204 Object* value_raw, 204 Object* value_raw,
205 void*) { 205 void*) {
206 HandleScope scope(isolate); 206 HandleScope scope(isolate);
207 Handle<JSObject> object(object_raw, isolate); 207 Handle<JSObject> object(object_raw, isolate);
208 Handle<Object> value(value_raw, isolate); 208 Handle<Object> value(value_raw, isolate);
209 209
210 // This means one of the object's prototypes is a JSArray and the 210 // This means one of the object's prototypes is a JSArray and the
211 // object does not have a 'length' property. Calling SetProperty 211 // object does not have a 'length' property. Calling SetProperty
212 // causes an infinite loop. 212 // causes an infinite loop.
213 if (!object->IsJSArray()) { 213 if (!object->IsJSArray()) {
214 Handle<Object> result; 214 Handle<Object> result;
215 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 215 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function, 844 Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function,
845 Handle<Object> prototype) { 845 Handle<Object> prototype) {
846 ASSERT(function->should_have_prototype()); 846 ASSERT(function->should_have_prototype());
847 Isolate* isolate = function->GetIsolate(); 847 Isolate* isolate = function->GetIsolate();
848 Handle<Object> result; 848 Handle<Object> result;
849 SetFunctionPrototype(isolate, function, prototype).ToHandle(&result); 849 SetFunctionPrototype(isolate, function, prototype).ToHandle(&result);
850 return result; 850 return result;
851 } 851 }
852 852
853 853
854 MaybeObject* Accessors::FunctionGetPrototype(Isolate* isolate, 854 Object* Accessors::FunctionGetPrototype(Isolate* isolate,
855 Object* object, 855 Object* object,
856 void*) { 856 void*) {
857 HandleScope scope(isolate); 857 HandleScope scope(isolate);
858 return *GetFunctionPrototype(isolate, Handle<Object>(object, isolate)); 858 return *GetFunctionPrototype(isolate, Handle<Object>(object, isolate));
859 } 859 }
860 860
861 861
862 MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate, 862 Object* Accessors::FunctionSetPrototype(Isolate* isolate,
863 JSObject* object, 863 JSObject* object,
864 Object* value, 864 Object* value,
865 void*) { 865 void*) {
866 Handle<Object> result; 866 Handle<Object> result;
867 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 867 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
868 isolate, result, 868 isolate, result,
869 SetFunctionPrototype(isolate, 869 SetFunctionPrototype(isolate,
870 Handle<JSObject>(object, isolate), 870 Handle<JSObject>(object, isolate),
871 Handle<Object>(value, isolate))); 871 Handle<Object>(value, isolate)));
872 return *result; 872 return *result;
873 } 873 }
874 874
875 875
876 const AccessorDescriptor Accessors::FunctionPrototype = { 876 const AccessorDescriptor Accessors::FunctionPrototype = {
877 FunctionGetPrototype, 877 FunctionGetPrototype,
878 FunctionSetPrototype, 878 FunctionSetPrototype,
879 0 879 0
880 }; 880 };
881 881
882 882
883 // 883 //
884 // Accessors::FunctionLength 884 // Accessors::FunctionLength
885 // 885 //
886 886
887 887
888 MaybeObject* Accessors::FunctionGetLength(Isolate* isolate, 888 Object* Accessors::FunctionGetLength(Isolate* isolate,
889 Object* object, 889 Object* object,
890 void*) { 890 void*) {
891 JSFunction* function = FindInstanceOf<JSFunction>(isolate, object); 891 JSFunction* function = FindInstanceOf<JSFunction>(isolate, object);
892 if (function == NULL) return Smi::FromInt(0); 892 if (function == NULL) return Smi::FromInt(0);
893 // Check if already compiled. 893 // Check if already compiled.
894 if (function->shared()->is_compiled()) { 894 if (function->shared()->is_compiled()) {
895 return Smi::FromInt(function->shared()->length()); 895 return Smi::FromInt(function->shared()->length());
896 } 896 }
897 // If the function isn't compiled yet, the length is not computed correctly 897 // If the function isn't compiled yet, the length is not computed correctly
898 // yet. Compile it now and return the right length. 898 // yet. Compile it now and return the right length.
899 HandleScope scope(isolate); 899 HandleScope scope(isolate);
900 Handle<JSFunction> function_handle(function); 900 Handle<JSFunction> function_handle(function);
901 if (Compiler::EnsureCompiled(function_handle, KEEP_EXCEPTION)) { 901 if (Compiler::EnsureCompiled(function_handle, KEEP_EXCEPTION)) {
902 return Smi::FromInt(function_handle->shared()->length()); 902 return Smi::FromInt(function_handle->shared()->length());
903 } 903 }
904 return isolate->heap()->exception(); 904 return isolate->heap()->exception();
905 } 905 }
906 906
907 907
908 const AccessorDescriptor Accessors::FunctionLength = { 908 const AccessorDescriptor Accessors::FunctionLength = {
909 FunctionGetLength, 909 FunctionGetLength,
910 ReadOnlySetAccessor, 910 ReadOnlySetAccessor,
911 0 911 0
912 }; 912 };
913 913
914 914
915 // 915 //
916 // Accessors::FunctionName 916 // Accessors::FunctionName
917 // 917 //
918 918
919 919
920 MaybeObject* Accessors::FunctionGetName(Isolate* isolate, 920 Object* Accessors::FunctionGetName(Isolate* isolate,
921 Object* object, 921 Object* object,
922 void*) { 922 void*) {
923 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object); 923 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
924 return holder == NULL 924 return holder == NULL
925 ? isolate->heap()->undefined_value() 925 ? isolate->heap()->undefined_value()
926 : holder->shared()->name(); 926 : holder->shared()->name();
927 } 927 }
928 928
929 929
930 const AccessorDescriptor Accessors::FunctionName = { 930 const AccessorDescriptor Accessors::FunctionName = {
931 FunctionGetName, 931 FunctionGetName,
932 ReadOnlySetAccessor, 932 ReadOnlySetAccessor,
933 0 933 0
934 }; 934 };
935 935
936 936
937 // 937 //
938 // Accessors::FunctionArguments 938 // Accessors::FunctionArguments
939 // 939 //
940 940
941 941
942 Handle<Object> Accessors::FunctionGetArguments(Handle<JSFunction> function) { 942 Handle<Object> Accessors::FunctionGetArguments(Handle<JSFunction> function) {
943 CALL_HEAP_FUNCTION(function->GetIsolate(), 943 CALL_HEAP_FUNCTION(function->GetIsolate(),
944 Accessors::FunctionGetArguments(function->GetIsolate(), 944 Accessors::FunctionGetArguments(function->GetIsolate(),
945 *function, 945 *function,
946 NULL), 946 NULL),
947 Object); 947 Object);
948 } 948 }
949 949
950 950
951 static MaybeObject* ConstructArgumentsObjectForInlinedFunction( 951 static Object* ConstructArgumentsObjectForInlinedFunction(
952 JavaScriptFrame* frame, 952 JavaScriptFrame* frame,
953 Handle<JSFunction> inlined_function, 953 Handle<JSFunction> inlined_function,
954 int inlined_frame_index) { 954 int inlined_frame_index) {
955 Isolate* isolate = inlined_function->GetIsolate(); 955 Isolate* isolate = inlined_function->GetIsolate();
956 Factory* factory = isolate->factory(); 956 Factory* factory = isolate->factory();
957 SlotRefValueBuilder slot_refs( 957 SlotRefValueBuilder slot_refs(
958 frame, 958 frame,
959 inlined_frame_index, 959 inlined_frame_index,
960 inlined_function->shared()->formal_parameter_count()); 960 inlined_function->shared()->formal_parameter_count());
961 961
962 int args_count = slot_refs.args_length(); 962 int args_count = slot_refs.args_length();
963 Handle<JSObject> arguments = 963 Handle<JSObject> arguments =
964 factory->NewArgumentsObject(inlined_function, args_count); 964 factory->NewArgumentsObject(inlined_function, args_count);
965 Handle<FixedArray> array = factory->NewFixedArray(args_count); 965 Handle<FixedArray> array = factory->NewFixedArray(args_count);
966 slot_refs.Prepare(isolate); 966 slot_refs.Prepare(isolate);
967 for (int i = 0; i < args_count; ++i) { 967 for (int i = 0; i < args_count; ++i) {
968 Handle<Object> value = slot_refs.GetNext(isolate, 0); 968 Handle<Object> value = slot_refs.GetNext(isolate, 0);
969 array->set(i, *value); 969 array->set(i, *value);
970 } 970 }
971 slot_refs.Finish(isolate); 971 slot_refs.Finish(isolate);
972 arguments->set_elements(*array); 972 arguments->set_elements(*array);
973 973
974 // Return the freshly allocated arguments object. 974 // Return the freshly allocated arguments object.
975 return *arguments; 975 return *arguments;
976 } 976 }
977 977
978 978
979 MaybeObject* Accessors::FunctionGetArguments(Isolate* isolate, 979 Object* Accessors::FunctionGetArguments(Isolate* isolate,
980 Object* object, 980 Object* object,
981 void*) { 981 void*) {
982 HandleScope scope(isolate); 982 HandleScope scope(isolate);
983 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object); 983 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
984 if (holder == NULL) return isolate->heap()->undefined_value(); 984 if (holder == NULL) return isolate->heap()->undefined_value();
985 Handle<JSFunction> function(holder, isolate); 985 Handle<JSFunction> function(holder, isolate);
986 986
987 if (function->shared()->native()) return isolate->heap()->null_value(); 987 if (function->shared()->native()) return isolate->heap()->null_value();
988 // Find the top invocation of the function by traversing frames. 988 // Find the top invocation of the function by traversing frames.
989 List<JSFunction*> functions(2); 989 List<JSFunction*> functions(2);
990 for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) { 990 for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) {
991 JavaScriptFrame* frame = it.frame(); 991 JavaScriptFrame* frame = it.frame();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 ASSERT(functions_.length() > 0); 1093 ASSERT(functions_.length() > 0);
1094 frame_iterator_.Advance(); 1094 frame_iterator_.Advance();
1095 index_ = functions_.length() - 1; 1095 index_ = functions_.length() - 1;
1096 } 1096 }
1097 JavaScriptFrameIterator frame_iterator_; 1097 JavaScriptFrameIterator frame_iterator_;
1098 List<JSFunction*> functions_; 1098 List<JSFunction*> functions_;
1099 int index_; 1099 int index_;
1100 }; 1100 };
1101 1101
1102 1102
1103 MaybeObject* Accessors::FunctionGetCaller(Isolate* isolate, 1103 Object* Accessors::FunctionGetCaller(Isolate* isolate,
1104 Object* object, 1104 Object* object,
1105 void*) { 1105 void*) {
1106 HandleScope scope(isolate); 1106 HandleScope scope(isolate);
1107 DisallowHeapAllocation no_allocation; 1107 DisallowHeapAllocation no_allocation;
1108 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object); 1108 JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
1109 if (holder == NULL) return isolate->heap()->undefined_value(); 1109 if (holder == NULL) return isolate->heap()->undefined_value();
1110 if (holder->shared()->native()) return isolate->heap()->null_value(); 1110 if (holder->shared()->native()) return isolate->heap()->null_value();
1111 Handle<JSFunction> function(holder, isolate); 1111 Handle<JSFunction> function(holder, isolate);
1112 1112
1113 FrameFunctionIterator it(isolate, no_allocation); 1113 FrameFunctionIterator it(isolate, no_allocation);
1114 1114
1115 // Find the function from the frames. 1115 // Find the function from the frames.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 info->set_data(Smi::FromInt(index)); 1218 info->set_data(Smi::FromInt(index));
1219 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); 1219 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport);
1220 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); 1220 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport);
1221 info->set_getter(*getter); 1221 info->set_getter(*getter);
1222 if (!(attributes & ReadOnly)) info->set_setter(*setter); 1222 if (!(attributes & ReadOnly)) info->set_setter(*setter);
1223 return info; 1223 return info;
1224 } 1224 }
1225 1225
1226 1226
1227 } } // namespace v8::internal 1227 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/accessors.h ('k') | src/execution.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698