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

Side by Side Diff: src/isolate.h

Issue 222163002: Introduce MaybeHandle to police exception checking in handlified code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comment 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/handles.h ('k') | src/objects.h » ('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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 127
128 #define RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, T) \ 128 #define RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, T) \
129 do { \ 129 do { \
130 Isolate* __isolate__ = (isolate); \ 130 Isolate* __isolate__ = (isolate); \
131 if (__isolate__->has_scheduled_exception()) { \ 131 if (__isolate__->has_scheduled_exception()) { \
132 __isolate__->PromoteScheduledException(); \ 132 __isolate__->PromoteScheduledException(); \
133 return Handle<T>::null(); \ 133 return Handle<T>::null(); \
134 } \ 134 } \
135 } while (false) 135 } while (false)
136 136
137 #define RETURN_IF_EMPTY_HANDLE_VALUE(isolate, call, value) \ 137 #define RETURN_IF_EMPTY_HANDLE_VALUE(isolate, call, value) \
138 do { \ 138 do { \
139 if ((call).is_null()) { \ 139 if ((call).is_null()) { \
140 ASSERT((isolate)->has_pending_exception()); \ 140 ASSERT((isolate)->has_pending_exception()); \
141 return (value); \ 141 return (value); \
142 } \ 142 } \
143 } while (false) 143 } while (false)
144 144
145 #define CHECK_NOT_EMPTY_HANDLE(isolate, call) \ 145 #define CHECK_NOT_EMPTY_HANDLE(isolate, call) \
146 do { \ 146 do { \
147 ASSERT(!(isolate)->has_pending_exception()); \ 147 ASSERT(!(isolate)->has_pending_exception()); \
148 CHECK(!(call).is_null()); \ 148 CHECK(!(call).is_null()); \
149 } while (false) 149 } while (false)
150 150
151 #define RETURN_IF_EMPTY_HANDLE(isolate, call) \ 151 #define RETURN_IF_EMPTY_HANDLE(isolate, call) \
152 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, call, Failure::Exception()) 152 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, call, Failure::Exception())
153 153
154
155 // Macros for MaybeHandle.
156
157 #define RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, T) \
158 do { \
159 Isolate* __isolate__ = (isolate); \
160 if (__isolate__->has_scheduled_exception()) { \
161 __isolate__->PromoteScheduledException(); \
162 return MaybeHandle<T>(); \
163 } \
164 } while (false)
165
166 #define ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, value) \
167 do { \
168 if (!(call).ToHandle(&dst)) { \
169 ASSERT((isolate)->has_pending_exception()); \
170 return value; \
171 } \
172 } while (false)
173
174 #define ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, dst, call) \
175 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, Failure::Exception())
176
177 #define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call, T) \
178 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, MaybeHandle<T>())
179
180 #define RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, value) \
181 do { \
182 if (call.is_null()) { \
183 ASSERT((isolate)->has_pending_exception()); \
184 return value; \
185 } \
186 } while (false)
187
188 #define RETURN_FAILURE_ON_EXCEPTION(isolate, call) \
189 RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, Failure::Exception())
190
191 #define RETURN_ON_EXCEPTION(isolate, call, T) \
192 RETURN_ON_EXCEPTION_VALUE( \
193 isolate, dst, call, MaybeHandle<T>::Exception())
194
195
154 #define FOR_EACH_ISOLATE_ADDRESS_NAME(C) \ 196 #define FOR_EACH_ISOLATE_ADDRESS_NAME(C) \
155 C(Handler, handler) \ 197 C(Handler, handler) \
156 C(CEntryFP, c_entry_fp) \ 198 C(CEntryFP, c_entry_fp) \
157 C(Context, context) \ 199 C(Context, context) \
158 C(PendingException, pending_exception) \ 200 C(PendingException, pending_exception) \
159 C(ExternalCaughtException, external_caught_exception) \ 201 C(ExternalCaughtException, external_caught_exception) \
160 C(JSEntrySP, js_entry_sp) 202 C(JSEntrySP, js_entry_sp)
161 203
162 204
163 // Platform-independent, reliable thread identifier. 205 // Platform-independent, reliable thread identifier.
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 bool MayIndexedAccess(JSObject* receiver, 802 bool MayIndexedAccess(JSObject* receiver,
761 uint32_t index, 803 uint32_t index,
762 v8::AccessType type); 804 v8::AccessType type);
763 805
764 void SetFailedAccessCheckCallback(v8::FailedAccessCheckCallback callback); 806 void SetFailedAccessCheckCallback(v8::FailedAccessCheckCallback callback);
765 void ReportFailedAccessCheck(JSObject* receiver, v8::AccessType type); 807 void ReportFailedAccessCheck(JSObject* receiver, v8::AccessType type);
766 808
767 // Exception throwing support. The caller should use the result 809 // Exception throwing support. The caller should use the result
768 // of Throw() as its return value. 810 // of Throw() as its return value.
769 Failure* Throw(Object* exception, MessageLocation* location = NULL); 811 Failure* Throw(Object* exception, MessageLocation* location = NULL);
812
813 template <typename T>
814 MUST_USE_RESULT MaybeHandle<T> Throw(Handle<Object> exception,
815 MessageLocation* location = NULL) {
816 Throw(*exception, location);
817 return MaybeHandle<T>();
818 }
819
770 // Re-throw an exception. This involves no error reporting since 820 // Re-throw an exception. This involves no error reporting since
771 // error reporting was handled when the exception was thrown 821 // error reporting was handled when the exception was thrown
772 // originally. 822 // originally.
773 Failure* ReThrow(MaybeObject* exception); 823 Failure* ReThrow(MaybeObject* exception);
774 void ScheduleThrow(Object* exception); 824 void ScheduleThrow(Object* exception);
775 // Re-set pending message, script and positions reported to the TryCatch 825 // Re-set pending message, script and positions reported to the TryCatch
776 // back to the TLS for re-use when rethrowing. 826 // back to the TLS for re-use when rethrowing.
777 void RestorePendingMessageFromTryCatch(v8::TryCatch* handler); 827 void RestorePendingMessageFromTryCatch(v8::TryCatch* handler);
778 void ReportPendingMessages(); 828 void ReportPendingMessages();
779 // Return pending location if any or unfilled structure. 829 // Return pending location if any or unfilled structure.
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 } 1582 }
1533 1583
1534 EmbeddedVector<char, 128> filename_; 1584 EmbeddedVector<char, 128> filename_;
1535 FILE* file_; 1585 FILE* file_;
1536 int scope_depth_; 1586 int scope_depth_;
1537 }; 1587 };
1538 1588
1539 } } // namespace v8::internal 1589 } } // namespace v8::internal
1540 1590
1541 #endif // V8_ISOLATE_H_ 1591 #endif // V8_ISOLATE_H_
OLDNEW
« no previous file with comments | « src/handles.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698