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

Side by Side Diff: Source/bindings/templates/constructors.cpp

Issue 17572008: WIP IDL compiler rewrite (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: Branch: const + primitive type readonly attributes Created 7 years, 4 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 unified diff | Download patch
« no previous file with comments | « Source/bindings/templates/constants.cpp ('k') | Source/bindings/templates/interface.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 {% from 'macros.cpp' import deprecation_notification, feature_observation, param eters_check with context %}
2
3 {##############################################################################}
4 {% macro make_constructors() %}
5 {% if has_named_constructor %}
6 {% elif has_constructor %}
7 {% for constructor in constructors %}
8 {{normal_constructor(constructor)}}
9 {% endfor %}
10 {% elif is_constructor_template_of_event %}
11 {{constructor_template_of_event()}}
12 {% elif is_constructor_template_of_typed_array %}
13 {% endif %}
14 {% endmacro %}
15
16
17 {##############################################################################}
18 {% macro normal_constructor(constructor) %}
19 {# FIXME: check name #}
20 static void constructor{{constructor.overloaded_index_string}}(const v8::Functio nCallbackInfo<v8::Value>& args)
21 {
22 {% if constructor.overloaded_index == 0 and constructor.mandatory_parameters %}
23 if (args.Length() < {{constructor.mandatory_parameters}}) {
24 throwNotEnoughArgumentsError(args.GetIsolate());
25 return;
26 }
27 {% endif %}
28 {% if constructor_raises_exception %}
29 ExceptionState es(args.GetIsolate());
30 {% endif %}
31 {{parameters_check(constructor)}}
32 {% if constructor_call_with == 'ScriptExecutionContext' %}
33 ScriptExecutionContext* context = getScriptExecutionContext();
34 {% endif %}
35 RefPtr<{{cpp_class_name}}> impl = {{cpp_class_name}}::create({{constructor.a rgument_string}});
36 v8::Handle<v8::Object> wrapper = args.Holder();
37 {% if constructor_raises_exception %}
38 if (es.throwIfNeeded())
39 return;
40 {% endif %}
41
42 V8DOMWrapper::associateObjectWithWrapper<{{v8_class_name}}>(impl.release(), &{{v8_class_name}}::info, wrapper, args.GetIsolate(), WrapperConfiguration::Depe ndent);
43 args.GetReturnValue().Set(wrapper);
44 }
45 {% endmacro %}
46
47
48 {##############################################################################}
49 {% macro constructor_template_of_event() %}
50 {# FIXME: check name #}
51 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& args)
52 {
53 if (args.Length() < 1) {
54 throwNotEnoughArgumentsError(args.GetIsolate());
55 return;
56 }
57
58 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, args[0]);
59 {% for attribute in attributes %}
60 {% if attribute.type == 'any' %}
61 v8::Local<v8::Value> {{attribute.name}};
62 {% endif %}
63 {% endfor %}
64 {{cpp_class_name}}Init eventInit;
65 if (args.Length() >= 2) {
66 V8TRYCATCH_VOID(Dictionary, options, Dictionary(args[1], args.GetIsolate ()));
67 if (!fill{{cpp_class_name}}Init(eventInit, options))
68 return;
69 {% for attribute in attributes %}
70 {% if attribute.type == 'any' %}
71 options.get("{{attribute.name}}", {{attribute.name}});
72 if (!{{attribute.name}}.IsEmpty())
73 args.Holder()->SetHiddenValue(V8HiddenPropertyName::{{attribute.name }}(), {{attribute.name}});
74 {% endif %}
75 {% endfor %}
76 }
77
78 RefPtr<{{cpp_class_name}}> event = {{cpp_class_name}}::create(type, eventIni t);
79 {% if number_of_any_attributes %}
80 {# If we're in an isolated world, create a SerializedScriptValue and store it in the event for
81 # later cloning if the property is accessed from another world.
82 # The main world case is handled lazily (in Custom code). #}
83 if (isolatedWorldForIsolate(args.GetIsolate())) {
84 {% for attribute in attributes %}
85 {% if attribute.type == 'any' %}
86 if (!{{attribute.name}}.IsEmpty())
87 event->{{attribute.setter}}(SerializedScriptValue::createAndSwallowE xceptions({{attribute.name}}, args.GetIsolate()));
88 {% endif %}
89 {% endfor %}
90 }
91
92 {% endif %}
93 v8::Handle<v8::Object> wrapper = args.Holder();
94 V8DOMWrapper::associateObjectWithWrapper<{{v8_class_name}}>(event.release(), &{{v8_class_name}}::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dep endent);
95 v8SetReturnValue(args, wrapper);
96 }{% endmacro %}
97
98
99 {##############################################################################}
100 {% macro more_constructor_stuff() %}
101 {# FIXME: check name #}
102 {% if has_named_constructor %}
103 {## working #}
104 WrapperTypeInfo {{v8_class_name}}Constructor::info = { {{v8_class_name}}Construc tor::GetTemplate, {{v8_class_name}}::derefObject, {{to_active_dom_object}}, {{to _event_target}}, 0, {{v8_class_name}}::installPerContextPrototypeProperties, 0, WrapperTypeObjectPrototype };
105
106 static void {{v8_class_name}}ConstructorCallback(const v8::FunctionCallbackInfo< v8::Value>& args)
107 {
108 {{feature_observation(measure_as) -}}
109 {{deprecation_notification(deprecate_as)}} if (!args.IsConstructCall()) {
110 throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());
111 return;
112 }
113
114 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) {
115 args.GetReturnValue().Set(args.Holder());
116 return;
117 }
118
119 Document* document = currentDocument();
120
121 // Make sure the document is added to the DOM Node map. Otherwise, the {{cpp _class_name}} instance
122 // may end up being the only node in the map and get garbage-collected prema turely.
123 toV8(document, args.Holder(), args.GetIsolate());
124
125 {{parameters_check(named_constructor)}}
126 {% if constructor_raises_exception %}
127 ExceptionCode ec = 0;
128 {% endif %}
129 RefPtr<{{cpp_class_name}}> impl = {{cpp_class_name}}::createForJSConstructor ({{named_constructor.argument_string}});
130 v8::Handle<v8::Object> wrapper = args.Holder();
131 {% if constructor_raises_exception %}
132 if (ec) {
133 setDOMException(ec, args.GetIsolate());
134 return;
135 }
136 {% endif %}
137
138 V8DOMWrapper::associateObjectWithWrapper<{{v8_class_name}}>(impl.release(), &{{v8_class_name}}Constructor::info, wrapper, args.GetIsolate(), WrapperConfigur ation::Dependent);
139 args.GetReturnValue().Set(wrapper);
140 }
141
142 v8::Handle<v8::FunctionTemplate> {{v8_class_name}}Constructor::GetTemplate(v8::I solate* isolate, WrapperWorldType currentWorldType)
143 {
144 // This is only for getting a unique pointer which we can pass to privateTem plate.
145 static const char* privateTemplateUniqueKey = "{{v8_class_name}}Constructor: :GetTemplatePrivateTemplate";
146 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
147 v8::Handle<v8::FunctionTemplate> result = data->privateTemplateIfExists(curr entWorldType, &privateTemplateUniqueKey);
148 if (!result.IsEmpty())
149 return result;
150
151 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
152 v8::HandleScope scope(isolate);
153 result = v8::FunctionTemplate::New({{v8_class_name}}ConstructorCallback);
154
155 v8::Local<v8::ObjectTemplate> instance = result->InstanceTemplate();
156 instance->SetInternalFieldCount({{v8_class_name}}::internalFieldCount);
157 result->SetClassName(v8::String::NewSymbol("{{cpp_class_name}}"));
158 result->Inherit({{v8_class_name}}::GetTemplate(isolate, currentWorldType));
159 data->setPrivateTemplate(currentWorldType, &privateTemplateUniqueKey, result );
160
161 return scope.Close(result);
162 }
163
164 {% endif %}
165 {% endmacro %}
166
167
168 {##############################################################################}
169 {% macro constructor_callback() %}
170 void {{v8_class_name}}::constructorCallback(const v8::FunctionCallbackInfo<v8::V alue>& args)
171 {
172 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor");{{feature_obser vation(measure_as)}}{{deprecation_notification(deprecate_as)}}
173 if (!args.IsConstructCall()) {
174 throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());
175 return;
176 }
177
178 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) {
179 args.GetReturnValue().Set(args.Holder());
180 return;
181 }
182
183 {% if has_custom_constructor %}
184 {{v8_class_name}}::constructorCustom(args);
185 {% else %}
186 {{cpp_class_name}}V8Internal::constructor(args);
187 {% endif %}
188 }
189 {% endmacro %}
OLDNEW
« no previous file with comments | « Source/bindings/templates/constants.cpp ('k') | Source/bindings/templates/interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698