All files / engine/Source/Scene ResourceLoader.js

95% Statements 19/20
100% Branches 6/6
87.5% Functions 7/8
95% Lines 19/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128                                          1x                         1x                   1x 1x             1x                 1x                         1x   81x     80x 73x     80x 80x 79x     80x                           1x 47148x                                   1x 19762x 19762x        
import Check from "../Core/Check.js";
import defined from "../Core/defined.js";
import destroyObject from "../Core/destroyObject.js";
import DeveloperError from "../Core/DeveloperError.js";
import RuntimeError from "../Core/RuntimeError.js";
 
/**
 * A cache resource.
 * <p>
 * This type describes an interface and is not intended to be instantiated directly.
 * </p>
 *
 * @alias ResourceLoader
 * @constructor
 *
 * @see ResourceCache
 *
 * @private
 */
function ResourceLoader() {}
 
Object.defineProperties(ResourceLoader.prototype, {
  /**
   * The cache key of the resource.
   *
   * @memberof ResourceLoader.prototype
   *
   * @type {string}
   * @readonly
   * @private
   */
  cacheKey: {
    // eslint-disable-next-line getter-return
    get: function () {
      DeveloperError.throwInstantiationError();
    },
  },
});
 
/**
 * Loads the resource.
 * @returns {Promise<ResourceLoader>} A promise which resolves to the loader when the resource loading is completed.
 * @private
 */
ResourceLoader.prototype.load = function () {
  DeveloperError.throwInstantiationError();
};
 
/**
 * Unloads the resource.
 * @private
 */
ResourceLoader.prototype.unload = function () {};
 
/**
 * Processes the resource until it becomes ready.
 *
 * @param {FrameState} frameState The frame state.
 * @returns {boolean} true once all resourced are ready.
 * @private
 */
ResourceLoader.prototype.process = function (frameState) {
  return false;
};
 
/**
 * Constructs a {@link RuntimeError} from an errorMessage and an error.
 *
 * @param {string} errorMessage The error message.
 * @param {Error} [error] The error.
 *
 * @returns {RuntimeError} The runtime error.
 * @private
 */
ResourceLoader.prototype.getError = function (errorMessage, error) {
  //>>includeStart('debug', pragmas.debug);
  Check.typeOf.string("errorMessage", errorMessage);
  //>>includeEnd('debug');
 
  if (defined(error) && defined(error.message)) {
    errorMessage += `\n${error.message}`;
  }
 
  const runtimeError = new RuntimeError(errorMessage);
  if (defined(error)) {
    runtimeError.stack = `Original stack:\n${error.stack}\nHandler stack:\n${runtimeError.stack}`;
  }
 
  return runtimeError;
};
 
/**
 * Returns true if this object was destroyed; otherwise, false.
 * <br /><br />
 * If this object was destroyed, it should not be used; calling any function other than
 * <code>isDestroyed</code> will result in a {@link DeveloperError} exception.
 *
 * @returns {boolean} <code>true</code> if this object was destroyed; otherwise, <code>false</code>.
 *
 * @see ResourceLoader#destroy
 * @private
 */
ResourceLoader.prototype.isDestroyed = function () {
  return false;
};
 
/**
 * Destroys the loaded resource.
 * <br /><br />
 * Once an object is destroyed, it should not be used; calling any function other than
 * <code>isDestroyed</code> will result in a {@link DeveloperError} exception.  Therefore,
 * assign the return value (<code>undefined</code>) to the object as done in the example.
 *
 * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
 *
 * @example
 * resourceLoader = resourceLoader && resourceLoader.destroy();
 *
 * @see ResourceLoader#isDestroyed
 * @private
 */
ResourceLoader.prototype.destroy = function () {
  this.unload();
  return destroyObject(this);
};
 
export default ResourceLoader;