1 | 'use strict';
|
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');
|
6 |
|
7 |
|
8 |
|
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;
|
13 | aFunction(callback);
|
14 | var isPresentInMap = map.has(key);
|
15 | if (!isPresentInMap && length < 3) {
|
16 | throw TypeError('Updating absent value');
|
17 | }
|
18 | var value = isPresentInMap ? map.get(key) : aFunction(length > 2 ? arguments[2] : undefined)(key, map);
|
19 | map.set(key, callback(value, key, map));
|
20 | return map;
|
21 | }
|
22 | });
|