|
3 | 3 | const {
|
4 | 4 | NumberParseInt,
|
5 | 5 | ObjectDefineProperty,
|
| 6 | + ObjectGetOwnPropertyDescriptor, |
6 | 7 | SafeMap,
|
7 | 8 | SafeWeakMap,
|
8 | 9 | StringPrototypeStartsWith,
|
@@ -36,6 +37,7 @@ function prepareMainThreadExecution(expandArgv1 = false) {
|
36 | 37 | setupInspectorHooks();
|
37 | 38 | setupWarningHandler();
|
38 | 39 | setupFetch();
|
| 40 | + setupWebCrypto(); |
39 | 41 |
|
40 | 42 | // Resolve the coverage directory to an absolute path, and
|
41 | 43 | // overwrite process.env so that the original path gets passed
|
@@ -163,6 +165,44 @@ function setupFetch() {
|
163 | 165 | exposeInterface(globalThis, 'Response', undici.Response);
|
164 | 166 | }
|
165 | 167 |
|
| 168 | +// TODO(aduh95): move this to internal/bootstrap/browser when the CLI flag is |
| 169 | +// removed. |
| 170 | +function setupWebCrypto() { |
| 171 | + if (!getOptionValue('--experimental-global-webcrypto')) { |
| 172 | + return; |
| 173 | + } |
| 174 | + |
| 175 | + let webcrypto; |
| 176 | + ObjectDefineProperty(globalThis, 'crypto', |
| 177 | + ObjectGetOwnPropertyDescriptor({ |
| 178 | + get crypto() { |
| 179 | + webcrypto ??= require('internal/crypto/webcrypto'); |
| 180 | + return webcrypto.crypto; |
| 181 | + } |
| 182 | + }, 'crypto')); |
| 183 | + if (internalBinding('config').hasOpenSSL) { |
| 184 | + webcrypto ??= require('internal/crypto/webcrypto'); |
| 185 | + ObjectDefineProperty(globalThis, 'Crypto', { |
| 186 | + writable: true, |
| 187 | + enumerable: false, |
| 188 | + configurable: true, |
| 189 | + value: webcrypto.Crypto |
| 190 | + }); |
| 191 | + ObjectDefineProperty(globalThis, 'CryptoKey', { |
| 192 | + writable: true, |
| 193 | + enumerable: false, |
| 194 | + configurable: true, |
| 195 | + value: webcrypto.CryptoKey |
| 196 | + }); |
| 197 | + ObjectDefineProperty(globalThis, 'SubtleCrypto', { |
| 198 | + writable: true, |
| 199 | + enumerable: false, |
| 200 | + configurable: true, |
| 201 | + value: webcrypto.SubtleCrypto |
| 202 | + }); |
| 203 | + } |
| 204 | +} |
| 205 | + |
166 | 206 | // Setup User-facing NODE_V8_COVERAGE environment variable that writes
|
167 | 207 | // ScriptCoverage to a specified file.
|
168 | 208 | function setupCoverageHooks(dir) {
|
@@ -504,6 +544,7 @@ module.exports = {
|
504 | 544 | setupCoverageHooks,
|
505 | 545 | setupWarningHandler,
|
506 | 546 | setupFetch,
|
| 547 | + setupWebCrypto, |
507 | 548 | setupDebugEnv,
|
508 | 549 | setupPerfHooks,
|
509 | 550 | prepareMainThreadExecution,
|
|
0 commit comments