Skip to content

Commit 2f7de8e

Browse files
authored
Update support for dynamic code compilation (#464)
Move checks to ensure the args are trusted to TT spec from Ecmascript proposal
1 parent 075e1f8 commit 2f7de8e

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

spec/index.bs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ a string |value| and a list |arguments|, execute the following steps:
973973
1. Let |trustedObject| be a new instance of an interface with a type
974974
name |trustedTypeName|, with its `[[Data]]` internal slot value
975975
set to |dataString|.
976-
1. If |trustedObject| is a {{TrustedScript}}, set its `[[HostDefinedCodeLike]]` internal slot value to the value in its `[[Data]]` slot.
976+
1. If |trustedObject| is a {{TrustedScript}}, set its `[[HostDefinedIsCodeLike]]` internal slot value to `true`.
977977

978978
Note: This adds an integration point with [dynamic-code-brand-checks proposal](https://tc39.es/proposal-dynamic-code-brand-checks/).
979979
1. Return |trustedObject|.
@@ -1061,7 +1061,7 @@ Given a {{TrustedType}} type (|expectedType|), a [=realm/global object=] (|globa
10611061
1. Let |trustedObject| be a new instance of an interface with a type
10621062
name |trustedTypeName|, with its `[[Data]]` internal slot value
10631063
set to |dataString|.
1064-
1. If |trustedObject| is a {{TrustedScript}}, set its `[[HostDefinedCodeLike]]` internal slot value to the value in its `[[Data]]` slot.
1064+
1. If |trustedObject| is a {{TrustedScript}}, set its `[[HostDefinedIsCodeLike]]` internal slot value to `true`.
10651065

10661066
Note: This adds an integration point with [dynamic-code-brand-checks proposal](https://tc39.es/proposal-dynamic-code-brand-checks/).
10671067
1. Return |trustedObject|.
@@ -1749,14 +1749,24 @@ The Trusted Types portion of this algorithm uses |calleeRealm| and its CSP setti
17491749
</pre>
17501750
</div>
17511751

1752-
Given a [[ECMA-262#realm|realm]] (|calleeRealm|), a list of strings (|parameterStrings|), a string (|bodyString|), <ins> a string (|source|), an enum (|compilationType|), and a boolean |wasCodeLike|</ins>, this algorithm returns normally if compilation is allowed, and
1752+
Given a [[ECMA-262#realm|realm]] (|calleeRealm|), a list of strings (|parameterStrings|), a string (|bodyString|), <ins> a string (|source|), an enum (|compilationType|), a list of ECMAScript language values (|parameterArgs|), and an ECMAScript language value (|bodyArg|), this algorithm returns normally if compilation is allowed, and
17531753
throws an "`EvalError`" if not:
17541754

1755-
1. <ins>If |wasCodeLike| is true, let |sourceToValidate| be a new instance of
1755+
1. <ins>Let |compilationSink| be `"Function"` if |compilationType| is `*FUNCTION*`, otherwise `"Eval"`.</ins>
1756+
1. <ins>Let |isTrusted| be `true`.</ins>
1757+
1. <ins>If |bodyArg| is not a {{TrustedScript}} object, set |isTrusted| to `false`.</ins>
1758+
1. <ins>If |isTrusted| is `true` then:
1759+
1. <ins>If |bodyString| is not equal to |bodyArg|'s `[[Data]]` internal slot, set |isTrusted| to `false`.</ins>
1760+
1. <ins>If |isTrusted| is `true`, then:</ins>
1761+
1. <ins> For each |arg| in |parameterArgs|:</ins>
1762+
1. <ins>Let |index| be the index of |arg| in |parameterArgs|.</ins>
1763+
1. <ins>If |arg| is not a {{TrustedScript}} object, set |isTrusted| to `false`.</ins>
1764+
1. <ins>If |isTrusted| is `true`, then:</ins>
1765+
1. <ins>if |parameterStrings|[|index|] is not equal to |arg|'s `[[Data]]` internal slot, set |isTrusted| to `false`.</ins>
1766+
1. <ins>If |isTrusted| is `true`, let |sourceToValidate| be a new instance of
17561767
the {{TrustedScript}} interface, with its `[[Data]]` internal slot value
17571768
set to |source|. Otherwise, let |sourceToValidate| be |source|.</ins>
17581769

1759-
1. <ins>Let |compilationSink| be `"Function"` if |compilationType| is `*FUNCTION*`, otherwise `"Eval"`.</ins>
17601770
1. <ins>Let |sourceString| be the result of executing the
17611771
[$Get Trusted Type compliant string$] algorithm, with:
17621772
* |calleeRealm| as |global|,

0 commit comments

Comments
 (0)