* @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)
| 20314 | * @return {*} A trusted representation of value, that can be used in the given context. |
| 20315 | */ |
| 20316 | function trustAs(type, trustedValue) { |
| 20317 | var Constructor = (byType.hasOwnProperty(type) ? byType[type] : null); |
| 20318 | if (!Constructor) { |
| 20319 | throw $sceMinErr('icontext', |
| 20320 | 'Attempted to trust a value in invalid context. Context: {0}; Value: {1}', |
| 20321 | type, trustedValue); |
| 20322 | } |
| 20323 | if (trustedValue === null || isUndefined(trustedValue) || trustedValue === '') { |
| 20324 | return trustedValue; |
| 20325 | } |
| 20326 | // All the current contexts in SCE_CONTEXTS happen to be strings. In order to avoid trusting |
| 20327 | // mutable objects, we ensure here that the value passed in is actually a string. |
| 20328 | if (typeof trustedValue !== 'string') { |
| 20329 | throw $sceMinErr('itype', |
| 20330 | 'Attempted to trust a non-string value in a content requiring a string: Context: {0}', |
| 20331 | type); |
| 20332 | } |
| 20333 | return new Constructor(trustedValue); |
| 20334 | } |
| 20335 | |
| 20336 | /** |
| 20337 | * @ngdoc method |
no test coverage detected