Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 3 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /trusted-types/eval-csp-tt-default-policy-mutate.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html>
<head>
<script nonce="abc" src="/resources/testharness.js"></script>
<script nonce="abc" src="/resources/testharnessreport.js"></script>
<script nonce="abc" src="support/helper.sub.js"></script>
<meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'">
</head>
<body>
<script>
trustedTypes.createPolicy("default", {createScript: s => s.replace("1", "4")});
test(t => {
assert_throws_js(EvalError, _ => eval('1+1'));
}, "eval of string where default policy mutates value throws.");
test(t => {
assert_throws_js(EvalError, _ => eval?.('1+1'));
}, "indirect eval of string where default policy mutates value throws.");
test(t => {
assert_throws_js(EvalError, _ => new Function('return 1+1'));
}, "Function constructor with string where default policy mutates value throws.");
</script>