all files / lib/resolver/ sealing.js

100% Statements 6/6
100% Branches 2/2
100% Functions 1/1
100% Lines 6/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21                             
"use strict";
 
var ResolutionError = require('../ResolutionError');
 
/**
 * After the next resolvers are invoked, use <code>Object.seal</code> to make the resolved
 * instance properties non-deletable. This resolver does not operate on the component to avoid the possibility
 * of sealing it due to misconfiguration.
 *
 * @function
 * @exports Resolver:sealing
 */
module.exports = function sealing(ctx, res) {
  var inst = res.instance(true);
  if (inst === ctx.component()) {
    throw new ResolutionError("sealing resolver cannot seal the component itself, only instances");
  }
 
  res.resolve(Object.seal(res.instance()));
};