|
9 | 9 | ArrayPrototypeSplice, |
10 | 10 | ObjectDefineProperty, |
11 | 11 | PromisePrototypeCatch, |
12 | | - globalThis: { Atomics }, |
| 12 | + globalThis: { |
| 13 | + Atomics, |
| 14 | + SharedArrayBuffer |
| 15 | + }, |
13 | 16 | } = primordials; |
14 | 17 |
|
15 | 18 | const { |
@@ -135,21 +138,23 @@ port.on('message', (message) => { |
135 | 138 |
|
136 | 139 | require('internal/worker').assignEnvironmentData(environmentData); |
137 | 140 |
|
138 | | - // The counter is only passed to the workers created by the main thread, not |
139 | | - // to workers created by other workers. |
140 | | - let cachedCwd = ''; |
141 | | - let lastCounter = -1; |
142 | | - const originalCwd = process.cwd; |
143 | | - |
144 | | - process.cwd = function() { |
145 | | - const currentCounter = Atomics.load(cwdCounter, 0); |
146 | | - if (currentCounter === lastCounter) |
| 141 | + if (typeof SharedArrayBuffer !== 'undefined') { |
| 142 | + // The counter is only passed to the workers created by the main thread, |
| 143 | + // not to workers created by other workers. |
| 144 | + let cachedCwd = ''; |
| 145 | + let lastCounter = -1; |
| 146 | + const originalCwd = process.cwd; |
| 147 | + |
| 148 | + process.cwd = function() { |
| 149 | + const currentCounter = Atomics.load(cwdCounter, 0); |
| 150 | + if (currentCounter === lastCounter) |
| 151 | + return cachedCwd; |
| 152 | + lastCounter = currentCounter; |
| 153 | + cachedCwd = originalCwd(); |
147 | 154 | return cachedCwd; |
148 | | - lastCounter = currentCounter; |
149 | | - cachedCwd = originalCwd(); |
150 | | - return cachedCwd; |
151 | | - }; |
152 | | - workerIo.sharedCwdCounter = cwdCounter; |
| 155 | + }; |
| 156 | + workerIo.sharedCwdCounter = cwdCounter; |
| 157 | + } |
153 | 158 |
|
154 | 159 | const CJSLoader = require('internal/modules/cjs/loader'); |
155 | 160 | assert(!CJSLoader.hasLoadedAnyUserCJSModule); |
|
0 commit comments