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
); |
| 265 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder); |
| 266 prop.Set(holder, ToV8({{attribute.cpp_value}}, holder, isolate)); |
| 267 } |
| 268 {% endmacro %} |
260 | 269 |
261 {##############################################################################} | 270 {##############################################################################} |
262 {% macro constructor_getter_callback(attribute, world_suffix) %} | 271 {% 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) { | 272 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 %} | 273 {% if attribute.deprecate_as %} |
265 Deprecation::CountDeprecation(CurrentExecutionContext(info.GetIsolate()), UseC
ounter::k{{attribute.deprecate_as}}); | 274 Deprecation::CountDeprecation(CurrentExecutionContext(info.GetIsolate()), UseC
ounter::k{{attribute.deprecate_as}}); |
266 {% endif %} | 275 {% endif %} |
267 | 276 |
268 {% if attribute.measure_as %} | 277 {% if attribute.measure_as %} |
269 UseCounter::Count(CurrentExecutionContext(info.GetIsolate()), UseCounter::k{{a
ttribute.measure_as('ConstructorGetter')}}); | 278 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 %} | 410 {% endif %} |
402 {{attribute.cpp_setter}}; | 411 {{attribute.cpp_setter}}; |
403 | 412 |
404 {% if attribute.cached_attribute_validation_method %} | 413 {% if attribute.cached_attribute_validation_method %} |
405 // [CachedAttribute] | 414 // [CachedAttribute] |
406 // Invalidate the cached value. | 415 // Invalidate the cached value. |
407 V8PrivateProperty::GetSymbol( | 416 V8PrivateProperty::GetSymbol( |
408 isolate, "{{cpp_class}}#{{attribute.name.capitalize()}}") | 417 isolate, "{{cpp_class}}#{{attribute.name.capitalize()}}") |
409 .DeleteProperty(holder, v8::Undefined(isolate)); | 418 .DeleteProperty(holder, v8::Undefined(isolate)); |
410 {% endif %} | 419 {% endif %} |
| 420 |
| 421 {% if attribute.is_lazy_cached_accessor %} |
| 422 // Call cache init callback to store the correct private property. |
| 423 {{attribute.name}}CacheInitCallback(info.GetIsolate(), holder); |
| 424 {% endif %} |
411 } | 425 } |
412 {% endfilter %}{# format_remove_duplicates #} | 426 {% endfilter %}{# format_remove_duplicates #} |
413 {% endmacro %} | 427 {% endmacro %} |
414 | 428 |
415 | 429 |
416 {##############################################################################} | 430 {##############################################################################} |
417 {% macro attribute_setter_callback(attribute, world_suffix) %} | 431 {% macro attribute_setter_callback(attribute, world_suffix) %} |
418 void {{v8_class_or_partial}}::{{attribute.name}}AttributeSetterCallback{{world_s
uffix}}( | 432 void {{v8_class_or_partial}}::{{attribute.name}}AttributeSetterCallback{{world_s
uffix}}( |
419 {%- if attribute.is_data_type_property %} | 433 {%- if attribute.is_data_type_property %} |
420 v8::Local<v8::Name>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInf
o<void>& info | 434 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 %} | 476 {% elif attribute.has_cross_origin_setter %} |
463 {{cpp_class_or_partial}}V8Internal::{{attribute.name}}AttributeSetter(v8Value,
V8CrossOriginSetterInfo(info.GetIsolate(), info.Holder())); | 477 {{cpp_class_or_partial}}V8Internal::{{attribute.name}}AttributeSetter(v8Value,
V8CrossOriginSetterInfo(info.GetIsolate(), info.Holder())); |
464 {% else %} | 478 {% else %} |
465 {{cpp_class_or_partial}}V8Internal::{{attribute.name}}AttributeSetter{{world_s
uffix}}(v8Value, info); | 479 {{cpp_class_or_partial}}V8Internal::{{attribute.name}}AttributeSetter{{world_s
uffix}}(v8Value, info); |
466 {% endif %} | 480 {% endif %} |
467 } | 481 } |
468 {% endmacro %} | 482 {% endmacro %} |
469 | 483 |
470 | 484 |
471 {##############################################################################} | 485 {##############################################################################} |
472 {% macro attribute_configuration(attribute) %} | 486 {% macro build_attribute_or_accessor_configuration(attribute, is_attribute_confi
guration) %} |
473 {% from 'utilities.cpp.tmpl' import property_location %} | 487 {% from 'utilities.cpp.tmpl' import property_location %} |
474 {% if attribute.constructor_type %} | 488 {% if attribute.constructor_type %} |
475 {% if attribute.needs_constructor_getter_callback %} | 489 {% if attribute.needs_constructor_getter_callback %} |
476 {% set getter_callback = '%s::%sConstructorGetterCallback' % (v8_class_or_pa
rtial, attribute.name) %} | 490 {% set getter_callback = '%s::%sConstructorGetterCallback' % (v8_class_or_pa
rtial, attribute.name) %} |
477 {% else %} | 491 {% else %} |
478 {% set getter_callback = 'V8%s::NamedConstructorAttributeGetter' % (attribut
e.constructor_type) | 492 {% set getter_callback = 'V8%s::NamedConstructorAttributeGetter' % (attribut
e.constructor_type) |
479 if attribute.is_named_constructor else 'V8ConstructorAttributeGetter' %} | 493 if attribute.is_named_constructor else 'V8ConstructorAttributeGetter' %} |
480 {% endif %} | 494 {% endif %} |
481 {% set setter_callback = 'nullptr' %} | 495 {% set setter_callback = 'nullptr' %} |
482 {% else %}{# regular attributes #} | 496 {% else %}{# regular attributes #} |
483 {% set getter_callback = '%s::%sAttributeGetterCallback' % | 497 {% set getter_callback = '%s::%sAttributeGetterCallback' % |
484 (v8_class_or_partial, attribute.name) %} | 498 (v8_class_or_partial, attribute.name) %} |
485 {% set setter_callback = '%s::%sAttributeSetterCallback' % | 499 {% set setter_callback = '%s::%sAttributeSetterCallback' % |
486 (v8_class_or_partial, attribute.name) | 500 (v8_class_or_partial, attribute.name) |
487 if attribute.has_setter else 'nullptr' %} | 501 if attribute.has_setter else 'nullptr' %} |
488 {% endif %} | 502 {% endif %} |
489 {% set wrapper_type_info = | 503 {% set wrapper_type_info = |
490 'const_cast<WrapperTypeInfo*>(&V8%s::wrapperTypeInfo)' % attribute.constr
uctor_type | 504 'const_cast<WrapperTypeInfo*>(&V8%s::wrapperTypeInfo)' % attribute.constr
uctor_type |
491 if attribute.constructor_type else 'nullptr' %} | 505 if attribute.constructor_type else 'nullptr' %} |
492 {% set property_attribute = 'static_cast<v8::PropertyAttribute>(%s)' % | 506 {% set property_attribute = 'static_cast<v8::PropertyAttribute>(%s)' % |
493 ' | '.join(attribute.property_attributes) %} | 507 ' | '.join(attribute.property_attributes) %} |
494 {% set cached_accessor_callback = | 508 {% set cached_property_key = |
495 '%s::%sCachedPropertyKey' % (v8_class_or_partial, attribute.name) | 509 '%s::%sCachedPropertyKey' % (v8_class_or_partial, attribute.name) |
496 if attribute.is_cached_accessor else | 510 if attribute.is_cached_accessor else |
497 'nullptr' %} | 511 'nullptr' %} |
| 512 {% set cache_init_callback = |
| 513 '%sV8Internal::%sCacheInitCallback' % |
| 514 (cpp_class_or_partial, attribute.name) |
| 515 if attribute.is_lazy_cached_accessor else |
| 516 'nullptr' %} |
498 {% set holder_check = 'V8DOMConfiguration::kDoNotCheckHolder' | 517 {% set holder_check = 'V8DOMConfiguration::kDoNotCheckHolder' |
499 if attribute.is_lenient_this else 'V8DOMConfiguration::kCheckHolder' %} | 518 if attribute.is_lenient_this else 'V8DOMConfiguration::kCheckHolder' %} |
500 {% if attribute.is_per_world_bindings %} | 519 {% if attribute.is_per_world_bindings %} |
501 {% set getter_callback_for_main_world = '%sForMainWorld' % getter_callback %} | 520 {% set getter_callback_for_main_world = '%sForMainWorld' % getter_callback %} |
502 {% set setter_callback_for_main_world = | 521 {% set setter_callback_for_main_world = |
503 '%sForMainWorld' % setter_callback | 522 '%sForMainWorld' % setter_callback |
504 if attribute.has_setter else 'nullptr' %} | 523 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}, | 524 {% 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} | 525 |
507 {%- else %} | 526 |
508 {"{{attribute.name}}", {{getter_callback}}, {{setter_callback}}, {{cached_access
or_callback}}, {{wrapper_type_info}}, {{property_attribute}}, {{property_locatio
n(attribute)}}, {{holder_check}}, V8DOMConfiguration::kAllWorlds} | 527 {% set config_pre = { |
509 {%- endif %} | 528 "main" : [ |
510 {%- endmacro %} | 529 '"%s"' % attribute.name, |
| 530 getter_callback_for_main_world, |
| 531 setter_callback_for_main_world, |
| 532 ], |
| 533 "non_main" : [ |
| 534 '"%s"' % attribute.name, |
| 535 getter_callback, |
| 536 setter_callback, |
| 537 ], |
| 538 } %} |
| 539 |
| 540 {% set accessor_only_fields = [] if is_attribute_configuration else [ |
| 541 cached_property_key, |
| 542 cache_init_callback, |
| 543 ] %} |
| 544 |
| 545 {% set config_post = [ |
| 546 wrapper_type_info, |
| 547 property_attribute, |
| 548 property_location(attribute), |
| 549 holder_check, |
| 550 ] %} |
| 551 |
| 552 {% if attribute.is_per_world_bindings %} |
| 553 {% set main_config_list = config_pre["main"] + accessor_only_fields + |
| 554 config_post + ['V8DOMConfiguration::kMainWorld'] %} |
| 555 {% set non_main_config_list = config_pre["non_main"] + accessor_only_fields + |
| 556 config_post + ['V8DOMConfiguration::kNonMainWorlds'] %} |
| 557 {# Emit for main world then non-main.#} |
| 558 {{'{'}}{{main_config_list | join(', ')}}{{'}'}} |
| 559 {{','}} |
| 560 {{'{'}}{{non_main_config_list | join(', ')}}{{'}'}} |
| 561 {% else %} |
| 562 {% set all_worlds_config_list = config_pre["non_main"] + accessor_only_fields
+ |
| 563 config_post + ['V8DOMConfiguration::kAllWorlds'] %} |
| 564 {# Emit only for all worlds #} |
| 565 {{'{'}}{{all_worlds_config_list | join(', ')}}{{'}'}} |
| 566 {% endif %} |
| 567 {% endmacro %} |
| 568 |
| 569 {##############################################################################} |
| 570 {% macro attribute_configuration(attribute) %} |
| 571 {% set is_attribute_configuration = true %} |
| 572 {{build_attribute_or_accessor_configuration(attribute, is_attribute_configuratio
n)}} |
| 573 {% endmacro %} |
| 574 |
| 575 {##############################################################################} |
| 576 {% macro accessor_configuration(attribute) %} |
| 577 {% set is_attribute_configuration = false %} |
| 578 {{build_attribute_or_accessor_configuration(attribute, is_attribute_configuratio
n)}} |
| 579 {% endmacro %} |
511 | 580 |
512 {##############################################################################} | 581 {##############################################################################} |
513 {% macro install_conditionally_enabled_attributes_on_prototype() %} | 582 {% 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 %} | 583 {% for attribute in attributes if (attribute.exposed_test or attribute.secure_co
ntext_test) and attribute.on_prototype %} |
515 {% filter exposed(attribute.exposed_test) %} | 584 {% filter exposed(attribute.exposed_test) %} |
516 {% filter secure_context(attribute.secure_context_test) %} | 585 {% filter secure_context(attribute.secure_context_test) %} |
517 {% filter runtime_enabled(attribute.runtime_enabled_feature_name) %} | 586 {% filter runtime_enabled(attribute.runtime_enabled_feature_name) %} |
518 static const V8DOMConfiguration::AccessorConfiguration accessorConfiguration[] =
{ | 587 static const V8DOMConfiguration::AccessorConfiguration accessorConfiguration[] =
{ |
519 {{attribute_configuration(attribute)}} | 588 {{accessor_configuration(attribute)}} |
520 }; | 589 }; |
521 for (const auto& accessorConfig : accessorConfiguration) | 590 for (const auto& accessorConfig : accessorConfiguration) |
522 V8DOMConfiguration::InstallAccessor(isolate, world, v8::Local<v8::Object>(), p
rototypeObject, interfaceObject, signature, accessorConfig); | 591 V8DOMConfiguration::InstallAccessor(isolate, world, v8::Local<v8::Object>(), p
rototypeObject, interfaceObject, signature, accessorConfig); |
523 {% endfilter %}{# runtime_enabled #} | 592 {% endfilter %}{# runtime_enabled #} |
524 {% endfilter %}{# secure_context #} | 593 {% endfilter %}{# secure_context #} |
525 {% endfilter %}{# exposed #} | 594 {% endfilter %}{# exposed #} |
526 {% endfor %} | 595 {% endfor %} |
527 {% endmacro %} | 596 {% endmacro %} |
OLD | NEW |