|
3 | 3 | const {
|
4 | 4 | NumberParseInt,
|
5 | 5 | ObjectDefineProperty,
|
| 6 | + ObjectGetOwnPropertyDescriptor, |
6 | 7 | SafeMap,
|
7 | 8 | SafeWeakMap,
|
8 | 9 | StringPrototypeStartsWith,
|
@@ -34,6 +35,7 @@ function prepareMainThreadExecution(expandArgv1 = false) {
|
34 | 35 | setupInspectorHooks();
|
35 | 36 | setupWarningHandler();
|
36 | 37 | setupFetch();
|
| 38 | + setupWebCrypto(); |
37 | 39 |
|
38 | 40 | // Resolve the coverage directory to an absolute path, and
|
39 | 41 | // overwrite process.env so that the original path gets passed
|
@@ -180,6 +182,44 @@ function setupFetch() {
|
180 | 182 | });
|
181 | 183 | }
|
182 | 184 |
|
| 185 | +// TODO(aduh95): move this to internal/bootstrap/browser when the CLI flag is |
| 186 | +// removed. |
| 187 | +function setupWebCrypto() { |
| 188 | + if (!getOptionValue('--experimental-global-webcrypto')) { |
| 189 | + return; |
| 190 | + } |
| 191 | + |
| 192 | + let webcrypto; |
| 193 | + ObjectDefineProperty(globalThis, 'crypto', |
| 194 | + ObjectGetOwnPropertyDescriptor({ |
| 195 | + get crypto() { |
| 196 | + webcrypto ??= require('internal/crypto/webcrypto'); |
| 197 | + return webcrypto.crypto; |
| 198 | + } |
| 199 | + }, 'crypto')); |
| 200 | + if (internalBinding('config').hasOpenSSL) { |
| 201 | + webcrypto ??= require('internal/crypto/webcrypto'); |
| 202 | + ObjectDefineProperty(globalThis, 'Crypto', { |
| 203 | + writable: true, |
| 204 | + enumerable: false, |
| 205 | + configurable: true, |
| 206 | + value: webcrypto.Crypto |
| 207 | + }); |
| 208 | + ObjectDefineProperty(globalThis, 'CryptoKey', { |
| 209 | + writable: true, |
| 210 | + enumerable: false, |
| 211 | + configurable: true, |
| 212 | + value: webcrypto.CryptoKey |
| 213 | + }); |
| 214 | + ObjectDefineProperty(globalThis, 'SubtleCrypto', { |
| 215 | + writable: true, |
| 216 | + enumerable: false, |
| 217 | + configurable: true, |
| 218 | + value: webcrypto.SubtleCrypto |
| 219 | + }); |
| 220 | + } |
| 221 | +} |
| 222 | + |
183 | 223 | // Setup User-facing NODE_V8_COVERAGE environment variable that writes
|
184 | 224 | // ScriptCoverage to a specified file.
|
185 | 225 | function setupCoverageHooks(dir) {
|
@@ -521,6 +561,7 @@ module.exports = {
|
521 | 561 | setupCoverageHooks,
|
522 | 562 | setupWarningHandler,
|
523 | 563 | setupFetch,
|
| 564 | + setupWebCrypto, |
524 | 565 | setupDebugEnv,
|
525 | 566 | setupPerfHooks,
|
526 | 567 | prepareMainThreadExecution,
|
|
0 commit comments