Skip to content

Emit instance *Trusted overloads on *TrustedTypesExtension - #607

Merged
kevmoo merged 1 commit into
mainfrom
trusted-types-extensions
Oct 30, 2026
Merged

kevmoo merged 1 commit into
mainfrom
trusted-types-extensions

Conversation

@kevmoo

@kevmoo kevmoo commented Oct 28, 2026

Copy link
Copy Markdown
Member

Move non-static *Trusted setters and methods onto companion *TrustedTypesExtension extensions so DOM extension types keep a single instance member per JS property name for @JSExport() and package:mockito, addressing review feedback on #596.

  • Names generated extensions *TrustedTypesExtension to avoid colliding with DocumentExtension and ElementExtension in lib/src/helpers/extensions.dart.
  • Keeps Worker.trusted, SharedWorker.trusted, and static Document.parseHTMLUnsafeTrusted on their extension types because @JSExport() only exports instance members and Dart extensions cannot declare constructors.

Move non-static `*Trusted` setters and methods onto companion
`*TrustedTypesExtension` extensions so DOM `extension type`s expose a
single instance member per JS property name for `@JSExport()` and
`package:mockito`.

- Name generated extensions `*TrustedTypesExtension` to avoid colliding
  with `DocumentExtension` and `ElementExtension` in
  `lib/src/helpers/extensions.dart`.
- Keep `Worker.trusted`, `SharedWorker.trusted`, and static
  `Document.parseHTMLUnsafeTrusted` on their `extension type`s.
- Add a structural `api_test` check verifying DOM extension types have
  no colliding JS instance member names.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the JS interop generator to emit Trusted Types helper methods and setters inside dedicated extension classes (e.g., *TrustedTypesExtension) rather than directly on the extension types themselves, preventing potential JS member name collisions. It also adds a test to verify that no colliding JS instance member names exist across public extension types. Feedback on the new test suggests adding a safety check in _effectiveJsName to ensure a setter's name actually ends with '=' before truncating it, preventing potential RangeError exceptions.

Comment thread web/test/api_test.dart Resolved
@natebosch

Copy link
Copy Markdown
Member

addressing review feedback on #596.

Is there also work happening on figuring out how to make this landable in google3, or handling the roll with same-cl fixes?

@kevmoo

kevmoo commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Yes — once #607 lands, I'll take ownership of the standalone Dart SDK web_rev roll and coordinated Google3 fix CL, starting by pre-migrating safe_html onto private @JS() bindings ahead of the roll. Since 2.0.0-wip narrowed both getters and external setters, a coordinated roll avoids migrating callers twice.

@kevmoo
kevmoo requested a review from srujzs October 29, 2026 17:28

@srujzs srujzs left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but iiuc, the central problem is that there are packages in google3 that rely on the JSAny-typed member, right? We can migrate the non-third_party ones, but for the ones that are rolled in, we're in a bind because this necessitates either:

  1. Publishing package:web v2 asap so the rolled-in packages can use it, and then we roll them all together into google3.
  2. Adding a patch into google3 for each package until we're ready for (1).
  3. Modifying the rolled-in packages in google3 directly (bad, because a new roll of those packages might reintroduce the problem).

Comment thread web/test/api_test.dart Resolved
@kevmoo

kevmoo commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

I'm digging in to mockito to see if IT should be fixed here.

We can land this now if it's helpful and revisit before we publish.

I kind of like the trusted bits being next to the normal bits just for readability.

@srujzs

srujzs commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

I'm digging in to mockito to see if IT should be fixed here.

I'm not sure there's a recourse here without extension members because you have two Dart definitions for one JS member. You can imagine unioning the two member types, but the issue of choosing one member definition still exists.

@kevmoo

kevmoo commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

@srujzs we HAVE a pattern for maintaining v1x and v2 – it's just a bit of a chore.

We don't really have any fixes in pkg:web that are critical for Google3, right? We could just...wait.

This seems like something we should chat about.

@kevmoo
kevmoo merged commit 45166fd into main Oct 30, 2026
27 checks passed
@kevmoo
kevmoo deleted the trusted-types-extensions branch October 30, 2026 17:48
@srujzs

srujzs commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

We don't really have any fixes in pkg:web that are critical for Google3, right? We could just...wait.

This seems like something we should chat about.

Waiting SGTM. I guess we might want helpers here to then be rolled into google3 and that might complicate things.

@kevmoo

kevmoo commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

@srujzs we can also move the "new" work into a long-lived branch and just do an (ugly) revert commit if we want to keep history clean and move in smaller changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants