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

Unified Diff: Source/bindings/tests/results/V8TestObject.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, 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/tests/results/V8TestObject.cpp
diff --git a/Source/bindings/tests/results/V8TestObject.cpp b/Source/bindings/tests/results/V8TestObject.cpp
index 4e8c53df3be663db2fbd8c9cdf6748abe161b5bf..f4e34cbe6df78d78fc13d57d2ed4832b7e51c84a 100644
--- a/Source/bindings/tests/results/V8TestObject.cpp
+++ b/Source/bindings/tests/results/V8TestObject.cpp
@@ -5537,8 +5537,22 @@ static void nodeFilterMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Va
static void promiseMethodMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
{
+ ExceptionState exceptionState(ExceptionState::ExecutionContext, "promiseMethod", "TestObject", info.Holder(), info.GetIsolate());
+ if (UNLIKELY(info.Length() < 3)) {
+ v8SetReturnValue(info, ScriptPromise::rejectWithArityTypeError(exceptionState, 3, info.Length()).v8Value());
+ return;
+ }
TestObject* impl = V8TestObject::toNative(info.Holder());
- v8SetReturnValue(info, impl->promiseMethod().v8Value());
+ V8TRYCATCH_EXCEPTION_VOID_PROMISE(int, arg1, toInt32(info[0], exceptionState), info, exceptionState);
+ V8TRYCATCH_VOID_PROMISE(Dictionary, arg2, Dictionary(info[1], info.GetIsolate()), info);
+ if (!arg2.isUndefinedOrNull() && !arg2.isObject()) {
+ exceptionState.throwTypeError("parameter 2 ('arg2') is not an object.");
+ v8SetReturnValue(info, exceptionState.rejectedPromise().v8Value());
+ return;
+ }
+ V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID_PROMISE(V8StringResource<>, arg3, info[2], info);
+ V8TRYCATCH_VOID_PROMISE(Vector<String>, variadic, toNativeArguments<String>(info, 3), info);
+ v8SetReturnValue(info, impl->promiseMethod(arg1, arg2, arg3, variadic).v8Value());
}
static void promiseMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
@@ -5548,6 +5562,28 @@ static void promiseMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value
TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
}
+static void promiseMethodWithoutExceptionStateMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
+{
+ if (UNLIKELY(info.Length() < 1)) {
+ v8SetReturnValue(info, ScriptPromise::rejectWithArityTypeErrorForMethod("promiseMethodWithoutExceptionState", "TestObject", 1, info.Length(), info.GetIsolate()).v8Value());
+ return;
+ }
+ TestObject* impl = V8TestObject::toNative(info.Holder());
+ V8TRYCATCH_VOID_PROMISE(Dictionary, arg1, Dictionary(info[0], info.GetIsolate()), info);
+ if (!arg1.isUndefinedOrNull() && !arg1.isObject()) {
+ v8SetReturnValue(info, ScriptPromise::rejectWithTypeError(ExceptionMessages::failedToExecute("promiseMethodWithoutExceptionState", "TestObject", "parameter 1 ('arg1') is not an object."), info.GetIsolate()).v8Value());
+ return;
+ }
+ v8SetReturnValue(info, impl->promiseMethodWithoutExceptionState(arg1).v8Value());
+}
+
+static void promiseMethodWithoutExceptionStateMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
+{
+ TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
+ TestObjectV8Internal::promiseMethodWithoutExceptionStateMethod(info);
+ TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
+}
+
static void serializedScriptValueMethodMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
{
TestObject* impl = V8TestObject::toNative(info.Holder());
@@ -5666,8 +5702,10 @@ static void voidMethodSerializedScriptValueArgMethod(const v8::FunctionCallbackI
}
TestObject* impl = V8TestObject::toNative(info.Holder());
RefPtr<SerializedScriptValue> serializedScriptValueArg = SerializedScriptValue::create(info[0], 0, 0, exceptionState, info.GetIsolate());
- if (exceptionState.throwIfNeeded())
+ if (exceptionState.hadException()) {
+ exceptionState.throwIfNeeded();
return;
+ }
impl->voidMethodSerializedScriptValueArg(serializedScriptValueArg);
}
@@ -7325,8 +7363,10 @@ static void raisesExceptionVoidMethodMethod(const v8::FunctionCallbackInfo<v8::V
ExceptionState exceptionState(ExceptionState::ExecutionContext, "raisesExceptionVoidMethod", "TestObject", info.Holder(), info.GetIsolate());
TestObject* impl = V8TestObject::toNative(info.Holder());
impl->raisesExceptionVoidMethod(exceptionState);
- if (exceptionState.throwIfNeeded())
+ if (exceptionState.hadException()) {
+ exceptionState.throwIfNeeded();
return;
+ }
}
static void raisesExceptionVoidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
@@ -7341,8 +7381,10 @@ static void raisesExceptionStringMethodMethod(const v8::FunctionCallbackInfo<v8:
ExceptionState exceptionState(ExceptionState::ExecutionContext, "raisesExceptionStringMethod", "TestObject", info.Holder(), info.GetIsolate());
TestObject* impl = V8TestObject::toNative(info.Holder());
String result = impl->raisesExceptionStringMethod(exceptionState);
- if (exceptionState.throwIfNeeded())
+ if (exceptionState.hadException()) {
+ exceptionState.throwIfNeeded();
return;
+ }
v8SetReturnValueString(info, result, info.GetIsolate());
}
@@ -7359,14 +7401,18 @@ static void raisesExceptionVoidMethodOptionalLongArgMethod(const v8::FunctionCal
TestObject* impl = V8TestObject::toNative(info.Holder());
if (UNLIKELY(info.Length() <= 0)) {
impl->raisesExceptionVoidMethodOptionalLongArg(exceptionState);
- if (exceptionState.throwIfNeeded())
+ if (exceptionState.hadException()) {
+ exceptionState.throwIfNeeded();
return;
+ }
return;
}
V8TRYCATCH_EXCEPTION_VOID(int, optionalLongArg, toInt32(info[0], exceptionState), exceptionState);
impl->raisesExceptionVoidMethodOptionalLongArg(optionalLongArg, exceptionState);
- if (exceptionState.throwIfNeeded())
+ if (exceptionState.hadException()) {
+ exceptionState.throwIfNeeded();
return;
+ }
}
static void raisesExceptionVoidMethodOptionalLongArgMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
@@ -7391,8 +7437,10 @@ static void raisesExceptionVoidMethodTestCallbackInterfaceArgMethod(const v8::Fu
}
OwnPtr<TestCallbackInterface> testCallbackInterfaceArg = V8TestCallbackInterface::create(v8::Handle<v8::Function>::Cast(info[0]), currentExecutionContext(info.GetIsolate()));
impl->raisesExceptionVoidMethodTestCallbackInterfaceArg(testCallbackInterfaceArg.release(), exceptionState);
- if (exceptionState.throwIfNeeded())
+ if (exceptionState.hadException()) {
+ exceptionState.throwIfNeeded();
return;
+ }
}
static void raisesExceptionVoidMethodTestCallbackInterfaceArgMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
@@ -7416,8 +7464,10 @@ static void raisesExceptionVoidMethodOptionalTestCallbackInterfaceArgMethod(cons
optionalTestCallbackInterfaceArg = V8TestCallbackInterface::create(v8::Handle<v8::Function>::Cast(info[0]), currentExecutionContext(info.GetIsolate()));
}
impl->raisesExceptionVoidMethodOptionalTestCallbackInterfaceArg(optionalTestCallbackInterfaceArg.release(), exceptionState);
- if (exceptionState.throwIfNeeded())
+ if (exceptionState.hadException()) {
+ exceptionState.throwIfNeeded();
return;
+ }
}
static void raisesExceptionVoidMethodOptionalTestCallbackInterfaceArgMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
@@ -7432,8 +7482,10 @@ static void raisesExceptionTestInterfaceEmptyVoidMethodMethod(const v8::Function
ExceptionState exceptionState(ExceptionState::ExecutionContext, "raisesExceptionTestInterfaceEmptyVoidMethod", "TestObject", info.Holder(), info.GetIsolate());
TestObject* impl = V8TestObject::toNative(info.Holder());
RefPtr<TestInterfaceEmpty> result = impl->raisesExceptionTestInterfaceEmptyVoidMethod(exceptionState);
- if (exceptionState.throwIfNeeded())
+ if (exceptionState.hadException()) {
+ exceptionState.throwIfNeeded();
return;
+ }
v8SetReturnValue(info, result.release());
}
@@ -7455,8 +7507,10 @@ static void callWithExecutionContextRaisesExceptionVoidMethodLongArgMethod(const
V8TRYCATCH_EXCEPTION_VOID(int, longArg, toInt32(info[0], exceptionState), exceptionState);
ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate());
impl->callWithExecutionContextRaisesExceptionVoidMethodLongArg(scriptContext, longArg, exceptionState);
- if (exceptionState.throwIfNeeded())
+ if (exceptionState.hadException()) {
+ exceptionState.throwIfNeeded();
return;
+ }
}
static void callWithExecutionContextRaisesExceptionVoidMethodLongArgMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
@@ -7876,7 +7930,8 @@ static const V8DOMConfiguration::MethodConfiguration V8TestObjectMethods[] = {
{"voidMethodTestEnumArg", TestObjectV8Internal::voidMethodTestEnumArgMethodCallback, 0, 1},
{"dictionaryMethod", TestObjectV8Internal::dictionaryMethodMethodCallback, 0, 0},
{"nodeFilterMethod", TestObjectV8Internal::nodeFilterMethodMethodCallback, 0, 0},
- {"promiseMethod", TestObjectV8Internal::promiseMethodMethodCallback, 0, 0},
+ {"promiseMethod", TestObjectV8Internal::promiseMethodMethodCallback, 0, 4},
+ {"promiseMethodWithoutExceptionState", TestObjectV8Internal::promiseMethodWithoutExceptionStateMethodCallback, 0, 1},
{"serializedScriptValueMethod", TestObjectV8Internal::serializedScriptValueMethodMethodCallback, 0, 0},
{"xPathNSResolverMethod", TestObjectV8Internal::xPathNSResolverMethodMethodCallback, 0, 0},
{"voidMethodDictionaryArg", TestObjectV8Internal::voidMethodDictionaryArgMethodCallback, 0, 1},

Powered by Google App Engine
This is Rietveld 408576698