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

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

Issue 349523004: IDL: Generate all constructor callbacks with the same template macro (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fix arity check Created 6 years, 6 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/templates/methods.cpp
diff --git a/Source/bindings/templates/methods.cpp b/Source/bindings/templates/methods.cpp
index 598506269c938201bd0d63a2271c22b8b373d6da..ec4a33cc859a3a336c3b8093973fbb6e9a80acb3 100644
--- a/Source/bindings/templates/methods.cpp
+++ b/Source/bindings/templates/methods.cpp
@@ -482,17 +482,31 @@ static void {{method.name}}OriginSafeMethodGetterCallback{{world_suffix}}(v8::Lo
{##############################################################################}
{% macro generate_constructor(constructor) %}
-static void constructor{{constructor.overload_index}}(const v8::FunctionCallbackInfo<v8::Value>& info)
+{% set name = '%sConstructorCallback' % v8_class
+ if constructor.is_named_constructor else
+ 'constructor%s' % (constructor.overload_index or '') %}
+static void {{name}}(const v8::FunctionCallbackInfo<v8::Value>& info)
{
v8::Isolate* isolate = info.GetIsolate();
+ {% if constructor.is_named_constructor %}
+ if (!info.IsConstructCall()) {
+ throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("{{constructor.name}}"), isolate);
+ return;
+ }
+
+ if (ConstructorMode::current(isolate) == ConstructorMode::WrapExistingObject) {
+ v8SetReturnValue(info, info.Holder());
+ return;
+ }
+ {% endif %}
haraken 2014/06/25 09:43:11 This block is fine in this CL, but we might want t
Jens Widell 2014/06/25 10:55:37 Ah, I was wondering why these things applied only
{% if constructor.has_exception_state %}
ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interface_name}}", info.Holder(), isolate);
{% endif %}
{# Overloaded constructors have length checked during overload resolution #}
- {% if interface_length and not constructor.overload_index %}
+ {% if constructor.number_of_required_arguments and not constructor.overload_index %}
Jens Widell 2014/06/25 07:50:42 Using 'constructor.number_of_required_arguments' i
haraken 2014/06/25 09:43:11 What is the spec saying? interface.cpp is still u
Jens Widell 2014/06/25 10:55:37 The key here is that regular constructors (or cust
{# FIXME: remove UNLIKELY: constructors are expensive, so no difference. #}
- if (UNLIKELY(info.Length() < {{interface_length}})) {
- {{throw_minimum_arity_type_error(constructor, interface_length)}};
+ if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}})) {
+ {{throw_minimum_arity_type_error(constructor, constructor.number_of_required_arguments)}};
return;
}
{% endif %}
@@ -529,43 +543,3 @@ V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{constr
{% endif %}
v8SetReturnValue(info, wrapper);
{% endmacro %}
-
-
-{##############################################################################}
-{% macro named_constructor_callback(constructor) %}
-static void {{v8_class}}ConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
-{
- v8::Isolate* isolate = info.GetIsolate();
- if (!info.IsConstructCall()) {
- throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("{{constructor.name}}"), isolate);
- return;
- }
-
- if (ConstructorMode::current(isolate) == ConstructorMode::WrapExistingObject) {
- v8SetReturnValue(info, info.Holder());
- return;
- }
-
- Document& document = *toDocument(currentExecutionContext(isolate));
-
- {% if constructor.has_exception_state %}
- ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interface_name}}", info.Holder(), isolate);
- {% endif %}
- {% if constructor.number_of_required_arguments %}
- if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}})) {
- {{throw_minimum_arity_type_error(constructor, constructor.number_of_required_arguments)}};
- return;
- }
- {% endif %}
- {% if constructor.arguments %}
- {{generate_arguments(constructor) | indent}}
- {% endif %}
- {{constructor.cpp_type}} impl = {{constructor.cpp_value}};
- {% if is_constructor_raises_exception %}
- if (exceptionState.throwIfNeeded())
- return;
- {% endif %}
-
- {{generate_constructor_wrapper(constructor) | indent}}
-}
-{% endmacro %}
« no previous file with comments | « Source/bindings/templates/interface.cpp ('k') | Source/bindings/tests/results/V8TestInterfaceEventTarget.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698