Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 {% from 'utilities.cpp.tmpl' import declare_enum_validation_variable, v8_value_t o_local_cpp_value %} | 1 {% from 'utilities.cpp.tmpl' import declare_enum_validation_variable, v8_value_t o_local_cpp_value %} |
| 2 | 2 |
| 3 {##############################################################################} | 3 {##############################################################################} |
| 4 {% macro attribute_getter(attribute, world_suffix) %} | 4 {% macro attribute_getter(attribute, world_suffix) %} |
| 5 static void {{attribute.name}}AttributeGetter{{world_suffix}}( | 5 static void {{attribute.name}}AttributeGetter{{world_suffix}}( |
| 6 {%- if attribute.is_data_type_property %} | 6 {%- if attribute.is_data_type_property %} |
| 7 const v8::PropertyCallbackInfo<v8::Value>& info | 7 const v8::PropertyCallbackInfo<v8::Value>& info |
| 8 {%- else %} | 8 {%- else %} |
| 9 const v8::FunctionCallbackInfo<v8::Value>& info | 9 const v8::FunctionCallbackInfo<v8::Value>& info |
| 10 {%- endif %}) { | 10 {%- endif %}) { |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 | 250 |
| 251 | 251 |
| 252 {##############################################################################} | 252 {##############################################################################} |
| 253 {% macro attribute_cached_property_key(attribute) %} | 253 {% macro attribute_cached_property_key(attribute) %} |
| 254 v8::Local<v8::Private> {{v8_class_or_partial}}::{{attribute.name}}CachedProperty Key(v8::Isolate* isolate) | 254 v8::Local<v8::Private> {{v8_class_or_partial}}::{{attribute.name}}CachedProperty Key(v8::Isolate* isolate) |
| 255 { | 255 { |
| 256 return V8PrivateProperty::Get{{attribute.cached_accessor_name}}(isolate).GetPr ivate(); | 256 return V8PrivateProperty::Get{{attribute.cached_accessor_name}}(isolate).GetPr ivate(); |
| 257 } | 257 } |
| 258 {% endmacro %} | 258 {% endmacro %} |
| 259 | 259 |
| 260 {##############################################################################} | |
| 261 {% macro attribute_cache_init_callback(attribute) %} | |
| 262 void {{attribute.name}}CacheInitCallback(v8::Isolate* isolate, v8::Local<v8::Obj ect> holder) | |
| 263 { | |
| 264 auto prop = V8PrivateProperty::Get{{attribute.cached_accessor_name}}(isolate ); | |
|
Yuki
2017/05/09 06:06:31
We may want to use V8PrivateProperty::GetSymbol(is
| |
| 265 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder); | |
| 266 prop.Set(holder, ToV8({{attribute.cpp_value}}, holder, isolate)); | |
| 267 //LOG(ERROR) << "{{attribute.name}}CacheInitCallback"; | |
|
Yuki
2017/05/09 06:06:31
nit: Remove this debugging code.
nverne
2017/05/10 02:11:49
Done
| |
| 268 } | |
| 269 {% endmacro %} | |
| 260 | 270 |
| 261 {##############################################################################} | 271 {##############################################################################} |
| 262 {% macro constructor_getter_callback(attribute, world_suffix) %} | 272 {% macro constructor_getter_callback(attribute, world_suffix) %} |
| 263 void {{v8_class_or_partial}}::{{attribute.name}}ConstructorGetterCallback{{world _suffix}}(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value >& info) { | 273 void {{v8_class_or_partial}}::{{attribute.name}}ConstructorGetterCallback{{world _suffix}}(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value >& info) { |
| 264 {% if attribute.deprecate_as %} | 274 {% if attribute.deprecate_as %} |
| 265 Deprecation::CountDeprecation(CurrentExecutionContext(info.GetIsolate()), UseC ounter::k{{attribute.deprecate_as}}); | 275 Deprecation::CountDeprecation(CurrentExecutionContext(info.GetIsolate()), UseC ounter::k{{attribute.deprecate_as}}); |
| 266 {% endif %} | 276 {% endif %} |
| 267 | 277 |
| 268 {% if attribute.measure_as %} | 278 {% if attribute.measure_as %} |
| 269 UseCounter::Count(CurrentExecutionContext(info.GetIsolate()), UseCounter::k{{a ttribute.measure_as('ConstructorGetter')}}); | 279 UseCounter::Count(CurrentExecutionContext(info.GetIsolate()), UseCounter::k{{a ttribute.measure_as('ConstructorGetter')}}); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 {% endif %} | 411 {% endif %} |
| 402 {{attribute.cpp_setter}}; | 412 {{attribute.cpp_setter}}; |
| 403 | 413 |
| 404 {% if attribute.cached_attribute_validation_method %} | 414 {% if attribute.cached_attribute_validation_method %} |
| 405 // [CachedAttribute] | 415 // [CachedAttribute] |
| 406 // Invalidate the cached value. | 416 // Invalidate the cached value. |
| 407 V8PrivateProperty::GetSymbol( | 417 V8PrivateProperty::GetSymbol( |
| 408 isolate, "{{cpp_class}}#{{attribute.name.capitalize()}}") | 418 isolate, "{{cpp_class}}#{{attribute.name.capitalize()}}") |
| 409 .DeleteProperty(holder, v8::Undefined(isolate)); | 419 .DeleteProperty(holder, v8::Undefined(isolate)); |
| 410 {% endif %} | 420 {% endif %} |
| 421 | |
| 422 {% if attribute.is_lazy_cached_accessor %} | |
| 423 // Call cache init callback to store the correct private property. | |
| 424 {{attribute.name}}CacheInitCallback(info.GetIsolate(), holder); | |
| 425 {% endif %} | |
| 426 | |
|
Yuki
2017/05/09 06:06:31
nit: Remove this empty line.
nverne
2017/05/10 02:11:49
Done
| |
| 411 } | 427 } |
| 412 {% endfilter %}{# format_remove_duplicates #} | 428 {% endfilter %}{# format_remove_duplicates #} |
| 413 {% endmacro %} | 429 {% endmacro %} |
| 414 | 430 |
| 415 | 431 |
| 416 {##############################################################################} | 432 {##############################################################################} |
| 417 {% macro attribute_setter_callback(attribute, world_suffix) %} | 433 {% macro attribute_setter_callback(attribute, world_suffix) %} |
| 418 void {{v8_class_or_partial}}::{{attribute.name}}AttributeSetterCallback{{world_s uffix}}( | 434 void {{v8_class_or_partial}}::{{attribute.name}}AttributeSetterCallback{{world_s uffix}}( |
| 419 {%- if attribute.is_data_type_property %} | 435 {%- if attribute.is_data_type_property %} |
| 420 v8::Local<v8::Name>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInf o<void>& info | 436 v8::Local<v8::Name>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInf o<void>& info |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 {% elif attribute.has_cross_origin_setter %} | 478 {% elif attribute.has_cross_origin_setter %} |
| 463 {{cpp_class_or_partial}}V8Internal::{{attribute.name}}AttributeSetter(v8Value, V8CrossOriginSetterInfo(info.GetIsolate(), info.Holder())); | 479 {{cpp_class_or_partial}}V8Internal::{{attribute.name}}AttributeSetter(v8Value, V8CrossOriginSetterInfo(info.GetIsolate(), info.Holder())); |
| 464 {% else %} | 480 {% else %} |
| 465 {{cpp_class_or_partial}}V8Internal::{{attribute.name}}AttributeSetter{{world_s uffix}}(v8Value, info); | 481 {{cpp_class_or_partial}}V8Internal::{{attribute.name}}AttributeSetter{{world_s uffix}}(v8Value, info); |
| 466 {% endif %} | 482 {% endif %} |
| 467 } | 483 } |
| 468 {% endmacro %} | 484 {% endmacro %} |
| 469 | 485 |
| 470 | 486 |
| 471 {##############################################################################} | 487 {##############################################################################} |
| 472 {% macro attribute_configuration(attribute) %} | 488 {% macro attribute_accessor_configuration(attribute, is_attribute) %} |
|
Yuki
2017/05/09 06:06:30
nit: s/is_attribute/is_data_property/
IDL attribu
nverne
2017/05/10 02:11:49
This macro builds either an AccessorConfiguration
| |
| 473 {% from 'utilities.cpp.tmpl' import property_location %} | 489 {% from 'utilities.cpp.tmpl' import property_location %} |
| 474 {% if attribute.constructor_type %} | 490 {% if attribute.constructor_type %} |
| 475 {% if attribute.needs_constructor_getter_callback %} | 491 {% if attribute.needs_constructor_getter_callback %} |
| 476 {% set getter_callback = '%s::%sConstructorGetterCallback' % (v8_class_or_pa rtial, attribute.name) %} | 492 {% set getter_callback = '%s::%sConstructorGetterCallback' % (v8_class_or_pa rtial, attribute.name) %} |
| 477 {% else %} | 493 {% else %} |
| 478 {% set getter_callback = 'V8%s::NamedConstructorAttributeGetter' % (attribut e.constructor_type) | 494 {% set getter_callback = 'V8%s::NamedConstructorAttributeGetter' % (attribut e.constructor_type) |
| 479 if attribute.is_named_constructor else 'V8ConstructorAttributeGetter' %} | 495 if attribute.is_named_constructor else 'V8ConstructorAttributeGetter' %} |
| 480 {% endif %} | 496 {% endif %} |
| 481 {% set setter_callback = 'nullptr' %} | 497 {% set setter_callback = 'nullptr' %} |
| 482 {% else %}{# regular attributes #} | 498 {% else %}{# regular attributes #} |
| 483 {% set getter_callback = '%s::%sAttributeGetterCallback' % | 499 {% set getter_callback = '%s::%sAttributeGetterCallback' % |
| 484 (v8_class_or_partial, attribute.name) %} | 500 (v8_class_or_partial, attribute.name) %} |
| 485 {% set setter_callback = '%s::%sAttributeSetterCallback' % | 501 {% set setter_callback = '%s::%sAttributeSetterCallback' % |
| 486 (v8_class_or_partial, attribute.name) | 502 (v8_class_or_partial, attribute.name) |
| 487 if attribute.has_setter else 'nullptr' %} | 503 if attribute.has_setter else 'nullptr' %} |
| 488 {% endif %} | 504 {% endif %} |
| 489 {% set wrapper_type_info = | 505 {% set wrapper_type_info = |
| 490 'const_cast<WrapperTypeInfo*>(&V8%s::wrapperTypeInfo)' % attribute.constr uctor_type | 506 'const_cast<WrapperTypeInfo*>(&V8%s::wrapperTypeInfo)' % attribute.constr uctor_type |
| 491 if attribute.constructor_type else 'nullptr' %} | 507 if attribute.constructor_type else 'nullptr' %} |
| 492 {% set property_attribute = 'static_cast<v8::PropertyAttribute>(%s)' % | 508 {% set property_attribute = 'static_cast<v8::PropertyAttribute>(%s)' % |
| 493 ' | '.join(attribute.property_attributes) %} | 509 ' | '.join(attribute.property_attributes) %} |
| 494 {% set cached_accessor_callback = | 510 {% set cached_property_key = |
| 495 '%s::%sCachedPropertyKey' % (v8_class_or_partial, attribute.name) | 511 '%s::%sCachedPropertyKey' % (v8_class_or_partial, attribute.name) |
| 496 if attribute.is_cached_accessor else | 512 if attribute.is_cached_accessor else |
| 497 'nullptr' %} | 513 'nullptr' %} |
| 514 {% set cache_init_callback = | |
| 515 '%sV8Internal::%sCacheInitCallback' % | |
| 516 (cpp_class_or_partial, attribute.name) | |
| 517 if attribute.is_lazy_cached_accessor else | |
| 518 'nullptr' %} | |
| 498 {% set holder_check = 'V8DOMConfiguration::kDoNotCheckHolder' | 519 {% set holder_check = 'V8DOMConfiguration::kDoNotCheckHolder' |
| 499 if attribute.is_lenient_this else 'V8DOMConfiguration::kCheckHolder' %} | 520 if attribute.is_lenient_this else 'V8DOMConfiguration::kCheckHolder' %} |
| 500 {% if attribute.is_per_world_bindings %} | 521 {% if attribute.is_per_world_bindings %} |
| 501 {% set getter_callback_for_main_world = '%sForMainWorld' % getter_callback %} | 522 {% set getter_callback_for_main_world = '%sForMainWorld' % getter_callback %} |
| 502 {% set setter_callback_for_main_world = | 523 {% set setter_callback_for_main_world = |
| 503 '%sForMainWorld' % setter_callback | 524 '%sForMainWorld' % setter_callback |
| 504 if attribute.has_setter else 'nullptr' %} | 525 if attribute.has_setter else 'nullptr' %} |
| 505 {"{{attribute.name}}", {{getter_callback_for_main_world}}, {{setter_callback_for _main_world}}, {{cached_accessor_callback}}, {{wrapper_type_info}}, {{property_a ttribute}}, {{property_location(attribute)}}, {{holder_check}}, V8DOMConfigurati on::kMainWorld}, | 526 {% endif %} |
| 506 {"{{attribute.name}}", {{getter_callback}}, {{setter_callback}}, {{cached_access or_callback}}, {{wrapper_type_info}}, {{property_attribute}}, {{property_locatio n(attribute)}}, {{holder_check}}, V8DOMConfiguration::kNonMainWorlds} | 527 |
| 507 {%- else %} | 528 |
| 508 {"{{attribute.name}}", {{getter_callback}}, {{setter_callback}}, {{cached_access or_callback}}, {{wrapper_type_info}}, {{property_attribute}}, {{property_locatio n(attribute)}}, {{holder_check}}, V8DOMConfiguration::kAllWorlds} | 529 {% set config_pre = { |
|
Yuki
2017/05/09 06:06:31
nit: I'd prefer naming this config_world_dependent
| |
| 509 {%- endif %} | 530 "main" : [ |
| 510 {%- endmacro %} | 531 '"%s"' % attribute.name, |
| 532 getter_callback_for_main_world, | |
| 533 setter_callback_for_main_world, | |
| 534 ], | |
| 535 "other" : [ | |
|
Yuki
2017/05/09 06:06:31
nit: "non-main" or something like that?
"non-main"
| |
| 536 '"%s"' % attribute.name, | |
| 537 getter_callback, | |
| 538 setter_callback, | |
| 539 ], | |
| 540 } %} | |
| 541 | |
| 542 {% set accessor_only_fields = [] if is_attribute else [ | |
|
Yuki
2017/05/09 06:06:31
nit: Can we fold this into config_post and rename
| |
| 543 cached_property_key, | |
| 544 cache_init_callback, | |
| 545 ] %} | |
| 546 | |
| 547 {% set config_post = [ | |
| 548 wrapper_type_info, | |
| 549 property_attribute, | |
| 550 property_location(attribute), | |
| 551 holder_check, | |
| 552 ] %} | |
| 553 | |
| 554 {% if attribute.is_per_world_bindings %} | |
|
Yuki
2017/05/09 06:06:31
Great improvement! Can we go farther?
I'm wonder
| |
| 555 {% set main_config_list = config_pre["main"] + accessor_only_fields + | |
| 556 config_post + ['V8DOMConfiguration::kMainWorld'] %} | |
| 557 {% set non_main_config_list = config_pre["other"] + accessor_only_fields + | |
| 558 config_post + ['V8DOMConfiguration::kNonMainWorlds'] %} | |
| 559 {# Emit for main world then non-main.#} | |
| 560 {{'{'}}{{main_config_list | join(', ')}}{{'}'}} | |
| 561 {{','}} | |
| 562 {{'{'}}{{non_main_config_list | join(', ')}}{{'}'}} | |
| 563 {% else %} | |
| 564 {% set all_worlds_config_list = config_pre["other"] + accessor_only_fields + | |
| 565 config_post + ['V8DOMConfiguration::kAllWorlds'] %} | |
| 566 {# Emit only for all worlds #} | |
| 567 {{'{'}}{{all_worlds_config_list | join(', ')}}{{'}'}} | |
| 568 {% endif %} | |
| 569 {% endmacro %} | |
| 570 | |
| 571 {##############################################################################} | |
| 572 {% macro attribute_configuration(attribute) %} | |
| 573 {% set is_attribute = true %} | |
|
Yuki
2017/05/09 06:06:31
nit: s/is_attribute/is_data_property/
| |
| 574 {{attribute_accessor_configuration(attribute, is_attribute)}} | |
| 575 {% endmacro %} | |
| 576 | |
| 577 {##############################################################################} | |
| 578 {% macro accessor_configuration(attribute) %} | |
| 579 {% set is_attribute = false %} | |
|
Yuki
2017/05/09 06:06:31
ditto
| |
| 580 {{attribute_accessor_configuration(attribute, is_attribute)}} | |
| 581 {% endmacro %} | |
| 511 | 582 |
| 512 {##############################################################################} | 583 {##############################################################################} |
| 513 {% macro install_conditionally_enabled_attributes_on_prototype() %} | 584 {% macro install_conditionally_enabled_attributes_on_prototype() %} |
| 514 {% for attribute in attributes if (attribute.exposed_test or attribute.secure_co ntext_test) and attribute.on_prototype %} | 585 {% for attribute in attributes if (attribute.exposed_test or attribute.secure_co ntext_test) and attribute.on_prototype %} |
| 515 {% filter exposed(attribute.exposed_test) %} | 586 {% filter exposed(attribute.exposed_test) %} |
| 516 {% filter secure_context(attribute.secure_context_test) %} | 587 {% filter secure_context(attribute.secure_context_test) %} |
| 517 {% filter runtime_enabled(attribute.runtime_enabled_feature_name) %} | 588 {% filter runtime_enabled(attribute.runtime_enabled_feature_name) %} |
| 518 static const V8DOMConfiguration::AccessorConfiguration accessorConfiguration[] = { | 589 static const V8DOMConfiguration::AccessorConfiguration accessorConfiguration[] = { |
| 519 {{attribute_configuration(attribute)}} | 590 {{accessor_configuration(attribute)}} |
| 520 }; | 591 }; |
| 521 for (const auto& accessorConfig : accessorConfiguration) | 592 for (const auto& accessorConfig : accessorConfiguration) |
| 522 V8DOMConfiguration::InstallAccessor(isolate, world, v8::Local<v8::Object>(), p rototypeObject, interfaceObject, signature, accessorConfig); | 593 V8DOMConfiguration::InstallAccessor(isolate, world, v8::Local<v8::Object>(), p rototypeObject, interfaceObject, signature, accessorConfig); |
| 523 {% endfilter %}{# runtime_enabled #} | 594 {% endfilter %}{# runtime_enabled #} |
| 524 {% endfilter %}{# secure_context #} | 595 {% endfilter %}{# secure_context #} |
| 525 {% endfilter %}{# exposed #} | 596 {% endfilter %}{# exposed #} |
| 526 {% endfor %} | 597 {% endfor %} |
| 527 {% endmacro %} | 598 {% endmacro %} |
| OLD | NEW |