|
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
|
@@ -162,6 +164,29 @@ function setupFetch() {
|
162 | 164 | exposeInterface(globalThis, 'Response', undici.Response);
|
163 | 165 | }
|
164 | 166 |
|
| 167 | +// TODO(aduh95): move this to internal/bootstrap/browser when the CLI flag is |
| 168 | +// removed. |
| 169 | +function setupWebCrypto() { |
| 170 | + if (!getOptionValue('--experimental-global-webcrypto')) { |
| 171 | + return; |
| 172 | + } |
| 173 | + |
| 174 | + let webcrypto; |
| 175 | + ObjectDefineProperty(globalThis, 'crypto', |
| 176 | + ObjectGetOwnPropertyDescriptor({ |
| 177 | + get crypto() { |
| 178 | + webcrypto ??= require('internal/crypto/webcrypto'); |
| 179 | + return webcrypto.crypto; |
| 180 | + } |
| 181 | + }, 'crypto')); |
| 182 | + if (internalBinding('config').hasOpenSSL) { |
| 183 | + webcrypto ??= require('internal/crypto/webcrypto'); |
| 184 | + exposeInterface(globalThis, 'Crypto', webcrypto.Crypto); |
| 185 | + exposeInterface(globalThis, 'CryptoKey', webcrypto.CryptoKey); |
| 186 | + exposeInterface(globalThis, 'SubtleCrypto', webcrypto.SubtleCrypto); |
| 187 | + } |
| 188 | +} |
| 189 | + |
165 | 190 | // Setup User-facing NODE_V8_COVERAGE environment variable that writes
|
166 | 191 | // ScriptCoverage to a specified file.
|
167 | 192 | function setupCoverageHooks(dir) {
|
@@ -503,6 +528,7 @@ module.exports = {
|
503 | 528 | setupCoverageHooks,
|
504 | 529 | setupWarningHandler,
|
505 | 530 | setupFetch,
|
| 531 | + setupWebCrypto, |
506 | 532 | setupDebugEnv,
|
507 | 533 | setupPerfHooks,
|
508 | 534 | prepareMainThreadExecution,
|
|
0 commit comments