main
Last change
on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | 'use strict'
|
---|
2 |
|
---|
3 | /* istanbul ignore file: only for Node 12 */
|
---|
4 |
|
---|
5 | const { kConnected, kSize } = require('../core/symbols')
|
---|
6 |
|
---|
7 | class CompatWeakRef {
|
---|
8 | constructor (value) {
|
---|
9 | this.value = value
|
---|
10 | }
|
---|
11 |
|
---|
12 | deref () {
|
---|
13 | return this.value[kConnected] === 0 && this.value[kSize] === 0
|
---|
14 | ? undefined
|
---|
15 | : this.value
|
---|
16 | }
|
---|
17 | }
|
---|
18 |
|
---|
19 | class CompatFinalizer {
|
---|
20 | constructor (finalizer) {
|
---|
21 | this.finalizer = finalizer
|
---|
22 | }
|
---|
23 |
|
---|
24 | register (dispatcher, key) {
|
---|
25 | if (dispatcher.on) {
|
---|
26 | dispatcher.on('disconnect', () => {
|
---|
27 | if (dispatcher[kConnected] === 0 && dispatcher[kSize] === 0) {
|
---|
28 | this.finalizer(key)
|
---|
29 | }
|
---|
30 | })
|
---|
31 | }
|
---|
32 | }
|
---|
33 | }
|
---|
34 |
|
---|
35 | module.exports = function () {
|
---|
36 | // FIXME: remove workaround when the Node bug is fixed
|
---|
37 | // https://github.com/nodejs/node/issues/49344#issuecomment-1741776308
|
---|
38 | if (process.env.NODE_V8_COVERAGE) {
|
---|
39 | return {
|
---|
40 | WeakRef: CompatWeakRef,
|
---|
41 | FinalizationRegistry: CompatFinalizer
|
---|
42 | }
|
---|
43 | }
|
---|
44 | return {
|
---|
45 | WeakRef: global.WeakRef || CompatWeakRef,
|
---|
46 | FinalizationRegistry: global.FinalizationRegistry || CompatFinalizer
|
---|
47 | }
|
---|
48 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.