|
| 1 | +const policy = trustedTypes.createPolicy("dummy", { createScript: x => x }); |
| 2 | + |
| 3 | +const AsyncFunction = async function() {}.constructor; |
| 4 | +const GeneratorFunction = function*() {}.constructor; |
| 5 | +const AsyncGeneratorFunction = async function*() {}.constructor; |
| 6 | + |
| 7 | +const input = `return${';'.repeat(100)}`; |
| 8 | +[Function, AsyncFunction, GeneratorFunction, AsyncGeneratorFunction].forEach(functionConstructor => { |
| 9 | + promise_test(async t => { |
| 10 | + await no_trusted_type_violation_for(_ => |
| 11 | + new functionConstructor(policy.createScript(input)) |
| 12 | + ); |
| 13 | + }, `No violation reported for ${functionConstructor.name} with TrustedScript.`); |
| 14 | + |
| 15 | + promise_test(async t => { |
| 16 | + await no_trusted_type_violation_for(_ => |
| 17 | + new functionConstructor(policy.createScript('a'), policy.createScript(input)) |
| 18 | + ); |
| 19 | + }, `No violation reported for ${functionConstructor.name} with multiple TrustedScript args.`); |
| 20 | + |
| 21 | + promise_test(async t => { |
| 22 | + let violation = await trusted_type_violation_for(EvalError, _ => |
| 23 | + new functionConstructor(input) |
| 24 | + ); |
| 25 | + assert_true(violation.originalPolicy.includes("require-trusted-types-for 'script'")); |
| 26 | + assert_equals(violation.blockedURI, "trusted-types-sink"); |
| 27 | + assert_equals(violation.sample, `Function|${clipSampleIfNeeded(`(\n) {\n${input}\n}`)}`); |
| 28 | + }, `Violation report for ${functionConstructor.name} with plain string.`); |
| 29 | +}); |
0 commit comments