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

Unified Diff: Source/bindings/templates/interface.cpp

Issue 112303003: IDL compiler: [Constructor] overloading (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Better test case Created 7 years 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/templates/interface.cpp
diff --git a/Source/bindings/templates/interface.cpp b/Source/bindings/templates/interface.cpp
index d2e9e89405e412db4cac1d4811913fd84829cd9e..8906722b7e61ab69a20e830a811213b3eaa419f2 100644
--- a/Source/bindings/templates/interface.cpp
+++ b/Source/bindings/templates/interface.cpp
@@ -129,40 +129,28 @@ static void {{cpp_class}}OriginSafeMethodSetterCallback(v8::Local<v8::String> na
{##############################################################################}
-{% from 'methods.cpp' import generate_argument with context %}
-{% block constructor %}
-{% if has_constructor %}
-{# FIXME: support overloading #}
+{% block overloaded_constructor_callback %}
Nils Barth (inactive) 2013/12/13 07:04:16 Diff looks weird; just look at new code. This is
+{% if constructors|length > 1 %}
static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
{
- {% if constructor_arguments %}
- {# FIXME: remove this UNLIKELY: constructors are heavy, so no difference. #}
- if (UNLIKELY(info.Length() < {{interface_length}})) {
- throwTypeError(ExceptionMessages::failedToExecute("Constructor", "{{interface_name}}", ExceptionMessages::notEnoughArguments({{interface_length}}, info.Length())), info.GetIsolate());
+ {% for constructor in constructors %}
+ if ({{constructor.overload_resolution_expression}}) {
+ {{cpp_class}}V8Internal::constructor{{constructor.overload_index}}(info);
return;
}
- {% endif %}
- {% if is_constructor_raises_exception %}
- ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interface_name}}", info.Holder(), info.GetIsolate());
- {% endif %}
- {% for argument in constructor_arguments %}
- {{generate_argument(constructor_method, argument) | indent}}
{% endfor %}
- {% if is_constructor_call_with_execution_context %}
- ExecutionContext* context = getExecutionContext();
- {% endif %}
- {% if is_constructor_call_with_document %}
- Document& document = *toDocument(getExecutionContext());
- {% endif %}
- RefPtr<{{cpp_class}}> impl = {{cpp_class}}::create({{constructor_argument_list | join(', ')}});
- v8::Handle<v8::Object> wrapper = info.Holder();
- {% if is_constructor_raises_exception %}
- if (exceptionState.throwIfNeeded())
+ {% if interface_length %}
+ ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interface_name}}", info.Holder(), info.GetIsolate());
+ if (UNLIKELY(info.Length() < {{interface_length}})) {
+ exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{interface_length}}, info.Length()));
+ exceptionState.throwIfNeeded();
return;
+ }
+ exceptionState.throwTypeError("No matching constructor signature.");
+ exceptionState.throwIfNeeded();
+ {% else %}
+ throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", "No matching constructor signature."), info.GetIsolate());
{% endif %}
-
- V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8_class}}::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent);
- v8SetReturnValue(info, wrapper);
}
{% endif %}
@@ -337,7 +325,7 @@ bool initialize{{cpp_class}}({{cpp_class}}Init& eventInit, const Dictionary& opt
{##############################################################################}
{% block constructor_callback %}
-{% if has_constructor or has_event_constructor %}
+{% if constructors or has_event_constructor %}
void {{v8_class}}::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor");
@@ -399,7 +387,7 @@ static v8::Handle<v8::FunctionTemplate> Configure{{v8_class}}Template(v8::Handle
isolate, currentWorldType);
{% endfilter %}
- {% if has_constructor or has_event_constructor %}
+ {% if constructors or has_event_constructor %}
functionTemplate->SetCallHandler({{v8_class}}::constructorCallback);
functionTemplate->SetLength({{interface_length}});
{% endif %}

Powered by Google App Engine
This is Rietveld 408576698