Commit 81dd156b authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

bind-gen: Fix minor bugs of Interface code generation

Fixes trivial bugs.
- Wrong assertion in blink_v8_bridge.py
- Support [Global=(Worklet, PaintWorklet)]
- Enumeration type is included in "string types"

Bug: 839389
Change-Id: Idaea55a6d827a4b816c4e844062eda6f253efb40
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1983113Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727748}
parent 9cb6407e
......@@ -203,7 +203,7 @@ def make_default_value_expr(idl_type, default_value):
if default_value.is_type_compatible_with(member_type):
idl_type = member_type
break
assert False
assert default_value.is_type_compatible_with(idl_type)
type_info = blink_type_info(idl_type)
is_initializer_lightweight = False
......
......@@ -144,7 +144,7 @@ def expr_uniq(terms):
return uniq_terms
def expr_from_exposure(exposure, in_global=None):
def expr_from_exposure(exposure, global_names=None):
"""
Args:
exposure: web_idl.Exposure
......@@ -152,7 +152,9 @@ def expr_from_exposure(exposure, in_global=None):
supposed to be / represent.
"""
assert isinstance(exposure, web_idl.Exposure)
assert in_global is None or isinstance(in_global, str)
assert (global_names is None
or (isinstance(global_names, (list, tuple))
and all(isinstance(name, str) for name in global_names)))
def ref_enabled(feature):
return _Expr("RuntimeEnabledFeatures::{}Enabled()".format(feature))
......@@ -172,16 +174,10 @@ def expr_from_exposure(exposure, in_global=None):
"Worker": "IsWorkerGlobalScope",
"Worklet": "IsWorkletGlobalScope",
}
in_globals = set()
if in_global:
in_globals.add(in_global)
for category_name in ("Worker", "Worklet"):
if in_global.endswith(category_name):
in_globals.add(category_name)
exposed_terms = []
for entry in exposure.global_names_and_features:
terms = []
if entry.global_name not in in_globals:
if entry.global_name not in (global_names or []):
pred = GLOBAL_NAME_TO_EXECUTION_CONTEXT_TEST[entry.global_name]
terms.append(_Expr("${{execution_context}}->{}()".format(pred)))
if entry.feature:
......
......@@ -1818,7 +1818,7 @@ def _make_property_entries_and_callback_defs(
assert isinstance(operation_entries, list)
interface = cg_context.interface
global_name = interface.extended_attributes.value_of("Global")
global_names = interface.extended_attributes.values_of("Global")
callback_def_nodes = ListNode()
......@@ -1826,7 +1826,7 @@ def _make_property_entries_and_callback_defs(
for member in members:
is_context_dependent = member.exposure.is_context_dependent
exposure_conditional = expr_from_exposure(member.exposure,
global_name)
global_names)
if "PerWorldBindings" in member.extended_attributes:
worlds = (CodeGenContext.MAIN_WORLD,
......
......@@ -271,6 +271,9 @@ class OverloadGroup(WithIdentifier):
return True
# step 4. Consider the two "innermost" types ...
def is_string_type(idl_type):
return idl_type.is_string or idl_type.is_enumeration
def is_interface_like(idl_type):
return idl_type.is_interface or idl_type.is_buffer_source_type
......@@ -291,11 +294,11 @@ class OverloadGroup(WithIdentifier):
return not type2.is_boolean
if type1.is_numeric:
return not type2.is_numeric
if type1.is_string:
return not type2.is_string
if is_string_type(type1):
return not is_string_type(type2)
if type1.is_object:
return (type2.is_boolean or type2.is_numeric or type2.is_string
or type2.is_symbol)
return (type2.is_boolean or type2.is_numeric
or is_string_type(type2) or type2.is_symbol)
if type1.is_symbol:
return not type2.is_symbol
if is_interface_like(type1):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment