27
27
28
28
#include < jni.h>
29
29
30
+ #include < wtf/Ref.h>
30
31
#include < wtf/RefPtr.h>
32
+ #include < wtf/GetPtr.h>
31
33
#include < wtf/text/WTFString.h>
32
34
#include " ExceptionOr.h"
33
35
@@ -58,6 +60,8 @@ void raiseNotSupportedErrorException(JNIEnv*);
58
60
void raiseDOMErrorException (JNIEnv*, Exception&&);
59
61
60
62
template <typename T> T raiseOnDOMError (JNIEnv*, ExceptionOr<T>&&);
63
+ template <typename T> T* raiseOnDOMError (JNIEnv*, ExceptionOr<Ref<T>>&&);
64
+ String raiseOnDOMError (JNIEnv*, ExceptionOr<String>&&);
61
65
void raiseOnDOMError (JNIEnv*, ExceptionOr<void >&&);
62
66
63
67
inline void raiseOnDOMError (JNIEnv* env, ExceptionOr<void >&& possibleException)
@@ -66,10 +70,30 @@ inline void raiseOnDOMError(JNIEnv* env, ExceptionOr<void>&& possibleException)
66
70
raiseDOMErrorException (env, possibleException.releaseException ());
67
71
}
68
72
73
+ inline String raiseOnDOMError (JNIEnv* env, ExceptionOr<String>&& exceptionOrReturnValue)
74
+ {
75
+ if (exceptionOrReturnValue.hasException ()) {
76
+ raiseDOMErrorException (env, exceptionOrReturnValue.releaseException ());
77
+ return emptyString ();
78
+ }
79
+ return exceptionOrReturnValue.releaseReturnValue ();
80
+ }
81
+
82
+ template <typename T> inline T* raiseOnDOMError (JNIEnv* env, ExceptionOr<Ref<T>>&& exceptionOrReturnValue)
83
+ {
84
+ if (exceptionOrReturnValue.hasException ()) {
85
+ raiseDOMErrorException (env, exceptionOrReturnValue.releaseException ());
86
+ return nullptr ;
87
+ }
88
+ return WTF::getPtr (exceptionOrReturnValue.releaseReturnValue ());
89
+ }
90
+
69
91
template <typename T> inline T raiseOnDOMError (JNIEnv* env, ExceptionOr<T>&& exceptionOrReturnValue)
70
92
{
71
- if (exceptionOrReturnValue.hasException ())
93
+ if (exceptionOrReturnValue.hasException ()) {
72
94
raiseDOMErrorException (env, exceptionOrReturnValue.releaseException ());
95
+ return static_cast <T>(NULL );
96
+ }
73
97
return exceptionOrReturnValue.releaseReturnValue ();
74
98
}
75
99
0 commit comments