@@ -9,64 +9,79 @@ const test_reference = require(`./build/${common.buildType}/test_reference`);
9
9
// This test script uses external values with finalizer callbacks
10
10
// in order to track when values get garbage-collected. Each invocation
11
11
// of a finalizer callback increments the finalizeCount property.
12
- assert . strictEqual ( 0 , test_reference . finalizeCount ) ;
12
+ assert . strictEqual ( test_reference . finalizeCount , 0 ) ;
13
13
14
- // External value without a finalizer
15
- let value = test_reference . createExternal ( ) ;
16
- assert . strictEqual ( typeof value , 'object' ) ;
17
- test_reference . checkExternal ( value ) ;
18
- value = null ;
19
- global . gc ( ) ;
20
- assert . strictEqual ( 0 , test_reference . finalizeCount ) ;
14
+ {
15
+ // External value without a finalizer
16
+ let value = test_reference . createExternal ( ) ;
17
+ assert . strictEqual ( test_reference . finalizeCount , 0 ) ;
18
+ assert . strictEqual ( typeof value , 'object' ) ;
19
+ test_reference . checkExternal ( value ) ;
20
+ value = null ;
21
+ global . gc ( ) ;
22
+ assert . strictEqual ( test_reference . finalizeCount , 0 ) ;
23
+ }
21
24
22
- // External value with a finalizer
23
- value = test_reference . createExternalWithFinalize ( ) ;
24
- assert . strictEqual ( typeof value , 'object' ) ;
25
- test_reference . checkExternal ( value ) ;
26
- value = null ;
27
- global . gc ( ) ;
28
- assert . strictEqual ( 1 , test_reference . finalizeCount ) ;
25
+ {
26
+ // External value with a finalizer
27
+ let value = test_reference . createExternalWithFinalize ( ) ;
28
+ assert . strictEqual ( test_reference . finalizeCount , 0 ) ;
29
+ assert . strictEqual ( typeof value , 'object' ) ;
30
+ test_reference . checkExternal ( value ) ;
31
+ value = null ;
32
+ global . gc ( ) ;
33
+ assert . strictEqual ( test_reference . finalizeCount , 1 ) ;
34
+ }
29
35
30
- // Weak reference
31
- value = test_reference . createExternalWithFinalize ( ) ;
32
- test_reference . createReference ( value , 0 ) ;
33
- assert . strictEqual ( test_reference . referenceValue , value ) ;
34
- value = null ;
35
- global . gc ( ) ; // Value should be GC'd because there is only a weak ref
36
- assert . strictEqual ( test_reference . referenceValue , undefined ) ;
37
- assert . strictEqual ( 2 , test_reference . finalizeCount ) ;
38
- test_reference . deleteReference ( ) ;
36
+ {
37
+ // Weak reference
38
+ let value = test_reference . createExternalWithFinalize ( ) ;
39
+ assert . strictEqual ( test_reference . finalizeCount , 0 ) ;
40
+ test_reference . createReference ( value , 0 ) ;
41
+ assert . strictEqual ( test_reference . referenceValue , value ) ;
42
+ value = null ;
43
+ global . gc ( ) ; // Value should be GC'd because there is only a weak ref
44
+ assert . strictEqual ( test_reference . referenceValue , undefined ) ;
45
+ assert . strictEqual ( test_reference . finalizeCount , 1 ) ;
46
+ test_reference . deleteReference ( ) ;
47
+ }
39
48
40
- // Strong reference
41
- value = test_reference . createExternalWithFinalize ( ) ;
42
- test_reference . createReference ( value , 1 ) ;
43
- assert . strictEqual ( test_reference . referenceValue , value ) ;
44
- value = null ;
45
- global . gc ( ) ; // Value should NOT be GC'd because there is a strong ref
46
- assert . strictEqual ( 2 , test_reference . finalizeCount ) ;
47
- test_reference . deleteReference ( ) ;
48
- global . gc ( ) ; // Value should be GC'd because the strong ref was deleted
49
- assert . strictEqual ( 3 , test_reference . finalizeCount ) ;
49
+ {
50
+ // Strong reference
51
+ let value = test_reference . createExternalWithFinalize ( ) ;
52
+ assert . strictEqual ( test_reference . finalizeCount , 0 ) ;
53
+ test_reference . createReference ( value , 1 ) ;
54
+ assert . strictEqual ( test_reference . referenceValue , value ) ;
55
+ value = null ;
56
+ global . gc ( ) ; // Value should NOT be GC'd because there is a strong ref
57
+ assert . strictEqual ( test_reference . finalizeCount , 0 ) ;
58
+ test_reference . deleteReference ( ) ;
59
+ global . gc ( ) ; // Value should be GC'd because the strong ref was deleted
60
+ assert . strictEqual ( test_reference . finalizeCount , 1 ) ;
61
+ }
50
62
51
- // Strong reference, increment then decrement to weak reference
52
- value = test_reference . createExternalWithFinalize ( ) ;
53
- test_reference . createReference ( value , 1 ) ;
54
- value = null ;
55
- global . gc ( ) ; // Value should NOT be GC'd because there is a strong ref
56
- assert . strictEqual ( 3 , test_reference . finalizeCount ) ;
63
+ {
64
+ // Strong reference, increment then decrement to weak reference
65
+ let value = test_reference . createExternalWithFinalize ( ) ;
66
+ assert . strictEqual ( test_reference . finalizeCount , 0 ) ;
67
+ test_reference . createReference ( value , 1 ) ;
68
+ value = null ;
69
+ global . gc ( ) ; // Value should NOT be GC'd because there is a strong ref
70
+ assert . strictEqual ( test_reference . finalizeCount , 0 ) ;
57
71
58
- assert . strictEqual ( test_reference . incrementRefcount ( ) , 2 ) ;
59
- global . gc ( ) ; // Value should NOT be GC'd because there is a strong ref
60
- assert . strictEqual ( 3 , test_reference . finalizeCount ) ;
72
+ assert . strictEqual ( test_reference . incrementRefcount ( ) , 2 ) ;
73
+ global . gc ( ) ; // Value should NOT be GC'd because there is a strong ref
74
+ assert . strictEqual ( test_reference . finalizeCount , 0 ) ;
61
75
62
- assert . strictEqual ( test_reference . decrementRefcount ( ) , 1 ) ;
63
- global . gc ( ) ; // Value should NOT be GC'd because there is a strong ref
64
- assert . strictEqual ( 3 , test_reference . finalizeCount ) ;
76
+ assert . strictEqual ( test_reference . decrementRefcount ( ) , 1 ) ;
77
+ global . gc ( ) ; // Value should NOT be GC'd because there is a strong ref
78
+ assert . strictEqual ( test_reference . finalizeCount , 0 ) ;
65
79
66
- assert . strictEqual ( test_reference . decrementRefcount ( ) , 0 ) ;
67
- global . gc ( ) ; // Value should be GC'd because the ref is now weak!
68
- assert . strictEqual ( 4 , test_reference . finalizeCount ) ;
80
+ assert . strictEqual ( test_reference . decrementRefcount ( ) , 0 ) ;
81
+ global . gc ( ) ; // Value should be GC'd because the ref is now weak!
82
+ assert . strictEqual ( test_reference . finalizeCount , 1 ) ;
69
83
70
- test_reference . deleteReference ( ) ;
71
- global . gc ( ) ; // Value was already GC'd
72
- assert . strictEqual ( 4 , test_reference . finalizeCount ) ;
84
+ test_reference . deleteReference ( ) ;
85
+ global . gc ( ) ; // Value was already GC'd
86
+ assert . strictEqual ( test_reference . finalizeCount , 1 ) ;
87
+ }
0 commit comments