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

Unified Diff: third_party/WebKit/Source/bindings/core/v8/GeneratedCodeHelper.h

Issue 2301993002: binding: Introduces ExceptionToPromiseScope. (Closed)
Patch Set: Addressed review comments (rename, empty line). Created 4 years, 3 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 | « no previous file | third_party/WebKit/Source/bindings/scripts/code_generator_v8.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/bindings/core/v8/GeneratedCodeHelper.h
diff --git a/third_party/WebKit/Source/bindings/core/v8/GeneratedCodeHelper.h b/third_party/WebKit/Source/bindings/core/v8/GeneratedCodeHelper.h
index 2bb7093baae50d29d70e7939b8a5b4ae93076732..1ee06ad2081f4f43c4515f8bd4357344631fa73c 100644
--- a/third_party/WebKit/Source/bindings/core/v8/GeneratedCodeHelper.h
+++ b/third_party/WebKit/Source/bindings/core/v8/GeneratedCodeHelper.h
@@ -11,18 +11,48 @@
#ifndef GeneratedCodeHelper_h
#define GeneratedCodeHelper_h
+#include "bindings/core/v8/ExceptionState.h"
+#include "bindings/core/v8/V8Binding.h"
#include "core/CoreExport.h"
#include "wtf/PassRefPtr.h"
#include <v8.h>
namespace blink {
+class ScriptState;
class SerializedScriptValue;
CORE_EXPORT void v8ConstructorAttributeGetter(v8::Local<v8::Name> propertyName, const v8::PropertyCallbackInfo<v8::Value>&);
CORE_EXPORT v8::Local<v8::Value> v8Deserialize(v8::Isolate*, PassRefPtr<SerializedScriptValue>);
+// ExceptionToRejectPromiseScope converts a possible exception to a reject
+// promise and returns the promise instead of throwing the exception.
+//
+// Promise-returning DOM operations are required to always return a promise
+// and to never throw an exception.
+// See also http://heycam.github.io/webidl/#es-operations
+class CORE_EXPORT ExceptionToRejectPromiseScope {
+ STACK_ALLOCATED();
+public:
+ ExceptionToRejectPromiseScope(const v8::FunctionCallbackInfo<v8::Value>& info, ScriptState* scriptState, ExceptionState& exceptionState)
+ : m_info(info)
+ , m_scriptState(scriptState)
+ , m_exceptionState(exceptionState) { }
+ ~ExceptionToRejectPromiseScope()
+ {
+ if (!m_exceptionState.hadException())
+ return;
+
+ v8SetReturnValue(m_info, m_exceptionState.reject(m_scriptState).v8Value());
+ }
+
+private:
+ const v8::FunctionCallbackInfo<v8::Value>& m_info;
+ ScriptState* m_scriptState;
+ ExceptionState& m_exceptionState;
+};
+
} // namespace blink
#endif // GeneratedCodeHelper_h
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/scripts/code_generator_v8.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698