Skip to content

Commit 68bad04

Browse files
committed
cli: remove --no-experimental-global-webcrypto flag
1 parent 128c60d commit 68bad04

File tree

9 files changed

+45
-91
lines changed

9 files changed

+45
-91
lines changed

doc/api/cli.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,14 +1375,6 @@ added: v21.2.0
13751375
13761376
Disable exposition of [Navigator API][] on the global scope.
13771377

1378-
### `--no-experimental-global-webcrypto`
1379-
1380-
<!-- YAML
1381-
added: v19.0.0
1382-
-->
1383-
1384-
Disable exposition of [Web Crypto API][] on the global scope.
1385-
13861378
### `--no-experimental-repl-await`
13871379

13881380
<!-- YAML
@@ -2640,7 +2632,6 @@ one is included in the list below.
26402632
* `--no-experimental-fetch`
26412633
* `--no-experimental-global-customevent`
26422634
* `--no-experimental-global-navigator`
2643-
* `--no-experimental-global-webcrypto`
26442635
* `--no-experimental-repl-await`
26452636
* `--no-experimental-websocket`
26462637
* `--no-extra-info-on-fatal-exception`
@@ -3130,7 +3121,6 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
31303121
[Source Map]: https://sourcemaps.info/spec.html
31313122
[Subresource Integrity]: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
31323123
[V8 JavaScript code coverage]: https://v8project.blogspot.com/2017/12/javascript-code-coverage.html
3133-
[Web Crypto API]: webcrypto.md
31343124
[`"type"`]: packages.md#type
31353125
[`--allow-child-process`]: #--allow-child-process
31363126
[`--allow-fs-read`]: #--allow-fs-read

doc/api/globals.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,15 @@ added:
361361
- v17.6.0
362362
- v16.15.0
363363
changes:
364+
- version: REPLACEME
365+
pr-url: https://github.com/nodejs/node/pull/52564
366+
description: No longer experimental.
364367
- version: v19.0.0
365368
pr-url: https://github.com/nodejs/node/pull/42083
366369
description: No longer behind `--experimental-global-webcrypto` CLI flag.
367370
-->
368371

369-
> Stability: 1 - Experimental. Disable this API with the
370-
> [`--no-experimental-global-webcrypto`][] CLI flag.
372+
> Stability: 2 - Stable.
371373
372374
A browser-compatible implementation of {Crypto}. This global is available
373375
only if the Node.js binary was compiled with including support for the
@@ -380,13 +382,15 @@ added:
380382
- v17.6.0
381383
- v16.15.0
382384
changes:
385+
- version: REPLACEME
386+
pr-url: https://github.com/nodejs/node/pull/52564
387+
description: No longer experimental.
383388
- version: v19.0.0
384389
pr-url: https://github.com/nodejs/node/pull/42083
385390
description: No longer behind `--experimental-global-webcrypto` CLI flag.
386391
-->
387392

388-
> Stability: 1 - Experimental. Disable this API with the
389-
> [`--no-experimental-global-webcrypto`][] CLI flag.
393+
> Stability: 2 - Stable.
390394
391395
A browser-compatible implementation of the [Web Crypto API][].
392396

@@ -397,13 +401,15 @@ added:
397401
- v17.6.0
398402
- v16.15.0
399403
changes:
404+
- version: REPLACEME
405+
pr-url: https://github.com/nodejs/node/pull/52564
406+
description: No longer experimental.
400407
- version: v19.0.0
401408
pr-url: https://github.com/nodejs/node/pull/42083
402409
description: No longer behind `--experimental-global-webcrypto` CLI flag.
403410
-->
404411

405-
> Stability: 1 - Experimental. Disable this API with the
406-
> [`--no-experimental-global-webcrypto`][] CLI flag.
412+
> Stability: 2 - Stable.
407413
408414
A browser-compatible implementation of {CryptoKey}. This global is available
409415
only if the Node.js binary was compiled with including support for the
@@ -981,8 +987,7 @@ changes:
981987
description: No longer behind `--experimental-global-webcrypto` CLI flag.
982988
-->
983989

984-
> Stability: 1 - Experimental. Disable this API with the
985-
> [`--no-experimental-global-webcrypto`][] CLI flag.
990+
> Stability: 2 - Stable.
986991
987992
A browser-compatible implementation of {SubtleCrypto}. This global is available
988993
only if the Node.js binary was compiled with including support for the
@@ -1147,7 +1152,6 @@ A browser-compatible implementation of [`WritableStreamDefaultWriter`][].
11471152
[Web Crypto API]: webcrypto.md
11481153
[`--no-experimental-global-customevent`]: cli.md#--no-experimental-global-customevent
11491154
[`--no-experimental-global-navigator`]: cli.md#--no-experimental-global-navigator
1150-
[`--no-experimental-global-webcrypto`]: cli.md#--no-experimental-global-webcrypto
11511155
[`--no-experimental-websocket`]: cli.md#--no-experimental-websocket
11521156
[`AbortController`]: https://developer.mozilla.org/en-US/docs/Web/API/AbortController
11531157
[`ByteLengthQueuingStrategy`]: webstreams.md#class-bytelengthqueuingstrategy

doc/node.1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,6 @@ Disable experimental support for the WebSocket API.
192192
.It Fl -no-experimental-global-customevent
193193
Disable exposition of the CustomEvent on the global scope.
194194
.
195-
.It Fl -no-experimental-global-webcrypto
196-
Disable exposition of the Web Crypto API on the global scope.
197-
.
198195
.It Fl -no-experimental-repl-await
199196
Disable top-level await keyword support in REPL.
200197
.

lib/internal/bootstrap/web/exposed-wildcard.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ const {
1111
} = primordials;
1212

1313
const {
14+
defineReplaceableLazyAttribute,
1415
exposeInterface,
1516
lazyDOMExceptionClass,
1617
exposeLazyInterfaces,
1718
exposeGetterAndSetter,
1819
exposeNamespace,
1920
} = require('internal/util');
21+
const {
22+
ERR_INVALID_THIS,
23+
ERR_NO_CRYPTO,
24+
} = require('internal/errors').codes;
2025
const config = internalBinding('config');
2126

2227
// https://console.spec.whatwg.org/#console-namespace
@@ -112,3 +117,29 @@ exposeLazyInterfaces(
112117
[
113118
'CompressionStream', 'DecompressionStream',
114119
]);
120+
121+
// WebCryptoAPI
122+
if (internalBinding('config').hasOpenSSL) {
123+
defineReplaceableLazyAttribute(
124+
globalThis,
125+
'internal/crypto/webcrypto',
126+
['crypto'],
127+
false,
128+
function cryptoThisCheck() {
129+
if (this !== globalThis && this != null)
130+
throw new ERR_INVALID_THIS(
131+
'nullish or must be the global object');
132+
},
133+
);
134+
exposeLazyInterfaces(
135+
globalThis, 'internal/crypto/webcrypto',
136+
['Crypto', 'CryptoKey', 'SubtleCrypto'],
137+
);
138+
} else {
139+
ObjectDefineProperty(globalThis, 'crypto',
140+
{ __proto__: null, ...ObjectGetOwnPropertyDescriptor({
141+
get crypto() {
142+
throw new ERR_NO_CRYPTO();
143+
},
144+
}, 'crypto') });
145+
}

lib/internal/crypto/webcrypto.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,18 +1025,6 @@ ObjectDefineProperties(
10251025
},
10261026
});
10271027

1028-
if (getOptionValue('--no-experimental-global-webcrypto')) {
1029-
// For backward compatibility, keep exposing CryptoKey in the Crypto prototype
1030-
// when using the flag.
1031-
ObjectDefineProperty(Crypto.prototype, 'CryptoKey', {
1032-
__proto__: null,
1033-
enumerable: true,
1034-
configurable: true,
1035-
writable: true,
1036-
value: CryptoKey,
1037-
});
1038-
}
1039-
10401028
ObjectDefineProperties(
10411029
SubtleCrypto.prototype, {
10421030
[SymbolToStringTag]: {

lib/internal/main/eval_string.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ if (getOptionValue('--input-type') === 'module' ||
3131
} else {
3232
// For backward compatibility, we want the identifier crypto to be the
3333
// `node:crypto` module rather than WebCrypto.
34-
const isUsingCryptoIdentifier =
35-
getOptionValue('--experimental-global-webcrypto') &&
36-
RegExpPrototypeExec(/\bcrypto\b/, source) !== null;
34+
const isUsingCryptoIdentifier = RegExpPrototypeExec(/\bcrypto\b/, source) !== null;
3735
const shouldDefineCrypto = isUsingCryptoIdentifier && internalBinding('config').hasOpenSSL;
3836

3937
if (isUsingCryptoIdentifier && !shouldDefineCrypto) {

lib/internal/process/pre_execution.js

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ const {
3636
} = require('internal/util');
3737

3838
const {
39-
ERR_INVALID_THIS,
4039
ERR_MANIFEST_ASSERT_INTEGRITY,
41-
ERR_NO_CRYPTO,
4240
ERR_MISSING_OPTION,
4341
ERR_ACCESS_DENIED,
4442
} = require('internal/errors').codes;
@@ -107,7 +105,6 @@ function prepareExecution(options) {
107105
setupNavigator();
108106
setupWarningHandler();
109107
setupUndici();
110-
setupWebCrypto();
111108
setupCustomEvent();
112109
setupCodeCoverage();
113110
setupDebugEnv();
@@ -341,41 +338,6 @@ function setupNavigator() {
341338
defineReplaceableLazyAttribute(globalThis, 'internal/navigator', ['navigator'], false);
342339
}
343340

344-
// TODO(aduh95): move this to internal/bootstrap/web/* when the CLI flag is
345-
// removed.
346-
function setupWebCrypto() {
347-
if (getEmbedderOptions().noBrowserGlobals ||
348-
getOptionValue('--no-experimental-global-webcrypto')) {
349-
return;
350-
}
351-
352-
if (internalBinding('config').hasOpenSSL) {
353-
defineReplaceableLazyAttribute(
354-
globalThis,
355-
'internal/crypto/webcrypto',
356-
['crypto'],
357-
false,
358-
function cryptoThisCheck() {
359-
if (this !== globalThis && this != null)
360-
throw new ERR_INVALID_THIS(
361-
'nullish or must be the global object');
362-
},
363-
);
364-
exposeLazyInterfaces(
365-
globalThis, 'internal/crypto/webcrypto',
366-
['Crypto', 'CryptoKey', 'SubtleCrypto'],
367-
);
368-
} else {
369-
ObjectDefineProperty(globalThis, 'crypto',
370-
{ __proto__: null, ...ObjectGetOwnPropertyDescriptor({
371-
get crypto() {
372-
throw new ERR_NO_CRYPTO();
373-
},
374-
}, 'crypto') });
375-
376-
}
377-
}
378-
379341
function setupCodeCoverage() {
380342
// Resolve the coverage directory to an absolute path, and
381343
// overwrite process.env so that the original path gets passed

test/parallel/test-cli-eval.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,6 @@ child.exec(
348348
common.mustSucceed((stdout) => {
349349
assert.match(stdout, /^number/);
350350
}));
351-
child.exec(
352-
`${nodejs} --no-experimental-global-webcrypto ` +
353-
'-p "var crypto = {randomBytes:1};typeof crypto.randomBytes"',
354-
common.mustSucceed((stdout) => {
355-
assert.match(stdout, /^number/);
356-
}));
357351

358352
// Regression test for https://github.com/nodejs/node/issues/45336
359353
child.execFile(process.execPath,

test/parallel/test-global-webcrypto-disbled.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)