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}} |
Nils Barth (inactive)
2014/04/10 01:01:23
nit: Could you fix the spacing here: ' | '
sof
2014/04/10 06:16:40
Done.
| |
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' if constructor.is_named_con structor else '') %} | |
Nils Barth (inactive)
2014/04/10 01:53:26
Slick ;)
Could you add a linebreak here?
sof
2014/04/10 06:16:40
Added, but perhaps not in the right spot?
Nils Barth (inactive)
2014/04/10 07:34:06
It's fine; you don't actually need () for implicit
| |
410 v8::Handle<v8::Object> wrapper = info.Holder(); | |
411 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{constr uctor_class}}::wrapperTypeInfo, wrapper, isolate, {{wrapper_configuration}}); | |
412 {% endif %} | |
413 v8SetReturnValue(info, wrapper); | |
414 {% endmacro %} | |
415 | |
416 | |
417 {##############################################################################} | |
408 {% macro named_constructor_callback(constructor) %} | 418 {% macro named_constructor_callback(constructor) %} |
409 static void {{v8_class}}ConstructorCallback(const v8::FunctionCallbackInfo<v8::V alue>& info) | 419 static void {{v8_class}}ConstructorCallback(const v8::FunctionCallbackInfo<v8::V alue>& info) |
410 { | 420 { |
421 v8::Isolate* isolate = info.GetIsolate(); | |
411 if (!info.IsConstructCall()) { | 422 if (!info.IsConstructCall()) { |
412 throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("{{co nstructor.name}}"), info.GetIsolate()); | 423 throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("{{co nstructor.name}}"), isolate); |
413 return; | 424 return; |
414 } | 425 } |
415 | 426 |
416 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExis tingObject) { | 427 if (ConstructorMode::current(isolate) == ConstructorMode::WrapExistingObject ) { |
417 v8SetReturnValue(info, info.Holder()); | 428 v8SetReturnValue(info, info.Holder()); |
418 return; | 429 return; |
419 } | 430 } |
420 | 431 |
421 Document* document = currentDOMWindow(info.GetIsolate())->document(); | 432 Document* document = currentDOMWindow(isolate)->document(); |
422 ASSERT(document); | 433 ASSERT(document); |
423 | 434 |
424 // Make sure the document is added to the DOM Node map. Otherwise, the {{cpp _class}} instance | 435 // 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. | 436 // may end up being the only node in the map and get garbage-collected prema turely. |
426 toV8(document, info.Holder(), info.GetIsolate()); | 437 toV8(document, info.Holder(), isolate); |
427 | 438 |
428 {% if constructor.has_exception_state %} | 439 {% if constructor.has_exception_state %} |
429 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf ace_name}}", info.Holder(), info.GetIsolate()); | 440 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf ace_name}}", info.Holder(), isolate); |
430 {% endif %} | 441 {% endif %} |
431 {% if constructor.number_of_required_arguments %} | 442 {% if constructor.number_of_required_arguments %} |
432 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}})) { | 443 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}})) { |
433 {{throw_arity_type_error(constructor, constructor.number_of_required_arg uments)}}; | 444 {{throw_arity_type_error(constructor, constructor.number_of_required_arg uments)}}; |
434 return; | 445 return; |
435 } | 446 } |
436 {% endif %} | 447 {% endif %} |
437 {% for argument in constructor.arguments %} | 448 {% for argument in constructor.arguments %} |
438 {{generate_argument(constructor, argument) | indent}} | 449 {{generate_argument(constructor, argument) | indent}} |
439 {% endfor %} | 450 {% endfor %} |
440 RefPtr<{{cpp_class}}> impl = {{cpp_class}}::createForJSConstructor({{constru ctor.argument_list | join(', ')}}); | 451 {{ref_ptr}}<{{cpp_class}}> impl = {{cpp_class}}::createForJSConstructor({{co nstructor.argument_list | join(', ')}}); |
441 {% if is_constructor_raises_exception %} | 452 {% if is_constructor_raises_exception %} |
442 if (exceptionState.throwIfNeeded()) | 453 if (exceptionState.throwIfNeeded()) |
443 return; | 454 return; |
444 {% endif %} | 455 {% endif %} |
445 | 456 |
446 {% if has_custom_wrap %} | 457 {{generate_constructor_wrapper(constructor)| indent}} |
Nils Barth (inactive)
2014/04/10 01:01:23
...and here: ' | '
sof
2014/04/10 06:16:40
Done.
| |
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 } | 458 } |
454 {% endmacro %} | 459 {% endmacro %} |
OLD | NEW |