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

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

Issue 657523002: Skip expensive hasInstance() type-checks in overloads (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
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{% if method.overload_index %}, int ty pe_checked_argument_index{% endif %})
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 #}
11 {% if method.number_of_required_arguments and not method.overload_index %} 11 {% if method.number_of_required_arguments and not method.overload_index %}
12 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { 12 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) {
13 {{throw_minimum_arity_type_error(method, method.number_of_required_argum ents) | indent(8)}} 13 {{throw_minimum_arity_type_error(method, method.number_of_required_argum ents) | indent(8)}}
14 return; 14 return;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 {% elif argument.is_dictionary %} 165 {% elif argument.is_dictionary %}
166 {# Dictionaries must have type Undefined, Null or Object: 166 {# Dictionaries must have type Undefined, Null or Object:
167 http://heycam.github.io/webidl/#es-dictionary #} 167 http://heycam.github.io/webidl/#es-dictionary #}
168 if (!isUndefinedOrNull(info[{{argument.index}}]) && !info[{{argument.index}}]->I sObject()) { 168 if (!isUndefinedOrNull(info[{{argument.index}}]) && !info[{{argument.index}}]->I sObject()) {
169 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % 169 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' %
170 (argument.index + 1, argument.name)) | indent}} 170 (argument.index + 1, argument.name)) | indent}}
171 return; 171 return;
172 } 172 }
173 {{argument.v8_value_to_local_cpp_value}}; 173 {{argument.v8_value_to_local_cpp_value}};
174 {% else %}{# argument.is_nullable #} 174 {% else %}{# argument.is_nullable #}
175 {# Optionally do an "unsafe" type conversion if meaningful for this argument's
176 type and if this method is overloaded and the argument's type was checked as
177 part of overload resolution for this particular call. #}
178 {% if method.overload_index and
179 argument.is_distinguishing_argument and
180 argument.v8_value_to_local_cpp_value_unsafe %}
181 if (type_checked_argument_index == {{argument.index}})
haraken 2014/10/14 13:54:07 Help me understand: I'm curious about the relation
Jens Widell 2014/10/14 14:37:56 Yes, it's possible. The key complexity here (which
182 {{argument.v8_value_to_local_cpp_value_unsafe}};
183 else
184 {{argument.v8_value_to_local_cpp_value}};
185 {% else %}
175 {{argument.v8_value_to_local_cpp_value}}; 186 {{argument.v8_value_to_local_cpp_value}};
187 {% endif %}
176 {% endif %}{# argument.is_nullable #} 188 {% endif %}{# argument.is_nullable #}
177 {# Type checking, possibly throw a TypeError, per: 189 {# Type checking, possibly throw a TypeError, per:
178 http://www.w3.org/TR/WebIDL/#es-type-mapping #} 190 http://www.w3.org/TR/WebIDL/#es-type-mapping #}
179 {% if argument.has_type_checking_unrestricted %} 191 {% if argument.has_type_checking_unrestricted %}
180 {# Non-finite floating point values (NaN, +Infinity or −Infinity), per: 192 {# Non-finite floating point values (NaN, +Infinity or −Infinity), per:
181 http://heycam.github.io/webidl/#es-float 193 http://heycam.github.io/webidl/#es-float
182 http://heycam.github.io/webidl/#es-double #} 194 http://heycam.github.io/webidl/#es-double #}
183 if (!std::isfinite({{argument.name}})) { 195 if (!std::isfinite({{argument.name}})) {
184 {{throw_type_error(method, '"%s parameter %s is non-finite."' % 196 {{throw_type_error(method, '"%s parameter %s is non-finite."' %
185 (argument.idl_type, argument.index + 1)) | indent }} 197 (argument.idl_type, argument.index + 1)) | indent }}
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 UseCounter::countDeprecation(callingExecutionContext(info.GetIsolate()), Use Counter::{{overloads.deprecate_all_as}}); 382 UseCounter::countDeprecation(callingExecutionContext(info.GetIsolate()), Use Counter::{{overloads.deprecate_all_as}});
371 {% endif %} 383 {% endif %}
372 {# First resolve by length #} 384 {# First resolve by length #}
373 {# 2. Initialize argcount to be min(maxarg, n). #} 385 {# 2. Initialize argcount to be min(maxarg, n). #}
374 switch (std::min({{overloads.maxarg}}, info.Length())) { 386 switch (std::min({{overloads.maxarg}}, info.Length())) {
375 {# 3. Remove from S all entries whose type list is not of length argcount. # } 387 {# 3. Remove from S all entries whose type list is not of length argcount. # }
376 {% for length, tests_methods in overloads.length_tests_methods %} 388 {% for length, tests_methods in overloads.length_tests_methods %}
377 {# 10. If i = d, then: #} 389 {# 10. If i = d, then: #}
378 case {{length}}: 390 case {{length}}:
379 {# Then resolve by testing argument #} 391 {# Then resolve by testing argument #}
380 {% for test, method in tests_methods %} 392 {% for test, method, typed_checked_argument_index in tests_methods %}
381 {% filter runtime_enabled(not overloads.runtime_enabled_function_all and 393 {% filter runtime_enabled(not overloads.runtime_enabled_function_all and
382 method.runtime_enabled_function) %} 394 method.runtime_enabled_function) %}
383 if ({{test}}) { 395 if ({{test}}) {
384 {% if method.measure_as and not overloads.measure_all_as %} 396 {% if method.measure_as and not overloads.measure_all_as %}
385 UseCounter::count(callingExecutionContext(info.GetIsolate()), UseCou nter::{{method.measure_as}}); 397 UseCounter::count(callingExecutionContext(info.GetIsolate()), UseCou nter::{{method.measure_as}});
386 {% endif %} 398 {% endif %}
387 {% if method.deprecate_as and not overloads.deprecate_all_as %} 399 {% if method.deprecate_as and not overloads.deprecate_all_as %}
388 UseCounter::countDeprecation(callingExecutionContext(info.GetIsolate ()), UseCounter::{{method.deprecate_as}}); 400 UseCounter::countDeprecation(callingExecutionContext(info.GetIsolate ()), UseCounter::{{method.deprecate_as}});
389 {% endif %} 401 {% endif %}
390 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info) ; 402 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info, {{typed_checked_argument_index}});
391 return; 403 return;
392 } 404 }
393 {% endfilter %} 405 {% endfilter %}
394 {% endfor %} 406 {% endfor %}
395 break; 407 break;
396 {% endfor %} 408 {% endfor %}
397 default: 409 default:
398 {# Invalid arity, throw error #} 410 {# Invalid arity, throw error #}
399 {# Report full list of valid arities if gaps and above minimum #} 411 {# Report full list of valid arities if gaps and above minimum #}
400 {% if overloads.valid_arities %} 412 {% if overloads.valid_arities %}
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 return true; 552 return true;
541 } 553 }
542 {% endmacro %} 554 {% endmacro %}
543 555
544 556
545 {##############################################################################} 557 {##############################################################################}
546 {% macro generate_constructor(constructor) %} 558 {% macro generate_constructor(constructor) %}
547 {% set name = '%sConstructorCallback' % v8_class 559 {% set name = '%sConstructorCallback' % v8_class
548 if constructor.is_named_constructor else 560 if constructor.is_named_constructor else
549 'constructor%s' % (constructor.overload_index or '') %} 561 'constructor%s' % (constructor.overload_index or '') %}
550 static void {{name}}(const v8::FunctionCallbackInfo<v8::Value>& info) 562 static void {{name}}(const v8::FunctionCallbackInfo<v8::Value>& info{% if constr uctor.overload_index %}, int type_checked_argument_index{% endif %})
haraken 2014/10/14 13:54:07 type_checked_argument_index => typeCheckedArgument
551 { 563 {
552 {% if constructor.is_named_constructor %} 564 {% if constructor.is_named_constructor %}
553 if (!info.IsConstructCall()) { 565 if (!info.IsConstructCall()) {
554 V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallab leAsFunction("{{constructor.name}}"), info.GetIsolate()); 566 V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallab leAsFunction("{{constructor.name}}"), info.GetIsolate());
555 return; 567 return;
556 } 568 }
557 569
558 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExis tingObject) { 570 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExis tingObject) {
559 v8SetReturnValue(info, info.Holder()); 571 v8SetReturnValue(info, info.Holder());
560 return; 572 return;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 if method.is_per_world_bindings else '0' %} 628 if method.is_per_world_bindings else '0' %}
617 {% set property_attribute = 629 {% set property_attribute =
618 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_attribut es) 630 'static_cast<v8::PropertyAttribute>(%s)' % ' | '.join(method.property_attribut es)
619 if method.property_attributes else 'v8::None' %} 631 if method.property_attributes else 'v8::None' %}
620 {% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivat eScript' if method.only_exposed_to_private_script else 'V8DOMConfiguration::Expo sedToAllScripts' %} 632 {% set only_exposed_to_private_script = 'V8DOMConfiguration::OnlyExposedToPrivat eScript' if method.only_exposed_to_private_script else 'V8DOMConfiguration::Expo sedToAllScripts' %}
621 static const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfig uration = { 633 static const V8DOMConfiguration::MethodConfiguration {{method.name}}MethodConfig uration = {
622 "{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{method.length}}, {{only_exposed_to_private_script}}, 634 "{{method.name}}", {{method_callback}}, {{method_callback_for_main_world}}, {{method.length}}, {{only_exposed_to_private_script}},
623 }; 635 };
624 V8DOMConfiguration::installMethod({{method.function_template}}, {{method.signatu re}}, {{property_attribute}}, {{method.name}}MethodConfiguration, isolate); 636 V8DOMConfiguration::installMethod({{method.function_template}}, {{method.signatu re}}, {{property_attribute}}, {{method.name}}MethodConfiguration, isolate);
625 {%- endmacro %} 637 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698