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

Side by Side Diff: Source/bindings/core/v8/V8BindingMacros.h

Issue 232563003: API functions returning Promises should not throw exceptions. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 type var; \ 63 type var; \
64 { \ 64 { \
65 v8::TryCatch block; \ 65 v8::TryCatch block; \
66 var = (value); \ 66 var = (value); \
67 if (UNLIKELY(block.HasCaught())) { \ 67 if (UNLIKELY(block.HasCaught())) { \
68 block.ReThrow(); \ 68 block.ReThrow(); \
69 return retVal; \ 69 return retVal; \
70 } \ 70 } \
71 } 71 }
72 72
73 #define TONATIVE_VOID_ASYNC_INTERNAL(var, value, info) \
74 var = (value); \
75 if (UNLIKELY(block.HasCaught())) { \
76 v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), block .Exception())); \
77 rethrow.cancel(); \
78 return; \
79 }
80
81 #define TONATIVE_VOID_ASYNC(type, var, value, info) \
82 type var; \
83 { \
84 v8::TryCatch block; \
85 V8RethrowTryCatchScope rethrow(block); \
haraken 2014/07/31 07:54:47 Do we need this? It looks redundant to set a V8Ret
yhirano 2014/08/01 02:27:57 We need this to reuse the x_ASYNC_INTERNAL macro i
haraken 2014/08/01 02:42:40 Makes sense. Let's keep the x_ASYNC_INTERNAL macro
86 TONATIVE_VOID_ASYNC_INTERNAL(var, value, info); \
87 }
88
89
73 #define TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(var, value, exceptionState) \ 90 #define TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(var, value, exceptionState) \
74 var = (value); \ 91 var = (value); \
75 if (UNLIKELY(block.HasCaught() || exceptionState.throwIfNeeded())) \ 92 if (UNLIKELY(block.HasCaught() || exceptionState.throwIfNeeded())) \
76 return; \ 93 return; \
77 94
78 #define TONATIVE_VOID_EXCEPTIONSTATE(type, var, value, exceptionState) \ 95 #define TONATIVE_VOID_EXCEPTIONSTATE(type, var, value, exceptionState) \
79 type var; \ 96 type var; \
80 { \ 97 { \
81 v8::TryCatch block; \ 98 v8::TryCatch block; \
82 V8RethrowTryCatchScope rethrow(block); \ 99 V8RethrowTryCatchScope rethrow(block); \
83 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(var, value, exceptionState); \ 100 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(var, value, exceptionState); \
84 } 101 }
85 102
86 #define TONATIVE_DEFAULT_EXCEPTIONSTATE(type, var, value, exceptionState, retVal ) \ 103 #define TONATIVE_DEFAULT_EXCEPTIONSTATE(type, var, value, exceptionState, retVal ) \
87 type var; \ 104 type var; \
88 { \ 105 { \
89 v8::TryCatch block; \ 106 v8::TryCatch block; \
90 V8RethrowTryCatchScope rethrow(block); \ 107 V8RethrowTryCatchScope rethrow(block); \
91 var = (value); \ 108 var = (value); \
92 if (UNLIKELY(block.HasCaught() || exceptionState.throwIfNeeded())) \ 109 if (UNLIKELY(block.HasCaught() || exceptionState.throwIfNeeded())) \
93 return retVal; \ 110 return retVal; \
94 } 111 }
95 112
113 #define TONATIVE_VOID_EXCEPTIONSTATE_ASYNC_INTERNAL(scriptState, var, value, exc eptionState, info) \
114 var = (value); \
115 if (UNLIKELY(block.HasCaught())) { \
116 v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), block .Exception())); \
117 rethrow.cancel(); \
haraken 2014/07/31 07:54:47 Shall we add a comment and mention why we need to
yhirano 2014/08/01 02:27:57 Done.
118 return; \
119 } \
120 if (UNLIKELY(exceptionState.hadException())) { \
121 v8SetReturnValue(info, exceptionState.reject(scriptState).v8Value()); \
122 return; \
123 }
124
125 #define TONATIVE_VOID_EXCEPTIONSTATE_ASYNC(scriptState, type, var, value, except ionState, info) \
126 type var; \
127 { \
128 v8::TryCatch block; \
129 V8RethrowTryCatchScope rethrow(block); \
130 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(scriptState, var, value, exception State, info); \
haraken 2014/07/31 07:54:47 Why doesn't this call TONATIVE_VOID_EXCEPTIONSTATE
yhirano 2014/08/01 02:27:57 You're right. Thanks, done.
131 }
132
96 // type is an instance of class template V8StringResource<>, 133 // type is an instance of class template V8StringResource<>,
97 // but Mode argument varies; using type (not Mode) for consistency 134 // but Mode argument varies; using type (not Mode) for consistency
98 // with other macros and ease of code generation 135 // with other macros and ease of code generation
99 #define TOSTRING_VOID(type, var, value) \ 136 #define TOSTRING_VOID(type, var, value) \
100 type var(value); \ 137 type var(value); \
101 if (UNLIKELY(!var.prepare())) \ 138 if (UNLIKELY(!var.prepare())) \
102 return; 139 return;
103 140
104 #define TOSTRING_VOID_INTERNAL(var, value) \ 141 #define TOSTRING_VOID_INTERNAL(var, value) \
105 var = (value); \ 142 var = (value); \
106 if (UNLIKELY(!var.prepare())) \ 143 if (UNLIKELY(!var.prepare())) \
107 return; 144 return;
108 145
109 #define TOSTRING_DEFAULT(type, var, value, retVal) \ 146 #define TOSTRING_DEFAULT(type, var, value, retVal) \
110 type var(value); \ 147 type var(value); \
111 if (UNLIKELY(!var.prepare())) \ 148 if (UNLIKELY(!var.prepare())) \
112 return retVal; 149 return retVal;
113 150
151 #define TOSTRING_VOID_ASYNC_INTERNAL(var, value, info) \
152 var = (value); \
153 if (UNLIKELY(!var.prepare())) { \
154 rethrow.cancel(); \
haraken 2014/07/31 07:54:47 Just for consistency, let's move rethrow.cancel()
yhirano 2014/08/01 02:27:57 Done.
155 info.GetReturnValue().Set(ScriptPromise::rejectRaw(info.GetIsolate(), bl ock.Exception())); \
156 return; \
157 }
158
159 #define TOSTRING_VOID_ASYNC(type, var, value, info) \
160 type var; \
161 { \
162 v8::TryCatch block; \
163 V8RethrowTryCatchScope rethrow(block); \
164 TOSTRING_VOID_ASYNC_INTERNAL(type, var, value, info); \
165 }
166
114 } // namespace blink 167 } // namespace blink
115 168
116 #endif // V8BindingMacros_h 169 #endif // V8BindingMacros_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698