function getTrusted(type, maybeTrusted) {
      if (maybeTrusted === null || isUndefined(maybeTrusted) || maybeTrusted === '') {
        return maybeTrusted;
      }
      var constructor = (byType.hasOwnProperty(type) ? byType[type] : null);
      // If maybeTrusted is a trusted class instance or subclass instance, then unwrap and return
      // as-is.
      if (constructor && maybeTrusted instanceof constructor) {
        return maybeTrusted.$$unwrapTrustedValue();
      }
      // Otherwise, if we get here, then we may either make it safe, or throw an exception. This
      // depends on the context: some are sanitizatible (HTML), some use whitelists (RESOURCE_URL),
      // some are impossible to do (JS). This step isn't implemented for CSS and URL, as AngularJS
      // has no corresponding sinks.
      if (type === SCE_CONTEXTS.RESOURCE_URL) {
        // RESOURCE_URL uses a whitelist.
        if (isResourceUrlAllowedByPolicy(maybeTrusted)) {
          return maybeTrusted;
        } else {
          throw $sceMinErr('insecurl',
              'Blocked loading resource from url not allowed by $sceDelegate policy.  URL: {0}',
              maybeTrusted.toString());
        }
      } else if (type === SCE_CONTEXTS.HTML) {
        // htmlSanitizer throws its own error when no sanitizer is available.
        return htmlSanitizer(maybeTrusted);
      }
      // Default error when the $sce service has no way to make the input safe.
      throw $sceMinErr('unsafe', 'Attempting to use an unsafe value in a safe context.');
    }
@ngdoc method
@name $sceDelegate#getTrusted

@description
Takes any input, and either returns a value that's safe to use in the specified context, or
throws an exception.

In practice, there are several cases. When given a string, this function runs checks
and sanitization to make it safe without prior assumptions. When given the result of a {@link
ng.$sceDelegate#trustAs `$sceDelegate.trustAs`} call, it returns the originally supplied
value if that value's context is valid for this call's context. Finally, this function can
also throw when there is no way to turn `maybeTrusted` in a safe value (e.g., no sanitization
is available or possible.)

@param {string} type The context in which this value is to be used (such as `$sce.HTML`).
@param {*} maybeTrusted The result of a prior {@link ng.$sceDelegate#trustAs
    `$sceDelegate.trustAs`} call, or anything else (which will not be considered trusted.)
@return {*} A version of the value that's safe to use in the given context, or throws an
    exception if this is impossible.