Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/lru-cache/index.js')
-rw-r--r--node_modules/lru-cache/index.js52
1 files changed, 40 insertions, 12 deletions
diff --git a/node_modules/lru-cache/index.js b/node_modules/lru-cache/index.js
index b63be6e98..fb1a076fa 100644
--- a/node_modules/lru-cache/index.js
+++ b/node_modules/lru-cache/index.js
@@ -1,15 +1,46 @@
const perf = typeof performance === 'object' && performance &&
typeof performance.now === 'function' ? performance : Date
-const hasAbortController = typeof AbortController !== 'undefined'
+const hasAbortController = typeof AbortController === 'function'
// minimal backwards-compatibility polyfill
+// this doesn't have nearly all the checks and whatnot that
+// actual AbortController/Signal has, but it's enough for
+// our purposes, and if used properly, behaves the same.
const AC = hasAbortController ? AbortController : Object.assign(
class AbortController {
constructor () { this.signal = new AC.AbortSignal }
- abort () { this.signal.aborted = true }
+ abort () {
+ this.signal.dispatchEvent('abort')
+ }
},
- { AbortSignal: class AbortSignal { constructor () { this.aborted = false }}}
+ {
+ AbortSignal: class AbortSignal {
+ constructor () {
+ this.aborted = false
+ this._listeners = []
+ }
+ dispatchEvent (type) {
+ if (type === 'abort') {
+ this.aborted = true
+ const e = { type, target: this }
+ this.onabort(e)
+ this._listeners.forEach(f => f(e), this)
+ }
+ }
+ onabort () {}
+ addEventListener (ev, fn) {
+ if (ev === 'abort') {
+ this._listeners.push(fn)
+ }
+ }
+ removeEventListener (ev, fn) {
+ if (ev === 'abort') {
+ this._listeners = this._listeners.filter(f => f !== fn)
+ }
+ }
+ }
+ }
)
const warned = new Set()
@@ -306,15 +337,6 @@ class LRUCache {
}
this.calculatedSize += this.sizes[index]
}
- this.delete = k => {
- if (this.size !== 0) {
- const index = this.keyMap.get(k)
- if (index !== undefined) {
- this.calculatedSize -= this.sizes[index]
- }
- }
- return LRUCache.prototype.delete.call(this, k)
- }
}
removeItemSize (index) {}
addItemSize (index, v, k, size) {}
@@ -730,6 +752,7 @@ class LRUCache {
deprecatedMethod('del', 'delete')
return this.delete
}
+
delete (k) {
let deleted = false
if (this.size !== 0) {
@@ -809,6 +832,7 @@ class LRUCache {
}
}
}
+
get reset () {
deprecatedMethod('reset', 'clear')
return this.clear
@@ -818,6 +842,10 @@ class LRUCache {
deprecatedProperty('length', 'size')
return this.size
}
+
+ static get AbortController () {
+ return AC
+ }
}
module.exports = LRUCache