* @ngdoc method * @name $sceDelegate#trustAs * * @description * Returns a trusted representation of the parameter for the specified context. This trusted * object will later on be used as-is, without any security check, by bindings or directives * that require this secu
(type, trustedValue)
| 19669 | * @return {*} A trusted representation of value, that can be used in the given context. |
| 19670 | */ |
| 19671 | function trustAs(type, trustedValue) { |
| 19672 | var Constructor = (byType.hasOwnProperty(type) ? byType[type] : null); |
| 19673 | if (!Constructor) { |
| 19674 | throw $sceMinErr('icontext', |
| 19675 | 'Attempted to trust a value in invalid context. Context: {0}; Value: {1}', |
| 19676 | type, trustedValue); |
| 19677 | } |
| 19678 | if (trustedValue === null || isUndefined(trustedValue) || trustedValue === '') { |
| 19679 | return trustedValue; |
| 19680 | } |
| 19681 | // All the current contexts in SCE_CONTEXTS happen to be strings. In order to avoid trusting |
| 19682 | // mutable objects, we ensure here that the value passed in is actually a string. |
| 19683 | if (typeof trustedValue !== 'string') { |
| 19684 | throw $sceMinErr('itype', |
| 19685 | 'Attempted to trust a non-string value in a content requiring a string: Context: {0}', |
| 19686 | type); |
| 19687 | } |
| 19688 | return new Constructor(trustedValue); |
| 19689 | } |
| 19690 | |
| 19691 | /** |
| 19692 | * @ngdoc method |
no test coverage detected