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

Unified Diff: Source/bindings/core/v8/ScriptPromise.cpp

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/ScriptPromise.h ('k') | Source/bindings/core/v8/V8Binding.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/core/v8/ScriptPromise.cpp
diff --git a/Source/bindings/core/v8/ScriptPromise.cpp b/Source/bindings/core/v8/ScriptPromise.cpp
index 44c6a93757a79a9ee69721c34e67d0878cab27d3..6400b7b203ba911afe8175cfdf78147bf4f61d27 100644
--- a/Source/bindings/core/v8/ScriptPromise.cpp
+++ b/Source/bindings/core/v8/ScriptPromise.cpp
@@ -31,7 +31,10 @@
#include "config.h"
#include "bindings/core/v8/ScriptPromise.h"
+#include "bindings/core/v8/ExceptionMessages.h"
+#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/V8Binding.h"
+#include "bindings/core/v8/V8ThrowException.h"
#include "core/dom/DOMException.h"
#include <v8.h>
@@ -164,4 +167,58 @@ ScriptPromise ScriptPromise::rejectWithDOMException(ScriptState* scriptState, Pa
return reject(scriptState, V8ValueTraits<PassRefPtrWillBeRawPtr<DOMException> >::toV8Value(exception, scriptState->context()->Global(), scriptState->isolate()));
}
+ScriptPromise ScriptPromise::rejectWithTypeError(ScriptState* scriptState, const String& message)
+{
+ v8::Isolate* isolate = scriptState->isolate();
+ return reject(scriptState, V8ThrowException::createTypeError(message, isolate));
+}
+
+ScriptPromise ScriptPromise::rejectWithArityTypeErrorForMethod(ScriptState* scriptState, const char* method, const char* type, const char* valid, unsigned provided)
+{
+ String message = ExceptionMessages::failedToExecute(method, type, ExceptionMessages::invalidArity(valid, provided));
+ return rejectWithTypeError(scriptState, message);
+}
+
+ScriptPromise ScriptPromise::rejectWithArityTypeErrorForConstructor(ScriptState* scriptState, const char* type, const char* valid, unsigned provided)
+{
+ String message = ExceptionMessages::failedToConstruct(type, ExceptionMessages::invalidArity(valid, provided));
+ return rejectWithTypeError(scriptState, message);
+}
+
+ScriptPromise ScriptPromise::rejectWithArityTypeError(ScriptState* scriptState, ExceptionState& exceptionState, const char* valid, unsigned provided)
+{
+ exceptionState.throwTypeError(ExceptionMessages::invalidArity(valid, provided));
+ return exceptionState.reject(scriptState);
+}
+
+ScriptPromise ScriptPromise::rejectWithMinimumArityTypeErrorForMethod(
+ ScriptState* scriptState, const char* method, const char* type, unsigned expected, unsigned providedLeastNumMandatoryParams)
+{
+ String message = ExceptionMessages::failedToExecute(method, type, ExceptionMessages::notEnoughArguments(expected, providedLeastNumMandatoryParams));
+ return rejectWithTypeError(scriptState, message);
+}
+
+ScriptPromise ScriptPromise::rejectWithMinimumArityTypeErrorForConstructor(
+ ScriptState* scriptState, const char* type, unsigned expected, unsigned providedLeastNumMandatoryParams)
+{
+ String message = ExceptionMessages::failedToConstruct(type, ExceptionMessages::notEnoughArguments(expected, providedLeastNumMandatoryParams));
+ return rejectWithTypeError(scriptState, message);
+}
+
+ScriptPromise ScriptPromise::rejectWithMinimumArityTypeError(ScriptState* scriptState, ExceptionState& exceptionState, unsigned expected, unsigned providedLeastNumMandatoryParams)
+{
+ exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(expected, providedLeastNumMandatoryParams));
+ return exceptionState.reject(scriptState);
+}
+
+v8::Local<v8::Promise> ScriptPromise::rejectRaw(v8::Isolate* isolate, v8::Handle<v8::Value> value)
+{
+ if (value.IsEmpty())
+ return v8::Local<v8::Promise>();
+ v8::Local<v8::Promise::Resolver> resolver = v8::Promise::Resolver::New(isolate);
+ v8::Local<v8::Promise> promise = resolver->GetPromise();
+ resolver->Reject(value);
+ return promise;
+}
+
} // namespace blink
« no previous file with comments | « Source/bindings/core/v8/ScriptPromise.h ('k') | Source/bindings/core/v8/V8Binding.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698