1
1
'use strict' ;
2
2
3
3
// Flags: --expose-internals
4
- // This test verifies that the binary is compiled with code cache and the
5
- // cache is used when built in modules are compiled.
4
+ // This test verifies that if the binary is compiled with code cache,
5
+ // and the cache is used when built in modules are compiled.
6
+ // Otherwise, verifies that no cache is used when compiling builtins.
6
7
7
8
require ( '../common' ) ;
8
9
const assert = require ( 'assert' ) ;
@@ -18,23 +19,36 @@ const {
18
19
compiledWithoutCache
19
20
} = require ( 'internal/bootstrap/cache' ) ;
20
21
21
- assert . strictEqual (
22
- typeof process . config . variables . node_code_cache_path ,
23
- 'string'
24
- ) ;
25
-
26
- assert . deepStrictEqual ( compiledWithoutCache , [ ] ) ;
27
-
28
22
const loadedModules = process . moduleLoadList
29
23
. filter ( ( m ) => m . startsWith ( 'NativeModule' ) )
30
24
. map ( ( m ) => m . replace ( 'NativeModule ' , '' ) ) ;
31
25
32
- for ( const key of loadedModules ) {
33
- assert ( compiledWithCache . includes ( key ) ,
34
- `"${ key } " should've been compiled with code cache` ) ;
35
- }
26
+ // The binary is not configured with code cache, verifies that the builtins
27
+ // are all compiled without cache and we are doing the bookkeeping right.
28
+ if ( process . config . variables . node_code_cache_path === undefined ) {
29
+ assert . deepStrictEqual ( compiledWithCache , [ ] ) ;
30
+ assert . notStrictEqual ( compiledWithoutCache . length , 0 ) ;
31
+
32
+ for ( const key of loadedModules ) {
33
+ assert ( compiledWithoutCache . includes ( key ) ,
34
+ `"${ key } " should not have been compiled with code cache` ) ;
35
+ }
36
36
37
- for ( const key of cachableBuiltins ) {
38
- assert ( isUint8Array ( codeCache [ key ] ) && codeCache [ key ] . length > 0 ,
39
- `Code cache for "${ key } " should've been generated` ) ;
37
+ } else {
38
+ // The binary is configured with code cache.
39
+ assert . strictEqual (
40
+ typeof process . config . variables . node_code_cache_path ,
41
+ 'string'
42
+ ) ;
43
+ assert . deepStrictEqual ( compiledWithoutCache , [ ] ) ;
44
+
45
+ for ( const key of loadedModules ) {
46
+ assert ( compiledWithCache . includes ( key ) ,
47
+ `"${ key } " should've been compiled with code cache` ) ;
48
+ }
49
+
50
+ for ( const key of cachableBuiltins ) {
51
+ assert ( isUint8Array ( codeCache [ key ] ) && codeCache [ key ] . length > 0 ,
52
+ `Code cache for "${ key } " should've been generated` ) ;
53
+ }
40
54
}
0 commit comments