0

Allow mojo consts to reference enums in .mojom.m.js

Before this change, generated mojom.m.js files would include a const
definition for enum consts:-

```
/**
 * @const { !sandbox_mojom_Sandbox }
 */
export const PROXY_RESOLVER_SANDBOX = sandbox_mojom_Sandbox.kProxyResolver;
```

but would not import the sandbox_mojom_Sandbox as the mojo module did
not know that consts could reference enums.

After this change, an import will be generated:-

```
import {
  Sandbox as sandbox_mojom_Sandbox,
  SandboxSpec as sandbox_mojom_SandboxSpec
} from '../../../../sandbox/policy/mojom/sandbox.mojom.m.js';
```

See CL https://chromium-review.googlesource.com/c/chromium/src/+/3093709
for why this change is required. Some web platform tests failed but now
pass with this CL:-

third_party\blink\tools\run_web_tests.bat -t Default wpt_internal/web-share

Bug: 1210301,1011660
Change-Id: I457bcf50ea55ea8084499c0ae3ce2c504997b941
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3098372
Reviewed-by: Ken Rockot <rockot@google.com>
Commit-Queue: Alex Gough <ajgo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#912326}
This commit is contained in:
Alex Gough
2021-08-16 20:44:15 +00:00
committed by Chromium LUCI CQ
parent e8f232c4bb
commit ed48e12492

@ -696,6 +696,11 @@ def _CollectReferencedKinds(module, all_defined_kinds):
for referenced_kind in extract_referenced_user_kinds(param.kind):
sanitized_kind = sanitize_kind(referenced_kind)
referenced_user_kinds[sanitized_kind.spec] = sanitized_kind
# Consts can reference imported enums.
for const in module.constants:
if not const.kind in mojom.PRIMITIVES:
sanitized_kind = sanitize_kind(const.kind)
referenced_user_kinds[sanitized_kind.spec] = sanitized_kind
return referenced_user_kinds