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

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 360ad019ceee574ba199c140f4e325878288ffef..62c01142e84db90ac7f49e9b0555082a80fdb491 100644
--- a/Source/bindings/tests/results/V8TestObject.cpp
+++ b/Source/bindings/tests/results/V8TestObject.cpp
@@ -5681,8 +5681,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());
+ TONATIVE_VOID_EXCEPTIONSTATE_ASYNC(int, arg1, toInt32(info[0], exceptionState), exceptionState, info);
+ TONATIVE_VOID_ASYNC(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.reject().v8Value());
+ return;
+ }
+ TOSTRING_VOID_ASYNC(V8StringResource<>, arg3, info[2], info);
+ TONATIVE_VOID_ASYNC(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)
@@ -5692,6 +5706,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());
+ TONATIVE_VOID_ASYNC(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());
@@ -5810,8 +5846,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);
}
@@ -7490,8 +7528,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)
@@ -7506,8 +7546,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());
}
@@ -7524,14 +7566,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;
}
TONATIVE_VOID_EXCEPTIONSTATE(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)
@@ -7556,8 +7602,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)
@@ -7581,8 +7629,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)
@@ -7597,8 +7647,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());
}
@@ -7620,8 +7672,10 @@ static void callWithExecutionContextRaisesExceptionVoidMethodLongArgMethod(const
TONATIVE_VOID_EXCEPTIONSTATE(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)
@@ -8081,7 +8135,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