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

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

Issue 116153002: IDL compiler: [NamedConstructor] (basic) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Revised 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/methods.cpp
diff --git a/Source/bindings/templates/methods.cpp b/Source/bindings/templates/methods.cpp
index 373ef448bb56654d2512d6ba4cfcae65e818a8ca..f534272324cdea3d0ee9da72145045056d630ccf 100644
--- a/Source/bindings/templates/methods.cpp
+++ b/Source/bindings/templates/methods.cpp
@@ -292,7 +292,7 @@ static void {{method.name}}OriginSafeMethodGetterCallback{{world_suffix}}(v8::Lo
{##############################################################################}
-{% macro constructor_callback(constructor) %}
+{% macro generate_constructor(constructor) %}
static void constructor{{constructor.overload_index}}(const v8::FunctionCallbackInfo<v8::Value>& info)
{
{% if interface_length and not constructor.overload_index %}
@@ -329,3 +329,35 @@ static void constructor{{constructor.overload_index}}(const v8::FunctionCallback
v8SetReturnValue(info, wrapper);
}
{% endmacro %}
+
+
+{##############################################################################}
+{% macro named_constructor_callback(constructor) %}
+static void {{v8_class}}ConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
+{
+ if (!info.IsConstructCall()) {
+ throwTypeError(ExceptionMessages::failedToConstruct("{{constructor.name}}", "Please use the 'new' operator, this DOM object constructor cannot be called as a function."), info.GetIsolate());
+ return;
+ }
+
+ if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) {
+ v8SetReturnValue(info, info.Holder());
+ return;
+ }
+
+ Document* document = currentDocument();
+ ASSERT(document);
+
+ // Make sure the document is added to the DOM Node map. Otherwise, the {{cpp_class}} instance
+ // may end up being the only node in the map and get garbage-collected prematurely.
+ toV8(document, info.Holder(), info.GetIsolate());
+
+ {# FIXME: arguments #}
+ {% set argument_list = ['*document'] %}
+ RefPtr<{{cpp_class}}> impl = {{cpp_class}}::createForJSConstructor({{argument_list | join(', ')}});
+ v8::Handle<v8::Object> wrapper = info.Holder();
+
+ V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8_class}}Constructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent);
+ v8SetReturnValue(info, wrapper);
+}
+{% endmacro %}
« no previous file with comments | « Source/bindings/templates/interface_base.cpp ('k') | Source/bindings/tests/idls/TestInterfaceNamedConstructor.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698