| OLD | NEW |
| 1 {% from 'utilities.cpp' import declare_enum_validation_variable, v8_value_to_loc
al_cpp_value %} | 1 {% from 'utilities.cpp' import declare_enum_validation_variable, v8_value_to_loc
al_cpp_value %} |
| 2 | 2 |
| 3 {##############################################################################} | 3 {##############################################################################} |
| 4 {% macro generate_method(method, world_suffix) %} | 4 {% macro generate_method(method, world_suffix) %} |
| 5 {% if method.returns_promise and method.has_exception_state %} | 5 {% if method.returns_promise and method.has_exception_state %} |
| 6 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}Promis
e(const v8::FunctionCallbackInfo<v8::Value>& info, ExceptionState& exceptionStat
e) | 6 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}Promis
e(const v8::FunctionCallbackInfo<v8::Value>& info, ExceptionState& exceptionStat
e) |
| 7 {% else %} | 7 {% else %} |
| 8 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const
v8::FunctionCallbackInfo<v8::Value>& info) | 8 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const
v8::FunctionCallbackInfo<v8::Value>& info) |
| 9 {% endif %} | 9 {% endif %} |
| 10 { | 10 { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 {% endif %} | 26 {% endif %} |
| 27 {# Security checks #} | 27 {# Security checks #} |
| 28 {% if method.is_check_security_for_receiver %} | 28 {% if method.is_check_security_for_receiver %} |
| 29 {% if interface_name == 'EventTarget' %} | 29 {% if interface_name == 'EventTarget' %} |
| 30 // Performance hack for EventTarget. Checking whether it's a Window or not | 30 // Performance hack for EventTarget. Checking whether it's a Window or not |
| 31 // prior to the call to BindingSecurity::shouldAllowAccessTo increases 30% | 31 // prior to the call to BindingSecurity::shouldAllowAccessTo increases 30% |
| 32 // of speed performance on Android Nexus 7 as of Dec 2015. ALWAYS_INLINE | 32 // of speed performance on Android Nexus 7 as of Dec 2015. ALWAYS_INLINE |
| 33 // didn't work in this case. | 33 // didn't work in this case. |
| 34 if (const DOMWindow* window = impl->toDOMWindow()) { | 34 if (const DOMWindow* window = impl->toDOMWindow()) { |
| 35 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsola
te()), window, exceptionState)) { | 35 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsola
te()), window, exceptionState)) { |
| 36 {% if not method.returns_promise %} | |
| 37 exceptionState.throwIfNeeded(); | |
| 38 {% endif %} | |
| 39 return; | 36 return; |
| 40 } | 37 } |
| 41 } | 38 } |
| 42 {% else %}{# interface_name == 'EventTarget' #} | 39 {% else %}{# interface_name == 'EventTarget' #} |
| 43 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()
), impl, exceptionState)) { | 40 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()
), impl, exceptionState)) { |
| 44 {% if not method.returns_promise %} | |
| 45 exceptionState.throwIfNeeded(); | |
| 46 {% endif %} | |
| 47 return; | 41 return; |
| 48 } | 42 } |
| 49 {% endif %}{# interface_name == 'EventTarget' #} | 43 {% endif %}{# interface_name == 'EventTarget' #} |
| 50 {% endif %} | 44 {% endif %} |
| 51 {% if method.is_check_security_for_return_value %} | 45 {% if method.is_check_security_for_return_value %} |
| 52 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()
), {{method.cpp_value}}, exceptionState)) { | 46 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()
), {{method.cpp_value}}, exceptionState)) { |
| 53 v8SetReturnValueNull(info); | 47 v8SetReturnValueNull(info); |
| 54 {% if not method.returns_promise %} | |
| 55 exceptionState.throwIfNeeded(); | |
| 56 {% endif %} | |
| 57 return; | 48 return; |
| 58 } | 49 } |
| 59 {% endif %} | 50 {% endif %} |
| 60 {# Call method #} | 51 {# Call method #} |
| 61 {% if method.arguments %} | 52 {% if method.arguments %} |
| 62 {{generate_arguments(method, world_suffix) | indent}} | 53 {{generate_arguments(method, world_suffix) | indent}} |
| 63 {% endif %} | 54 {% endif %} |
| 64 {% if world_suffix %} | 55 {% if world_suffix %} |
| 65 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method.
cpp_value) | indent}} | 56 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method.
cpp_value) | indent}} |
| 66 {% else %} | 57 {% else %} |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 Note: for variadic arguments, the type checking is done for each matched | 192 Note: for variadic arguments, the type checking is done for each matched |
| 202 argument instead; see argument.is_variadic_wrapper_type code-path above. #} | 193 argument instead; see argument.is_variadic_wrapper_type code-path above. #} |
| 203 if (!{{argument.name}}{% if argument.is_nullable %} && !isUndefinedOrNull(info[{
{argument.index}}]){% endif %}) { | 194 if (!{{argument.name}}{% if argument.is_nullable %} && !isUndefinedOrNull(info[{
{argument.index}}]){% endif %}) { |
| 204 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % | 195 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % |
| 205 (argument.index + 1, argument.idl_type)) | indent
}} | 196 (argument.index + 1, argument.idl_type)) | indent
}} |
| 206 } | 197 } |
| 207 {% elif argument.enum_values %} | 198 {% elif argument.enum_values %} |
| 208 {# Invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} | 199 {# Invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} |
| 209 {{declare_enum_validation_variable(argument.enum_values)}} | 200 {{declare_enum_validation_variable(argument.enum_values)}} |
| 210 if (!isValidEnum({{argument.name}}, validValues, WTF_ARRAY_LENGTH(validValues),
"{{argument.enum_type}}", exceptionState)) { | 201 if (!isValidEnum({{argument.name}}, validValues, WTF_ARRAY_LENGTH(validValues),
"{{argument.enum_type}}", exceptionState)) { |
| 211 {% if not method.returns_promise %} | |
| 212 exceptionState.throwIfNeeded(); | |
| 213 {% endif %} | |
| 214 return; | 202 return; |
| 215 } | 203 } |
| 216 {% elif argument.idl_type == 'Promise' %} | 204 {% elif argument.idl_type == 'Promise' %} |
| 217 {# We require this for our implementation of promises, though not in spec: | 205 {# We require this for our implementation of promises, though not in spec: |
| 218 http://heycam.github.io/webidl/#es-promise #} | 206 http://heycam.github.io/webidl/#es-promise #} |
| 219 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) { | 207 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) { |
| 220 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % | 208 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % |
| 221 (argument.index + 1, argument.name)) | indent}} | 209 (argument.index + 1, argument.name)) | indent}} |
| 222 } | 210 } |
| 223 {% endif %} | 211 {% endif %} |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 {% if method.is_constructor %} | 305 {% if method.is_constructor %} |
| 318 ExceptionMessages::failedToConstruct("{{interface_name}}", {{error_message}}) | 306 ExceptionMessages::failedToConstruct("{{interface_name}}", {{error_message}}) |
| 319 {%- else %} | 307 {%- else %} |
| 320 ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", {{er
ror_message}}) | 308 ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", {{er
ror_message}}) |
| 321 {%- endif %} | 309 {%- endif %} |
| 322 {%- endmacro %} | 310 {%- endmacro %} |
| 323 | 311 |
| 324 | 312 |
| 325 {######################################} | 313 {######################################} |
| 326 {% macro propagate_error_with_exception_state(method_or_overloads) %} | 314 {% macro propagate_error_with_exception_state(method_or_overloads) %} |
| 327 {% if method_or_overloads.returns_promise_all %} | 315 {% if method_or_overloads.returns_promise_all or |
| 316 method_or_overloads.returns_promise %} |
| 328 v8SetReturnValue(info, exceptionState.reject(ScriptState::current(info.GetIsolat
e())).v8Value()); | 317 v8SetReturnValue(info, exceptionState.reject(ScriptState::current(info.GetIsolat
e())).v8Value()); |
| 329 {% elif not method_or_overloads.returns_promise %} | |
| 330 exceptionState.throwIfNeeded(); | |
| 331 {% endif %} | 318 {% endif %} |
| 332 return; | 319 return; |
| 333 {%- endmacro %} | 320 {%- endmacro %} |
| 334 | 321 |
| 335 | 322 |
| 336 {######################################} | 323 {######################################} |
| 337 {% macro throw_minimum_arity_type_error(method, number_of_required_arguments) %} | 324 {% macro throw_minimum_arity_type_error(method, number_of_required_arguments) %} |
| 338 {% if method.has_exception_state %} | 325 {% if method.has_exception_state %} |
| 339 setMinimumArityTypeError(exceptionState, {{number_of_required_arguments}}, info.
Length()); | 326 setMinimumArityTypeError(exceptionState, {{number_of_required_arguments}}, info.
Length()); |
| 340 {{propagate_error_with_exception_state(method)}} | 327 {{propagate_error_with_exception_state(method)}} |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 {% endmacro %} | 452 {% endmacro %} |
| 466 | 453 |
| 467 | 454 |
| 468 {##############################################################################} | 455 {##############################################################################} |
| 469 {% macro generate_post_message_impl() %} | 456 {% macro generate_post_message_impl() %} |
| 470 void postMessageImpl(const char* interfaceName, {{cpp_class}}* instance, const v
8::FunctionCallbackInfo<v8::Value>& info) | 457 void postMessageImpl(const char* interfaceName, {{cpp_class}}* instance, const v
8::FunctionCallbackInfo<v8::Value>& info) |
| 471 { | 458 { |
| 472 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage
", interfaceName, info.Holder(), info.GetIsolate()); | 459 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage
", interfaceName, info.Holder(), info.GetIsolate()); |
| 473 if (UNLIKELY(info.Length() < 1)) { | 460 if (UNLIKELY(info.Length() < 1)) { |
| 474 setMinimumArityTypeError(exceptionState, 1, info.Length()); | 461 setMinimumArityTypeError(exceptionState, 1, info.Length()); |
| 475 exceptionState.throwIfNeeded(); | |
| 476 return; | 462 return; |
| 477 } | 463 } |
| 478 Transferables transferables; | 464 Transferables transferables; |
| 479 if (info.Length() > 1) { | 465 if (info.Length() > 1) { |
| 480 const int transferablesArgIndex = 1; | 466 const int transferablesArgIndex = 1; |
| 481 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info
[transferablesArgIndex], transferablesArgIndex, transferables, exceptionState))
{ | 467 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info
[transferablesArgIndex], transferablesArgIndex, transferables, exceptionState))
{ |
| 482 exceptionState.throwIfNeeded(); | |
| 483 return; | 468 return; |
| 484 } | 469 } |
| 485 } | 470 } |
| 486 RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(inf
o.GetIsolate(), info[0], &transferables, nullptr, exceptionState); | 471 RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(inf
o.GetIsolate(), info[0], &transferables, nullptr, exceptionState); |
| 487 if (exceptionState.throwIfNeeded()) | 472 if (exceptionState.hadException()) |
| 488 return; | 473 return; |
| 489 // FIXME: Only pass context/exceptionState if instance really requires it. | 474 // FIXME: Only pass context/exceptionState if instance really requires it. |
| 490 ExecutionContext* context = currentExecutionContext(info.GetIsolate()); | 475 ExecutionContext* context = currentExecutionContext(info.GetIsolate()); |
| 491 instance->postMessage(context, message.release(), transferables.messagePorts
, exceptionState); | 476 instance->postMessage(context, message.release(), transferables.messagePorts
, exceptionState); |
| 492 exceptionState.throwIfNeeded(); | |
| 493 } | 477 } |
| 494 {% endmacro %} | 478 {% endmacro %} |
| 495 | 479 |
| 496 {##############################################################################} | 480 {##############################################################################} |
| 497 {% macro method_callback(method, world_suffix) %} | 481 {% macro method_callback(method, world_suffix) %} |
| 498 static void {{method.name}}MethodCallback{{world_suffix}}(const v8::FunctionCall
backInfo<v8::Value>& info) | 482 static void {{method.name}}MethodCallback{{world_suffix}}(const v8::FunctionCall
backInfo<v8::Value>& info) |
| 499 { | 483 { |
| 500 {% if not method.overloads %}{# Overloaded methods are measured in overload_
resolution_method() #} | 484 {% if not method.overloads %}{# Overloaded methods are measured in overload_
resolution_method() #} |
| 501 {% if method.measure_as %} | 485 {% if method.measure_as %} |
| 502 UseCounter::countIfNotPrivateScript(info.GetIsolate(), currentExecutionConte
xt(info.GetIsolate()), UseCounter::{{method.measure_as('Method')}}); | 486 UseCounter::countIfNotPrivateScript(info.GetIsolate(), currentExecutionConte
xt(info.GetIsolate()), UseCounter::{{method.measure_as('Method')}}); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 if method.overloads else | 678 if method.overloads else |
| 695 method.runtime_enabled_function) %} | 679 method.runtime_enabled_function) %} |
| 696 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration
= {{method_configuration(method)}}; | 680 const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfiguration
= {{method_configuration(method)}}; |
| 697 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto
typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration); | 681 V8DOMConfiguration::installMethod(isolate, world, v8::Local<v8::Object>(), proto
typeObject, interfaceObject, signature, {{method.name}}MethodConfiguration); |
| 698 {% endfilter %}{# runtime_enabled() #} | 682 {% endfilter %}{# runtime_enabled() #} |
| 699 {% endfilter %}{# exposed() #} | 683 {% endfilter %}{# exposed() #} |
| 700 {% endfilter %}{# secure_context() #} | 684 {% endfilter %}{# secure_context() #} |
| 701 {% endfor %} | 685 {% endfor %} |
| 702 {% endif %} | 686 {% endif %} |
| 703 {%- endmacro %} | 687 {%- endmacro %} |
| OLD | NEW |