2 var call = require('../internals/function-call');
3 var aCallable = require('../internals/a-callable');
4 var anObject = require('../internals/an-object');
6 // `Map.prototype.emplace` method
7 // https://github.com/thumbsupep/proposal-upsert
8 module.exports = function emplace(key, handler) {
9 var map = anObject(this);
10 var get = aCallable(map.get);
11 var has = aCallable(map.has);
12 var set = aCallable(map.set);
13 var value = (call(has, map, key) && 'update' in handler)
14 ? handler.update(call(get, map, key), key, map)
15 : handler.insert(key, map);
16 call(set, map, key, value);