Commit d8a924a2 authored by bashi's avatar bashi Committed by Commit bot

IDL: Support callback interface in overload resolution

Per the spec[1] we can treat an object as a callback interface
if an effective overload set contains the callback interface.

[1] http://heycam.github.io/webidl/#es-overloads

BUG=629068

Review-Url: https://codereview.chromium.org/2175463002
Cr-Commit-Position: refs/heads/master@{#407077}
parent 1ebd26d0
...@@ -1107,9 +1107,9 @@ def resolution_tests_methods(effective_overloads): ...@@ -1107,9 +1107,9 @@ def resolution_tests_methods(effective_overloads):
# Array in overloaded method: http://crbug.com/262383 # Array in overloaded method: http://crbug.com/262383
yield '%s->IsArray()' % cpp_value, method yield '%s->IsArray()' % cpp_value, method
for idl_type, method in idl_types_methods: for idl_type, method in idl_types_methods:
if idl_type.is_dictionary or idl_type.name == 'Dictionary': if idl_type.is_dictionary or idl_type.name == 'Dictionary' or idl_type.is_callback_interface:
# FIXME: should be '{1}->IsObject() && !{1}->IsDate() && !{1}->IsRegExp()'.format(cpp_value) # FIXME: should be '{1}->IsObject() && !{1}->IsRegExp()'.format(cpp_value)
# FIXME: the IsDate and IsRegExp checks can be skipped if we've # FIXME: the IsRegExp checks can be skipped if we've
# already generated tests for them. # already generated tests for them.
yield '%s->IsObject()' % cpp_value, method yield '%s->IsObject()' % cpp_value, method
......
...@@ -475,6 +475,8 @@ interface TestObject { ...@@ -475,6 +475,8 @@ interface TestObject {
void overloadedMethodK(DOMString stringArg); void overloadedMethodK(DOMString stringArg);
void overloadedMethodL(long longArg, any... restArgs); void overloadedMethodL(long longArg, any... restArgs);
void overloadedMethodL(DOMString stringArg, any... restArgs); void overloadedMethodL(DOMString stringArg, any... restArgs);
void overloadedMethodN(TestInterface testInterfaceArg);
void overloadedMethodN(TestCallbackInterface testCallbackInterfaceArg);
Promise promiseOverloadMethod(); Promise promiseOverloadMethod();
Promise promiseOverloadMethod(Window arg1, double arg2); Promise promiseOverloadMethod(Window arg1, double arg2);
......
...@@ -8600,6 +8600,66 @@ static void overloadedMethodLMethodCallback(const v8::FunctionCallbackInfo<v8::V ...@@ -8600,6 +8600,66 @@ static void overloadedMethodLMethodCallback(const v8::FunctionCallbackInfo<v8::V
TestObjectV8Internal::overloadedMethodLMethod(info); TestObjectV8Internal::overloadedMethodLMethod(info);
} }
static void overloadedMethodN1Method(const v8::FunctionCallbackInfo<v8::Value>& info)
{
TestObject* impl = V8TestObject::toImpl(info.Holder());
TestInterfaceImplementation* testInterfaceArg;
{
testInterfaceArg = V8TestInterface::toImplWithTypeCheck(info.GetIsolate(), info[0]);
if (!testInterfaceArg) {
V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToExecute("overloadedMethodN", "TestObject", "parameter 1 is not of type 'TestInterface'."));
return;
}
}
impl->overloadedMethodN(testInterfaceArg);
}
static void overloadedMethodN2Method(const v8::FunctionCallbackInfo<v8::Value>& info)
{
TestObject* impl = V8TestObject::toImpl(info.Holder());
TestCallbackInterface* testCallbackInterfaceArg;
{
if (info.Length() <= 0 || !info[0]->IsFunction()) {
V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToExecute("overloadedMethodN", "TestObject", "The callback provided as parameter 1 is not a function."));
return;
}
testCallbackInterfaceArg = V8TestCallbackInterface::create(v8::Local<v8::Function>::Cast(info[0]), ScriptState::current(info.GetIsolate()));
}
impl->overloadedMethodN(testCallbackInterfaceArg);
}
static void overloadedMethodNMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
{
ExceptionState exceptionState(ExceptionState::ExecutionContext, "overloadedMethodN", "TestObject", info.Holder(), info.GetIsolate());
switch (std::min(1, info.Length())) {
case 1:
if (V8TestInterface::hasInstance(info[0], info.GetIsolate())) {
overloadedMethodN1Method(info);
return;
}
if (info[0]->IsObject()) {
overloadedMethodN2Method(info);
return;
}
break;
default:
break;
}
if (info.Length() < 1) {
exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length()));
exceptionState.throwIfNeeded();
return;
}
exceptionState.throwTypeError("No function was found that matched the signature provided.");
exceptionState.throwIfNeeded();
return;
}
static void overloadedMethodNMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
TestObjectV8Internal::overloadedMethodNMethod(info);
}
static void promiseOverloadMethod1Method(const v8::FunctionCallbackInfo<v8::Value>& info) static void promiseOverloadMethod1Method(const v8::FunctionCallbackInfo<v8::Value>& info)
{ {
TestObject* impl = V8TestObject::toImpl(info.Holder()); TestObject* impl = V8TestObject::toImpl(info.Holder());
...@@ -11521,6 +11581,7 @@ const V8DOMConfiguration::MethodConfiguration V8TestObjectMethods[] = { ...@@ -11521,6 +11581,7 @@ const V8DOMConfiguration::MethodConfiguration V8TestObjectMethods[] = {
{"overloadedMethodJ", TestObjectV8Internal::overloadedMethodJMethodCallback, 0, 1, v8::None, V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnPrototype}, {"overloadedMethodJ", TestObjectV8Internal::overloadedMethodJMethodCallback, 0, 1, v8::None, V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnPrototype},
{"overloadedMethodK", TestObjectV8Internal::overloadedMethodKMethodCallback, 0, 1, v8::None, V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnPrototype}, {"overloadedMethodK", TestObjectV8Internal::overloadedMethodKMethodCallback, 0, 1, v8::None, V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnPrototype},
{"overloadedMethodL", TestObjectV8Internal::overloadedMethodLMethodCallback, 0, 1, v8::None, V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnPrototype}, {"overloadedMethodL", TestObjectV8Internal::overloadedMethodLMethodCallback, 0, 1, v8::None, V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnPrototype},
{"overloadedMethodN", TestObjectV8Internal::overloadedMethodNMethodCallback, 0, 1, v8::None, V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnPrototype},
{"promiseOverloadMethod", TestObjectV8Internal::promiseOverloadMethodMethodCallback, 0, 0, v8::None, V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnPrototype}, {"promiseOverloadMethod", TestObjectV8Internal::promiseOverloadMethodMethodCallback, 0, 0, v8::None, V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnPrototype},
{"overloadedPerWorldBindingsMethod", TestObjectV8Internal::overloadedPerWorldBindingsMethodMethodCallback, TestObjectV8Internal::overloadedPerWorldBindingsMethodMethodCallbackForMainWorld, 0, v8::None, V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnPrototype}, {"overloadedPerWorldBindingsMethod", TestObjectV8Internal::overloadedPerWorldBindingsMethodMethodCallback, TestObjectV8Internal::overloadedPerWorldBindingsMethodMethodCallbackForMainWorld, 0, v8::None, V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnPrototype},
{"overloadedStaticMethod", TestObjectV8Internal::overloadedStaticMethodMethodCallback, 0, 1, v8::None, V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInterface}, {"overloadedStaticMethod", TestObjectV8Internal::overloadedStaticMethodMethodCallback, 0, 1, v8::None, V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInterface},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment