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

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, 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/core/v8/V8Binding.h ('k') | Source/bindings/scripts/v8_interface.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..798d5b36ec0d8884dd95b740be61987d154a6e17 100644
--- a/Source/bindings/core/v8/V8BindingMacros.h
+++ b/Source/bindings/core/v8/V8BindingMacros.h
@@ -70,6 +70,24 @@ namespace blink {
} \
}
+// We need to cancel the exception propergation when we return a rejected
+// Promise.
+#define TONATIVE_VOID_PROMISE_INTERNAL(var, value, info) \
+ var = (value); \
+ if (UNLIKELY(block.HasCaught())) { \
+ v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), block.Exception())); \
+ block.Reset(); \
+ return; \
+ }
+
+#define TONATIVE_VOID_PROMISE(type, var, value, info) \
+ type var; \
+ { \
+ v8::TryCatch block; \
+ TONATIVE_VOID_PROMISE_INTERNAL(var, value, info); \
+ }
+
+
#define TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(var, value, exceptionState) \
var = (value); \
if (UNLIKELY(block.HasCaught() || exceptionState.throwIfNeeded())) \
@@ -93,6 +111,27 @@ namespace blink {
return retVal; \
}
+// We need to cancel the exception propergation when we return a rejected
+// Promise.
+#define TONATIVE_VOID_EXCEPTIONSTATE_PROMISE_INTERNAL(var, value, exceptionState, info, scriptState) \
+ var = (value); \
+ if (UNLIKELY(block.HasCaught())) { \
+ v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), block.Exception())); \
+ block.Reset(); \
+ return; \
+ } \
+ if (UNLIKELY(exceptionState.hadException())) { \
+ v8SetReturnValue(info, exceptionState.reject(scriptState).v8Value()); \
+ return; \
+ }
+
+#define TONATIVE_VOID_EXCEPTIONSTATE_PROMISE(type, var, value, exceptionState, info, scriptState) \
+ type var; \
+ { \
+ v8::TryCatch block; \
+ TONATIVE_VOID_EXCEPTIONSTATE_PROMISE_INTERNAL(var, value, exceptionState, info, scriptState); \
+ }
+
// 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 +150,23 @@ namespace blink {
if (UNLIKELY(!var.prepare())) \
return retVal;
+// We need to cancel the exception propergation when we return a rejected
+// Promise.
+#define TOSTRING_VOID_PROMISE_INTERNAL(var, value, info) \
+ var = (value); \
+ if (UNLIKELY(!var.prepare())) { \
+ info.GetReturnValue().Set(ScriptPromise::rejectRaw(info.GetIsolate(), block.Exception())); \
+ block.Reset(); \
+ return; \
+ }
+
+#define TOSTRING_VOID_PROMISE(type, var, value, info) \
+ type var; \
+ { \
+ v8::TryCatch block; \
+ TOSTRING_VOID_PROMISE_INTERNAL(type, var, value, info); \
+ }
+
} // namespace blink
#endif // V8BindingMacros_h
« no previous file with comments | « Source/bindings/core/v8/V8Binding.h ('k') | Source/bindings/scripts/v8_interface.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698