OLD | NEW |
1 {##############################################################################} | 1 {##############################################################################} |
2 {% macro generate_method(method, world_suffix) %} | 2 {% macro generate_method(method, world_suffix) %} |
3 {% filter conditional(method.conditional_string) %} | 3 {% filter conditional(method.conditional_string) %} |
4 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const
v8::FunctionCallbackInfo<v8::Value>& info) | 4 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const
v8::FunctionCallbackInfo<v8::Value>& info) |
5 { | 5 { |
6 {# Local variables #} | 6 {# Local variables #} |
7 {% if method.has_exception_state %} | 7 {% if method.has_exception_state %} |
8 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na
me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 8 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na
me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); |
9 {% endif %} | 9 {% endif %} |
10 {% if method.number_of_required_arguments %} | 10 {% if method.number_of_required_arguments %} |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 {% endif %} | 193 {% endif %} |
194 {% if method.is_call_with_execution_context %} | 194 {% if method.is_call_with_execution_context %} |
195 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()); | 195 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()); |
196 {% endif %} | 196 {% endif %} |
197 {% if method.is_call_with_script_arguments %} | 197 {% if method.is_call_with_script_arguments %} |
198 RefPtr<ScriptArguments> scriptArguments(createScriptArguments(info, {{method.num
ber_of_arguments}})); | 198 RefPtr<ScriptArguments> scriptArguments(createScriptArguments(info, {{method.num
ber_of_arguments}})); |
199 {% endif %} | 199 {% endif %} |
200 {# Call #} | 200 {# Call #} |
201 {% if method.idl_type == 'void' %} | 201 {% if method.idl_type == 'void' %} |
202 {{cpp_value}}; | 202 {{cpp_value}}; |
| 203 {% elif method.is_constructor %} |
| 204 {{ref_ptr}}<{{cpp_class}}> impl = {{cpp_value}}; |
203 {% elif method.is_call_with_script_state or method.is_call_with_new_script_state
or method.is_raises_exception %} | 205 {% elif method.is_call_with_script_state or method.is_call_with_new_script_state
or method.is_raises_exception %} |
204 {# FIXME: consider always using a local variable #} | 206 {# FIXME: consider always using a local variable #} |
205 {{method.cpp_type}} result = {{cpp_value}}; | 207 {{method.cpp_type}} result = {{cpp_value}}; |
206 {% endif %} | 208 {% endif %} |
207 {# Post-call #} | 209 {# Post-call #} |
208 {% if method.is_raises_exception %} | 210 {% if method.is_raises_exception %} |
209 if (exceptionState.throwIfNeeded()) | 211 if (exceptionState.throwIfNeeded()) |
210 return; | 212 return; |
211 {% endif %} | 213 {% endif %} |
212 {# Set return value #} | 214 {# Set return value #} |
213 {% if method.union_arguments %} | 215 {% if method.is_constructor %} |
| 216 {{generate_constructor_wrapper(method)}}{% elif method.union_arguments %} |
214 {{union_type_method_call_and_set_return_value(method)}} | 217 {{union_type_method_call_and_set_return_value(method)}} |
215 {% elif v8_set_return_value %}{{v8_set_return_value}};{% endif %}{# None for voi
d #} | 218 {% elif v8_set_return_value %}{{v8_set_return_value}};{% endif %}{# None for voi
d #} |
216 {% endmacro %} | 219 {% endmacro %} |
217 | 220 |
218 | 221 |
219 {######################################} | 222 {######################################} |
220 {% macro union_type_method_call_and_set_return_value(method) %} | 223 {% macro union_type_method_call_and_set_return_value(method) %} |
221 {% for cpp_type in method.cpp_type %} | 224 {% for cpp_type in method.cpp_type %} |
222 bool result{{loop.index0}}Enabled = false; | 225 bool result{{loop.index0}}Enabled = false; |
223 {{cpp_type}} result{{loop.index0}}; | 226 {{cpp_type}} result{{loop.index0}}; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 {% endif %} | 389 {% endif %} |
387 {% if is_constructor_call_with_document %} | 390 {% if is_constructor_call_with_document %} |
388 Document& document = *toDocument(currentExecutionContext(isolate)); | 391 Document& document = *toDocument(currentExecutionContext(isolate)); |
389 {% endif %} | 392 {% endif %} |
390 {{ref_ptr}}<{{cpp_class}}> impl = {{cpp_class}}::create({{constructor.argume
nt_list | join(', ')}}); | 393 {{ref_ptr}}<{{cpp_class}}> impl = {{cpp_class}}::create({{constructor.argume
nt_list | join(', ')}}); |
391 {% if is_constructor_raises_exception %} | 394 {% if is_constructor_raises_exception %} |
392 if (exceptionState.throwIfNeeded()) | 395 if (exceptionState.throwIfNeeded()) |
393 return; | 396 return; |
394 {% endif %} | 397 {% endif %} |
395 | 398 |
396 {% if has_custom_wrap %} | 399 {{generate_constructor_wrapper(constructor) | indent}} |
397 v8::Handle<v8::Object> wrapper = wrap(impl.get(), info.Holder(), isolate); | |
398 {% else %} | |
399 v8::Handle<v8::Object> wrapper = info.Holder(); | |
400 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8
_class}}::wrapperTypeInfo, wrapper, isolate, {{wrapper_configuration}}); | |
401 {% endif %} | |
402 v8SetReturnValue(info, wrapper); | |
403 } | 400 } |
404 {% endmacro %} | 401 {% endmacro %} |
405 | 402 |
406 | 403 |
407 {##############################################################################} | 404 {##############################################################################} |
| 405 {% macro generate_constructor_wrapper(constructor) %} |
| 406 {% if has_custom_wrap %} |
| 407 v8::Handle<v8::Object> wrapper = wrap(impl.get(), info.Holder(), isolate); |
| 408 {% else %} |
| 409 {% set constructor_class = v8_class + ('Constructor' |
| 410 if constructor.is_named_constructor else |
| 411 '') %} |
| 412 v8::Handle<v8::Object> wrapper = info.Holder(); |
| 413 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{constr
uctor_class}}::wrapperTypeInfo, wrapper, isolate, {{wrapper_configuration}}); |
| 414 {% endif %} |
| 415 v8SetReturnValue(info, wrapper); |
| 416 {% endmacro %} |
| 417 |
| 418 |
| 419 {##############################################################################} |
408 {% macro named_constructor_callback(constructor) %} | 420 {% macro named_constructor_callback(constructor) %} |
409 static void {{v8_class}}ConstructorCallback(const v8::FunctionCallbackInfo<v8::V
alue>& info) | 421 static void {{v8_class}}ConstructorCallback(const v8::FunctionCallbackInfo<v8::V
alue>& info) |
410 { | 422 { |
| 423 v8::Isolate* isolate = info.GetIsolate(); |
411 if (!info.IsConstructCall()) { | 424 if (!info.IsConstructCall()) { |
412 throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("{{co
nstructor.name}}"), info.GetIsolate()); | 425 throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("{{co
nstructor.name}}"), isolate); |
413 return; | 426 return; |
414 } | 427 } |
415 | 428 |
416 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExis
tingObject) { | 429 if (ConstructorMode::current(isolate) == ConstructorMode::WrapExistingObject
) { |
417 v8SetReturnValue(info, info.Holder()); | 430 v8SetReturnValue(info, info.Holder()); |
418 return; | 431 return; |
419 } | 432 } |
420 | 433 |
421 Document* document = currentDOMWindow(info.GetIsolate())->document(); | 434 Document* document = currentDOMWindow(isolate)->document(); |
422 ASSERT(document); | 435 ASSERT(document); |
423 | 436 |
424 // Make sure the document is added to the DOM Node map. Otherwise, the {{cpp
_class}} instance | 437 // Make sure the document is added to the DOM Node map. Otherwise, the {{cpp
_class}} instance |
425 // may end up being the only node in the map and get garbage-collected prema
turely. | 438 // may end up being the only node in the map and get garbage-collected prema
turely. |
426 toV8(document, info.Holder(), info.GetIsolate()); | 439 toV8(document, info.Holder(), isolate); |
427 | 440 |
428 {% if constructor.has_exception_state %} | 441 {% if constructor.has_exception_state %} |
429 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf
ace_name}}", info.Holder(), info.GetIsolate()); | 442 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf
ace_name}}", info.Holder(), isolate); |
430 {% endif %} | 443 {% endif %} |
431 {% if constructor.number_of_required_arguments %} | 444 {% if constructor.number_of_required_arguments %} |
432 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}}))
{ | 445 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}}))
{ |
433 {{throw_arity_type_error(constructor, constructor.number_of_required_arg
uments)}}; | 446 {{throw_arity_type_error(constructor, constructor.number_of_required_arg
uments)}}; |
434 return; | 447 return; |
435 } | 448 } |
436 {% endif %} | 449 {% endif %} |
437 {% for argument in constructor.arguments %} | 450 {% for argument in constructor.arguments %} |
438 {{generate_argument(constructor, argument) | indent}} | 451 {{generate_argument(constructor, argument) | indent}} |
439 {% endfor %} | 452 {% endfor %} |
440 RefPtr<{{cpp_class}}> impl = {{cpp_class}}::createForJSConstructor({{constru
ctor.argument_list | join(', ')}}); | 453 {{ref_ptr}}<{{cpp_class}}> impl = {{cpp_class}}::createForJSConstructor({{co
nstructor.argument_list | join(', ')}}); |
441 {% if is_constructor_raises_exception %} | 454 {% if is_constructor_raises_exception %} |
442 if (exceptionState.throwIfNeeded()) | 455 if (exceptionState.throwIfNeeded()) |
443 return; | 456 return; |
444 {% endif %} | 457 {% endif %} |
445 | 458 |
446 {% if has_custom_wrap %} | 459 {{generate_constructor_wrapper(constructor) | indent}} |
447 v8::Handle<v8::Object> wrapper = wrap(impl.get(), info.Holder(), info.GetIso
late()); | |
448 {% else %} | |
449 v8::Handle<v8::Object> wrapper = info.Holder(); | |
450 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8
_class}}Constructor::wrapperTypeInfo, wrapper, info.GetIsolate(), {{wrapper_conf
iguration}}); | |
451 {% endif %} | |
452 v8SetReturnValue(info, wrapper); | |
453 } | 460 } |
454 {% endmacro %} | 461 {% endmacro %} |
OLD | NEW |