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

Unified Diff: Source/bindings/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, 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 side-by-side diff with in-line comments
Download patch
Index: Source/bindings/v8/V8BindingMacros.h
diff --git a/Source/bindings/v8/V8BindingMacros.h b/Source/bindings/v8/V8BindingMacros.h
index f5ab5832bef8783b2b6e8890d6f03dce09915a27..4b30694221b7b490f11dc2c1aa152a46e99c24f0 100644
--- a/Source/bindings/v8/V8BindingMacros.h
+++ b/Source/bindings/v8/V8BindingMacros.h
@@ -86,6 +86,33 @@ namespace WebCore {
return; \
}
+#define V8TRYCATCH_VOID_PROMISE(type, var, value, info) \
+ type var; \
+ { \
+ v8::TryCatch block; \
+ var = (value); \
+ if (UNLIKELY(block.HasCaught())) { \
+ v8::Isolate* isolate = info.GetIsolate(); \
+ ScriptPromise promise = ScriptPromise::reject(block.Exception(), isolate); \
+ v8SetReturnValue(info, promise.v8Value()); \
+ return; \
+ } \
+ }
+
+#define V8TRYCATCH_EXCEPTION_VOID_PROMISE(type, var, value, info, exceptionState) \
haraken 2014/04/10 12:09:17 The macro names in this file are getting broken...
Nils Barth (inactive) 2014/04/11 01:03:41 I'll grab this. My suggestion: V8TRYCATCH[_TYPE][
Nils Barth (inactive) 2014/04/11 02:19:38 Posted: Rename V8TRYCATCH_* macros in v8/V8Binding
yhirano 2014/04/11 10:19:04 Done.
+ type var; \
+ { \
+ v8::TryCatch block; \
+ var = (value); \
+ v8::Isolate* isolate = info.GetIsolate(); \
+ if (UNLIKELY(block.HasCaught())) \
+ exceptionState.rethrowV8Exception(block.Exception()); \
+ if (UNLIKELY(exceptionState.hadException())) { \
haraken 2014/04/10 12:09:17 Shouldn't this be exceptionState.throwIfNeeded()?
yhirano 2014/04/11 10:19:04 What I want to do is returning a Promise rejected
+ v8SetReturnValue(info, exceptionState.rejectedPromise().v8Value()); \
+ return; \
+ } \
+ }
+
#define V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(type, var, value, retVal) \
type var(value); \
if (UNLIKELY(!var.prepare())) \
@@ -96,6 +123,19 @@ namespace WebCore {
if (UNLIKELY(!var.prepare())) \
return;
+#define V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID_PROMISE(type, var, value, info) \
+ type var(value); \
+ { \
+ v8::TryCatch block; \
+ var.prepare(); \
+ if (UNLIKELY(block.HasCaught())) { \
+ v8::Isolate* isolate = info.GetIsolate(); \
+ ScriptPromise promise = ScriptPromise::reject(block.Exception(), isolate); \
+ v8SetReturnValue(info, promise.v8Value()); \
+ return; \
+ } \
+ }
+
} // namespace WebCore
#endif // V8BindingMacros_h

Powered by Google App Engine
This is Rietveld 408576698