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

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

Issue 100473006: IDL compiler: [Constructor] w/o arguments (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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 a25df2f939223d0975221785fe17997212bcefac..bc5cd0f04680e093d9b308b3ffcd848665196997 100644
--- a/Source/bindings/templates/interface.cpp
+++ b/Source/bindings/templates/interface.cpp
@@ -129,6 +129,46 @@ static void {{cpp_class}}OriginSafeMethodSetterCallback(v8::Local<v8::String> na
{##############################################################################}
+{% block constructor %}
+{% if has_constructor %}
+{# FIXME: support overloading #}
+static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
+{
+ {# FIXME: support arguments #}
+ RefPtr<{{cpp_class}}> impl = {{cpp_class}}::create();
+ v8::Handle<v8::Object> wrapper = info.Holder();
+
+ V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8_class}}::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent);
+ info.GetReturnValue().Set(wrapper);
haraken 2013/12/05 05:54:16 Can you use v8SetReturnValue()?
Nils Barth (inactive) 2013/12/05 06:09:20 I'll try in a followup!
+}
+
+{% endif %}
+{% endblock %}
+
+
+{##############################################################################}
+{% block constructor_callback %}
+{% if has_constructor %}
+void {{v8_class}}::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
+{
+ TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor");
+ if (!info.IsConstructCall()) {
+ throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", "Please use the 'new' operator, this DOM object constructor cannot be called as a function."), info.GetIsolate());
+ return;
+ }
+
+ if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) {
+ info.GetReturnValue().Set(info.Holder());
haraken 2013/12/05 05:54:16 Ditto.
+ return;
+ }
+
+ {{cpp_class}}V8Internal::constructor(info);
+}
+
+{% endif %}
+{% endblock %}
+
+{##############################################################################}
{% block visit_dom_wrapper %}
{% if generate_visit_dom_wrapper_function %}
void {{v8_class}}::visitDOMWrapper(void* object, const v8::Persistent<v8::Object>& wrapper, v8::Isolate* isolate)
@@ -232,6 +272,11 @@ static v8::Handle<v8::FunctionTemplate> Configure{{v8_class}}Template(v8::Handle
{% endfilter %}
UNUSED_PARAM(defaultSignature);
+ {% if has_constructor %}
+ functionTemplate->SetCallHandler({{v8_class}}::constructorCallback);
+ {# FIXME: compute length #}
+ functionTemplate->SetLength(0);
+ {% endif %}
v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceTemplate();
v8::Local<v8::ObjectTemplate> prototypeTemplate = functionTemplate->PrototypeTemplate();
UNUSED_PARAM(instanceTemplate);

Powered by Google App Engine
This is Rietveld 408576698