Commit 4b69bb2f authored by jl@opera.com's avatar jl@opera.com

IDL: Support callback function types in overload resolution

The specification has a "if Callable(V) is true, ..." case for (among
other things) callback function types, which is implemented here, only
for callback function types.

BUG=293561

Review URL: https://codereview.chromium.org/715353002

git-svn-id: svn://svn.chromium.org/blink/trunk@185230 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 761c1560
......@@ -842,12 +842,33 @@ def resolution_tests_methods(effective_overloads):
test = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate())'.format(idl_type=idl_type.base_type, cpp_value=cpp_value)
yield test, method
# 8. Otherwise: if V is any kind of object except for a native Date object,
# 13. Otherwise: if IsCallable(V) is true, and there is an entry in S that
# has one of the following types at position i of its type list,
# • a callback function type
# ...
#
# FIXME:
# We test for functions rather than callability, which isn't strictly the
# same thing.
try:
method = next(method for idl_type, method in idl_types_methods
if idl_type.is_callback_function)
test = '%s->IsFunction()' % cpp_value
yield test, method
except StopIteration:
pass
# 14. Otherwise: if V is any kind of object except for a native Date object,
# a native RegExp object, and there is an entry in S that has one of the
# following types at position i of its type list,
# • an array type
# • a sequence type
# ...
#
# 15. Otherwise: if V is any kind of object except for a native Date object,
# a native RegExp object, and there is an entry in S that has one of the
# following types at position i of its type list,
# • an array type
# ...
# • a dictionary
#
# FIXME:
......
......@@ -448,6 +448,8 @@ interface TestObject {
void overloadedMethodI(double doubleArg);
void overloadedMethodJ(DOMString stringArg);
void overloadedMethodJ(TestDictionary testDictionaryArg);
void overloadedMethodK(Function functionArg);
void overloadedMethodK(DOMString stringArg);
Promise promiseOverloadMethod();
Promise promiseOverloadMethod(Window arg1, double arg2);
......
......@@ -8273,6 +8273,56 @@ static void overloadedMethodJMethodCallback(const v8::FunctionCallbackInfo<v8::V
TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
}
static void overloadedMethodK1Method(const v8::FunctionCallbackInfo<v8::Value>& info)
{
TestObject* impl = V8TestObject::toImpl(info.Holder());
ScriptValue functionArg;
{
functionArg = ScriptValue(ScriptState::current(info.GetIsolate()), info[0]);
}
impl->overloadedMethodK(functionArg);
}
static void overloadedMethodK2Method(const v8::FunctionCallbackInfo<v8::Value>& info)
{
TestObject* impl = V8TestObject::toImpl(info.Holder());
V8StringResource<> stringArg;
{
TOSTRING_VOID_INTERNAL(stringArg, info[0]);
}
impl->overloadedMethodK(stringArg);
}
static void overloadedMethodKMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
{
ExceptionState exceptionState(ExceptionState::ExecutionContext, "overloadedMethodK", "TestObject", info.Holder(), info.GetIsolate());
switch (std::min(1, info.Length())) {
case 1:
if (info[0]->IsFunction()) {
overloadedMethodK1Method(info);
return;
}
if (true) {
overloadedMethodK2Method(info);
return;
}
break;
default:
exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length()));
exceptionState.throwIfNeeded();
return;
}
exceptionState.throwTypeError("No function was found that matched the signature provided.");
exceptionState.throwIfNeeded();
}
static void overloadedMethodKMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod");
TestObjectV8Internal::overloadedMethodKMethod(info);
TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
}
static void promiseOverloadMethod1Method(const v8::FunctionCallbackInfo<v8::Value>& info)
{
TestObject* impl = V8TestObject::toImpl(info.Holder());
......@@ -10681,6 +10731,7 @@ static const V8DOMConfiguration::MethodConfiguration V8TestObjectMethods[] = {
{"overloadedMethodH", TestObjectV8Internal::overloadedMethodHMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts},
{"overloadedMethodI", TestObjectV8Internal::overloadedMethodIMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts},
{"overloadedMethodJ", TestObjectV8Internal::overloadedMethodJMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts},
{"overloadedMethodK", TestObjectV8Internal::overloadedMethodKMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts},
{"promiseOverloadMethod", TestObjectV8Internal::promiseOverloadMethodMethodCallback, 0, 0, V8DOMConfiguration::ExposedToAllScripts},
{"overloadedPerWorldBindingsMethod", TestObjectV8Internal::overloadedPerWorldBindingsMethodMethodCallback, TestObjectV8Internal::overloadedPerWorldBindingsMethodMethodCallbackForMainWorld, 0, V8DOMConfiguration::ExposedToAllScripts},
{"voidMethodClampUnsignedShortArg", TestObjectV8Internal::voidMethodClampUnsignedShortArgMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts},
......
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