-
Notifications
You must be signed in to change notification settings - Fork 471
/
Copy pathfinalizer_order.js
98 lines (83 loc) · 3.8 KB
/
finalizer_order.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
'use strict';
/* eslint-disable no-unused-vars */
const assert = require('assert');
const common = require('./common');
const testUtil = require('./testUtil');
module.exports = require('./common').runTest(test);
function test (binding) {
const { isExperimental } = binding;
let isCallbackCalled = false;
const tests = [
'Finalizer Order - ObjectWrap',
() => {
let test = new binding.finalizer_order.Test(() => { isCallbackCalled = true; });
test = null;
global.gc();
if (isExperimental) {
assert.strictEqual(binding.finalizer_order.Test.isBasicFinalizerCalled, true, 'Expected basic finalizer to be called [before ticking]');
assert.strictEqual(binding.finalizer_order.Test.isFinalizerCalled, false, 'Expected (extended) finalizer to not be called [before ticking]');
assert.strictEqual(isCallbackCalled, false, 'Expected callback to not be called [before ticking]');
} else {
assert.strictEqual(binding.finalizer_order.Test.isBasicFinalizerCalled, false, 'Expected basic finalizer to not be called [before ticking]');
assert.strictEqual(binding.finalizer_order.Test.isFinalizerCalled, false, 'Expected (extended) finalizer to not be called [before ticking]');
assert.strictEqual(isCallbackCalled, false, 'Expected callback to not be called [before ticking]');
}
},
() => {
assert.strictEqual(binding.finalizer_order.Test.isBasicFinalizerCalled, true, 'Expected basic finalizer to be called [after ticking]');
assert.strictEqual(binding.finalizer_order.Test.isFinalizerCalled, true, 'Expected (extended) finalizer to be called [after ticking]');
assert.strictEqual(isCallbackCalled, true, 'Expected callback to be called [after ticking]');
},
'Finalizer Order - External with Basic Finalizer',
() => {
let ext = binding.finalizer_order.createExternalBasicFinalizer();
ext = null;
global.gc();
if (isExperimental) {
assert.strictEqual(binding.finalizer_order.isExternalBasicFinalizerCalled(), true, 'Expected External basic finalizer to be called [before ticking]');
} else {
assert.strictEqual(binding.finalizer_order.isExternalBasicFinalizerCalled(), false, 'Expected External basic finalizer to not be called [before ticking]');
}
},
() => {
assert.strictEqual(binding.finalizer_order.isExternalBasicFinalizerCalled(), true, 'Expected External basic finalizer to be called [after ticking]');
},
'Finalizer Order - External with Finalizer',
() => {
let ext = binding.finalizer_order.createExternalFinalizer();
ext = null;
global.gc();
assert.strictEqual(binding.finalizer_order.isExternalFinalizerCalled(), false, 'Expected External extended finalizer to not be called [before ticking]');
},
() => {
assert.strictEqual(binding.finalizer_order.isExternalFinalizerCalled(), true, 'Expected External extended finalizer to be called [after ticking]');
}
];
if (binding.isExperimental) {
tests.push(...[
'PostFinalizer',
() => {
binding.finalizer_order.PostFinalizer(common.mustCall());
},
'PostFinalizerWithData',
() => {
const data = {};
const callback = (callbackData) => {
assert.strictEqual(callbackData, data);
};
binding.finalizer_order.PostFinalizerWithData(common.mustCall(callback), data);
},
'PostFinalizerWithDataAndHint',
() => {
const data = {};
const hint = {};
const callback = (callbackData, callbackHint) => {
assert.strictEqual(callbackData, data);
assert.strictEqual(callbackHint, hint);
};
binding.finalizer_order.PostFinalizerWithDataAndHint(common.mustCall(callback), data, hint);
}
]);
}
return testUtil.runGCTests(tests);
}