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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
Index: Source/bindings/core/v8/V8BindingMacros.h
diff --git a/Source/bindings/core/v8/V8BindingMacros.h b/Source/bindings/core/v8/V8BindingMacros.h
index 165d5b7b0144f1c7756a018f4110c2bc2a598063..2756f1d76c74f25a306b99ad4320e4c046461f32 100644
--- a/Source/bindings/core/v8/V8BindingMacros.h
+++ b/Source/bindings/core/v8/V8BindingMacros.h
@@ -70,6 +70,23 @@ namespace blink {
} \
}
+#define TONATIVE_VOID_ASYNC_INTERNAL(var, value, info) \
+ var = (value); \
+ if (UNLIKELY(block.HasCaught())) { \
+ v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), block.Exception())); \
+ rethrow.cancel(); \
Jens Widell 2014/07/30 10:29:10 Would it work to do block.Reset() here instead? I
yhirano 2014/07/31 03:03:25 Sadly, No. When an exception is thrown and is caug
Jens Widell 2014/07/31 08:29:09 That is unfortunate, and sounds like a bug in TryC
yhirano 2014/08/06 05:48:47 I've just created a V8 patch. https://codereview.c
yhirano 2014/08/11 06:29:35 Done.
+ return; \
+ }
+
+#define TONATIVE_VOID_ASYNC(type, var, value, info) \
+ type var; \
+ { \
+ v8::TryCatch block; \
+ V8RethrowTryCatchScope rethrow(block); \
Jens Widell 2014/07/30 10:29:10 Additionally, if we skip rethrow.cancel(), we coul
yhirano 2014/07/31 03:03:25 I think we can't skip rethrow.cancel() at present.
yhirano 2014/08/11 06:29:35 Done.
+ TONATIVE_VOID_ASYNC_INTERNAL(var, value, info); \
+ }
+
+
#define TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(var, value, exceptionState) \
var = (value); \
if (UNLIKELY(block.HasCaught() || exceptionState.throwIfNeeded())) \
@@ -93,6 +110,26 @@ namespace blink {
return retVal; \
}
+#define TONATIVE_VOID_EXCEPTIONSTATE_ASYNC_INTERNAL(scriptState, var, value, exceptionState, info) \
+ var = (value); \
+ if (UNLIKELY(block.HasCaught())) { \
+ v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), block.Exception())); \
+ rethrow.cancel(); \
+ return; \
+ } \
+ if (UNLIKELY(exceptionState.hadException())) { \
+ v8SetReturnValue(info, exceptionState.reject(scriptState).v8Value()); \
+ return; \
+ }
+
+#define TONATIVE_VOID_EXCEPTIONSTATE_ASYNC(scriptState, type, var, value, exceptionState, info) \
+ type var; \
+ { \
+ v8::TryCatch block; \
+ V8RethrowTryCatchScope rethrow(block); \
+ TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(scriptState, var, value, exceptionState, info); \
+ }
+
// type is an instance of class template V8StringResource<>,
// but Mode argument varies; using type (not Mode) for consistency
// with other macros and ease of code generation
@@ -111,6 +148,22 @@ namespace blink {
if (UNLIKELY(!var.prepare())) \
return retVal;
+#define TOSTRING_VOID_ASYNC_INTERNAL(var, value, info) \
+ var = (value); \
+ if (UNLIKELY(!var.prepare())) { \
+ rethrow.cancel(); \
+ info.GetReturnValue().Set(ScriptPromise::rejectRaw(info.GetIsolate(), block.Exception())); \
+ return; \
+ }
+
+#define TOSTRING_VOID_ASYNC(type, var, value, info) \
+ type var; \
+ { \
+ v8::TryCatch block; \
+ V8RethrowTryCatchScope rethrow(block); \
+ TOSTRING_VOID_ASYNC_INTERNAL(type, var, value, info); \
+ }
+
} // namespace blink
#endif // V8BindingMacros_h

Powered by Google App Engine
This is Rietveld 408576698