summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_expr.py
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_expr.py')
-rw-r--r--chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_expr.py54
1 files changed, 31 insertions, 23 deletions
diff --git a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_expr.py b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_expr.py
index de9fb61d764..e1b6c8b1b08 100644
--- a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_expr.py
+++ b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_expr.py
@@ -4,7 +4,6 @@
import web_idl
-
_CODE_GEN_EXPR_PASS_KEY = object()
@@ -144,18 +143,22 @@ 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
- in_global: A global name of [Exposed] that the ExecutionContext is
- supposed to be / represent.
+ exposure: web_idl.Exposure of the target construct.
+ global_names: When specified, it's taken into account that the global
+ object implements |global_names|.
"""
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))
+ arg = "${execution_context}" if feature.is_context_dependent else ""
+ return _Expr("RuntimeEnabledFeatures::{}Enabled({})".format(
+ feature, arg))
top_terms = [_Expr(True)]
@@ -172,22 +175,26 @@ 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 global_names:
+ matched_global_count = 0
+ for entry in exposure.global_names_and_features:
+ if entry.global_name not in global_names:
+ continue
+ matched_global_count += 1
+ if entry.feature:
+ exposed_terms.append(ref_enabled(entry.feature))
+ assert (not exposure.global_names_and_features
+ or matched_global_count > 0)
+ else:
+ for entry in exposure.global_names_and_features:
+ terms = []
pred = GLOBAL_NAME_TO_EXECUTION_CONTEXT_TEST[entry.global_name]
terms.append(_Expr("${{execution_context}}->{}()".format(pred)))
- if entry.feature:
- terms.append(ref_enabled(entry.feature))
- if terms:
- exposed_terms.append(expr_and(terms))
+ if entry.feature:
+ terms.append(ref_enabled(entry.feature))
+ if terms:
+ exposed_terms.append(expr_and(terms))
if exposed_terms:
top_terms.append(expr_or(exposed_terms))
@@ -198,13 +205,14 @@ def expr_from_exposure(exposure, in_global=None):
# [SecureContext]
if exposure.only_in_secure_contexts is True:
- top_terms.append(_Expr("${in_secure_context}"))
+ top_terms.append(_Expr("${is_in_secure_context}"))
elif exposure.only_in_secure_contexts is False:
top_terms.append(_Expr(True))
else:
terms = map(ref_enabled, exposure.only_in_secure_contexts)
top_terms.append(
- expr_or([_Expr("${in_secure_context}"),
- expr_not(expr_and(terms))]))
+ expr_or(
+ [_Expr("${is_in_secure_context}"),
+ expr_not(expr_and(terms))]))
return expr_and(top_terms)