-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimplementation.js
More file actions
38 lines (26 loc) · 1.02 KB
/
implementation.js
File metadata and controls
38 lines (26 loc) · 1.02 KB
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
'use strict';
var callBind = require('call-bind');
var $TypeError = require('es-errors/type');
var Call = require('es-abstract/2025/Call');
var CanonicalizeKeyedCollectionKey = require('./aos/CanonicalizeKeyedCollectionKey');
var IsCallable = require('es-abstract/2025/IsCallable');
var $Map = require('es-map/polyfill')();
var $mapHas = callBind($Map.prototype.has);
var $mapGet = callBind($Map.prototype.get);
var $mapSet = callBind($Map.prototype.set);
module.exports = function getOrInsertComputed(key, callbackfn) {
var M = this; // step 1
// 2. Perform ? RequireInternalSlot(M, [[MapData]]).
$mapHas(M); // step 2
if (!IsCallable(callbackfn)) {
throw new $TypeError('callbackfn must be a function'); // step 3
}
// eslint-disable-next-line no-param-reassign
key = CanonicalizeKeyedCollectionKey(key); // step 4
if ($mapHas(M, key)) { // step 5
return $mapGet(M, key); // step 5.a
}
var value = Call(callbackfn, void undefined, [key]); // step 6
$mapSet(M, key, value); // steps 8 - 10
return value; // step 11
};