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 {# Overloaded methods have length checked during overload resolution #} | 10 {# Overloaded methods have length checked during overload resolution #} |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 '"The callback provided as parameter %s is not a function."' % | 159 '"The callback provided as parameter %s is not a function."' % |
160 (argument.index + 1)) | indent }} | 160 (argument.index + 1)) | indent }} |
161 return; | 161 return; |
162 } | 162 } |
163 {{argument.name}} = {% if argument.is_nullable %}info[{{argument.index}}]->IsNul l() ? nullptr : {% endif %}V8{{argument.idl_type}}::create(v8::Handle<v8::Functi on>::Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate())); | 163 {{argument.name}} = {% if argument.is_nullable %}info[{{argument.index}}]->IsNul l() ? nullptr : {% endif %}V8{{argument.idl_type}}::create(v8::Handle<v8::Functi on>::Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate())); |
164 {% endif %}{# argument.is_optional #} | 164 {% endif %}{# argument.is_optional #} |
165 {% endif %}{# argument.idl_type == 'EventListener' #} | 165 {% endif %}{# argument.idl_type == 'EventListener' #} |
166 {% elif argument.is_clamp %}{# argument.is_callback_interface #} | 166 {% elif argument.is_clamp %}{# argument.is_callback_interface #} |
167 {# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #} | 167 {# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #} |
168 double {{argument.name}}NativeValue; | 168 double {{argument.name}}NativeValue; |
169 {% if method.idl_type == 'Promise' %} | |
170 TONATIVE_VOID_ASYNC_INTERNAL({{argument.name}}NativeValue, info[{{argument.index }}]->NumberValue(), info); | |
171 {% else %} | |
169 TONATIVE_VOID_INTERNAL({{argument.name}}NativeValue, info[{{argument.index}}]->N umberValue()); | 172 TONATIVE_VOID_INTERNAL({{argument.name}}NativeValue, info[{{argument.index}}]->N umberValue()); |
173 {% endif %} | |
170 if (!std::isnan({{argument.name}}NativeValue)) | 174 if (!std::isnan({{argument.name}}NativeValue)) |
171 {# IDL type is used for clamping, for the right bounds, since different | 175 {# IDL type is used for clamping, for the right bounds, since different |
172 IDL integer types have same internal C++ type (int or unsigned) #} | 176 IDL integer types have same internal C++ type (int or unsigned) #} |
173 {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}NativeVa lue); | 177 {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}NativeVa lue); |
174 {% elif argument.idl_type == 'SerializedScriptValue' %} | 178 {% elif argument.idl_type == 'SerializedScriptValue' %} |
175 {{argument.name}} = SerializedScriptValue::create(info[{{argument.index}}], 0, 0 , exceptionState, info.GetIsolate()); | 179 {{argument.name}} = SerializedScriptValue::create(info[{{argument.index}}], 0, 0 , exceptionState, info.GetIsolate()); |
176 if (exceptionState.hadException()) { | 180 if (exceptionState.hadException()) { |
177 {{throw_from_exception_state(method)}}; | 181 {{throw_from_exception_state(method)}}; |
178 return; | 182 return; |
179 } | 183 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 v8SetReturnValueNull(info); | 315 v8SetReturnValueNull(info); |
312 {% endmacro %} | 316 {% endmacro %} |
313 | 317 |
314 | 318 |
315 {######################################} | 319 {######################################} |
316 {% macro throw_type_error(method, error_message) %} | 320 {% macro throw_type_error(method, error_message) %} |
317 {% if method.has_exception_state %} | 321 {% if method.has_exception_state %} |
318 exceptionState.throwTypeError({{error_message}}); | 322 exceptionState.throwTypeError({{error_message}}); |
319 {{throw_from_exception_state(method)}}; | 323 {{throw_from_exception_state(method)}}; |
320 {% elif method.is_constructor %} | 324 {% elif method.is_constructor %} |
325 {% if method.idl_type == 'Promise' %} | |
326 {# FIXME: reduce code duplication between sync / async exception handling. #} | |
haraken
2014/07/31 07:54:47
Yeah... would it be any way to avoid duplicating r
yhirano
2014/08/01 02:27:57
I think so. My current plan is to decouple excepti
haraken
2014/08/01 02:42:40
Thanks, it's great you could fix it in a follow-up
| |
327 v8SetReturnValue(info, ScriptPromise::rejectWithTypeError(ScriptState::current(i nfo.GetIsolate()), ExceptionMessages::failedToConstruct("{{interface_name}}", {{ error_message}})).v8Value()); | |
328 {% else %} | |
321 throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", {{erro r_message}}), info.GetIsolate()); | 329 throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", {{erro r_message}}), info.GetIsolate()); |
330 {% endif %} | |
322 {% else %}{# method.has_exception_state #} | 331 {% else %}{# method.has_exception_state #} |
332 {% if method.idl_type == 'Promise' %} | |
333 v8SetReturnValue(info, ScriptPromise::rejectWithTypeError(ScriptState::current(i nfo.GetIsolate()), ExceptionMessages::failedToExecute("{{method.name}}", "{{inte rface_name}}", {{error_message}})).v8Value()); | |
334 {% else %} | |
323 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interfac e_name}}", {{error_message}}), info.GetIsolate()); | 335 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interfac e_name}}", {{error_message}}), info.GetIsolate()); |
336 {% endif %} | |
324 {% endif %}{# method.has_exception_state #} | 337 {% endif %}{# method.has_exception_state #} |
325 {% endmacro %} | 338 {% endmacro %} |
326 | 339 |
327 | 340 |
328 {######################################} | 341 {######################################} |
329 {# FIXME: return a rejected Promise if method.idl_type == 'Promise' #} | |
330 {% macro throw_from_exception_state(method) %} | 342 {% macro throw_from_exception_state(method) %} |
343 {% if method.idl_type == 'Promise' %} | |
344 v8SetReturnValue(info, exceptionState.reject(ScriptState::current(info.GetIsolat e())).v8Value()) | |
345 {%- else %} | |
331 exceptionState.throwIfNeeded() | 346 exceptionState.throwIfNeeded() |
347 {%- endif %} | |
332 {%- endmacro %} | 348 {%- endmacro %} |
333 | 349 |
334 | 350 |
335 {######################################} | 351 {######################################} |
336 {% macro throw_arity_type_error(method, valid_arities) %} | 352 {% macro throw_arity_type_error(method, valid_arities) %} |
353 {% if method.idl_type == 'Promise' %} | |
354 {% if method.has_exception_state %} | |
355 v8SetReturnValue(info, ScriptPromise::rejectWithArityTypeError(ScriptState::curr ent(info.GetIsolate()), exceptionState, {{valid_arities}}, info.Length()).v8Valu e()) | |
356 {%- elif method.is_constructor %} | |
357 v8SetReturnValue(info, ScriptPromise::rejectWithArityTypeErrorForConstructor(Scr iptState::current(info.GetIsolate()), "{{interface_name}}", {{valid_arities}}, i nfo.Length()).v8Value()) | |
358 {%- else %} | |
359 v8SetReturnValue(info, ScriptPromise::rejectWithArityTypeErrorForMethod(ScriptSt ate::current(info.GetIsolate()), "{{method.name}}", "{{interface_name}}", {{vali d_arities}}, info.Length()).v8Value()) | |
360 {%- endif %} | |
361 {%- else %}{# methods.idl_type == 'Promise' #} | |
337 {% if method.has_exception_state %} | 362 {% if method.has_exception_state %} |
338 throwArityTypeError(exceptionState, {{valid_arities}}, info.Length()) | 363 throwArityTypeError(exceptionState, {{valid_arities}}, info.Length()) |
339 {%- elif method.is_constructor %} | 364 {%- elif method.is_constructor %} |
340 throwArityTypeErrorForConstructor("{{interface_name}}", {{valid_arities}}, info. Length(), info.GetIsolate()) | 365 throwArityTypeErrorForConstructor("{{interface_name}}", {{valid_arities}}, info. Length(), info.GetIsolate()) |
341 {%- else %} | 366 {%- else %} |
342 throwArityTypeErrorForMethod("{{method.name}}", "{{interface_name}}", {{valid_ar ities}}, info.Length(), info.GetIsolate()) | 367 throwArityTypeErrorForMethod("{{method.name}}", "{{interface_name}}", {{valid_ar ities}}, info.Length(), info.GetIsolate()) |
343 {%- endif %} | 368 {%- endif %} |
369 {%- endif %}{# methods.idl_type == 'Promise' #} | |
344 {% endmacro %} | 370 {% endmacro %} |
345 | 371 |
346 | 372 |
347 {######################################} | 373 {######################################} |
348 {% macro throw_minimum_arity_type_error(method, number_of_required_arguments) %} | 374 {% macro throw_minimum_arity_type_error(method, number_of_required_arguments) %} |
375 {% if method.idl_type == 'Promise' %} | |
376 {% if method.has_exception_state %} | |
377 v8SetReturnValue(info, ScriptPromise::rejectWithMinimumArityTypeError(ScriptStat e::current(info.GetIsolate()), exceptionState, {{number_of_required_arguments}}, info.Length()).v8Value()) | |
378 {%- elif method.is_constructor %} | |
379 v8SetReturnValue(info, ScriptPromise::rejectWithMinimumArityTypeErrorForConstruc tor(ScriptState::current(info.GetIsolate()), "{{interface_name}}", {{number_of_r equired_arguments}}, info.Length()).v8Value()) | |
380 {%- else %} | |
381 v8SetReturnValue(info, ScriptPromise::rejectWithMinimumArityTypeErrorForMethod(S criptState::current(info.GetIsolate()), "{{method.name}}", "{{interface_name}}", {{number_of_required_arguments}}, info.Length()).v8Value()) | |
382 {%- endif %} | |
383 {%- else %}{# methods.idl_type == 'Promise' #} | |
349 {% if method.has_exception_state %} | 384 {% if method.has_exception_state %} |
350 throwMinimumArityTypeError(exceptionState, {{number_of_required_arguments}}, inf o.Length()) | 385 throwMinimumArityTypeError(exceptionState, {{number_of_required_arguments}}, inf o.Length()) |
351 {%- elif method.is_constructor %} | 386 {%- elif method.is_constructor %} |
352 throwMinimumArityTypeErrorForConstructor("{{interface_name}}", {{number_of_requi red_arguments}}, info.Length(), info.GetIsolate()) | 387 throwMinimumArityTypeErrorForConstructor("{{interface_name}}", {{number_of_requi red_arguments}}, info.Length(), info.GetIsolate()) |
353 {%- else %} | 388 {%- else %} |
354 throwMinimumArityTypeErrorForMethod("{{method.name}}", "{{interface_name}}", {{n umber_of_required_arguments}}, info.Length(), info.GetIsolate()) | 389 throwMinimumArityTypeErrorForMethod("{{method.name}}", "{{interface_name}}", {{n umber_of_required_arguments}}, info.Length(), info.GetIsolate()) |
355 {%- endif %} | 390 {%- endif %} |
391 {%- endif %}{# methods.idl_type == 'Promise' #} | |
356 {% endmacro %} | 392 {% endmacro %} |
357 | 393 |
358 | 394 |
359 {##############################################################################} | 395 {##############################################################################} |
360 {% macro overload_resolution_method(overloads, world_suffix) %} | 396 {% macro overload_resolution_method(overloads, world_suffix) %} |
361 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI nfo<v8::Value>& info) | 397 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI nfo<v8::Value>& info) |
362 { | 398 { |
363 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{overloads .name}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 399 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{overloads .name}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); |
364 {% if overloads.measure_all_as %} | 400 {% if overloads.measure_all_as %} |
365 UseCounter::count(callingExecutionContext(info.GetIsolate()), UseCounter::{{ overloads.measure_all_as}}); | 401 UseCounter::count(callingExecutionContext(info.GetIsolate()), UseCounter::{{ overloads.measure_all_as}}); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
592 v8::Handle<v8::Object> wrapper = wrap(impl.get(), info.Holder(), info.GetIsolate ()); | 628 v8::Handle<v8::Object> wrapper = wrap(impl.get(), info.Holder(), info.GetIsolate ()); |
593 {% else %} | 629 {% else %} |
594 {% set constructor_class = v8_class + ('Constructor' | 630 {% set constructor_class = v8_class + ('Constructor' |
595 if constructor.is_named_constructor else | 631 if constructor.is_named_constructor else |
596 '') %} | 632 '') %} |
597 v8::Handle<v8::Object> wrapper = info.Holder(); | 633 v8::Handle<v8::Object> wrapper = info.Holder(); |
598 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{constr uctor_class}}::wrapperTypeInfo, wrapper, info.GetIsolate(), {{wrapper_configurat ion}}); | 634 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{constr uctor_class}}::wrapperTypeInfo, wrapper, info.GetIsolate(), {{wrapper_configurat ion}}); |
599 {% endif %} | 635 {% endif %} |
600 v8SetReturnValue(info, wrapper); | 636 v8SetReturnValue(info, wrapper); |
601 {% endmacro %} | 637 {% endmacro %} |
OLD | NEW |