Skip to content

Conversation

@hamishwillee
Copy link
Collaborator

@hamishwillee hamishwillee commented Dec 19, 2025

The Function() constructor can execute its arguments as JavaScript.
Similarly eval() executes its input as JavaScript.

This updates the TrustedType information for both methods.

Note, I provided an example for eval() but not Function. I wasn't sure if I should do either, because even though this is notionally safer than not using trusted types, there is really no direction on how you can practically and generically transform a script so that it is safe.

For the eval() case I just indicated the use of custom transforming function, for which I provided no implementation. For Function, I added a disclaimer and linked to the eval() example.

Related docs work tracked in #41507

@hamishwillee hamishwillee requested a review from a team as a code owner December 19, 2025 05:57
@hamishwillee hamishwillee requested review from Josh-Cena and wbamberg and removed request for a team December 19, 2025 05:57
@github-actions github-actions bot added Content:JS JavaScript docs size/m [PR only] 51-500 LoC changed labels Dec 19, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 19, 2025

@hamishwillee hamishwillee changed the title TrustedTypes: Function() constructor TrustedTypes: Function() constructor + eval() Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:JS JavaScript docs size/m [PR only] 51-500 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant