2 var $ = require('../internals/export');
3 var IS_PURE = require('../internals/is-pure');
4 var anObject = require('../internals/an-object');
5 var aFunction = require('../internals/a-function');
7 // `Set.prototype.update` method
8 // https://github.com/tc39/proposal-collection-methods
9 $({ target: 'Map', proto: true, real: true, forced: IS_PURE }, {
10 update: function update(key, callback /* , thunk */) {
11 var map = anObject(this);
12 var length = arguments.length;
14 var isPresentInMap = map.has(key);
15 if (!isPresentInMap && length < 3) {
16 throw TypeError('Updating absent value');
18 var value = isPresentInMap ? map.get(key) : aFunction(length > 2 ? arguments[2] : undefined)(key, map);
19 map.set(key, callback(value, key, map));