Skip to content

Commit d8edf03

Browse files
committed
cli: remove --no-experimental-global-webcrypto flag
1 parent 9eb363a commit d8edf03

File tree

11 files changed

+35
-112
lines changed

11 files changed

+35
-112
lines changed

doc/api/cli.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -402,14 +402,6 @@ added: v18.0.0
402402

403403
Disable experimental support for the [Fetch API][].
404404

405-
### `--no-experimental-global-webcrypto`
406-
407-
<!-- YAML
408-
added: v19.0.0
409-
-->
410-
411-
Disable exposition of [Web Crypto API][] on the global scope.
412-
413405
### `--no-experimental-global-customevent`
414406

415407
<!-- YAML
@@ -1915,7 +1907,6 @@ Node.js options that are allowed are:
19151907
* `--no-deprecation`
19161908
* `--no-experimental-fetch`
19171909
* `--no-experimental-global-customevent`
1918-
* `--no-experimental-global-webcrypto`
19191910
* `--no-experimental-repl-await`
19201911
* `--no-extra-info-on-fatal-exception`
19211912
* `--no-force-async-hooks-checks`
@@ -2329,7 +2320,6 @@ done
23292320
[Source Map]: https://sourcemaps.info/spec.html
23302321
[Subresource Integrity]: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
23312322
[V8 JavaScript code coverage]: https://v8project.blogspot.com/2017/12/javascript-code-coverage.html
2332-
[Web Crypto API]: webcrypto.md
23332323
[`"type"`]: packages.md#type
23342324
[`--cpu-prof-dir`]: #--cpu-prof-dir
23352325
[`--diagnostic-dir`]: #--diagnostic-dirdirectory

doc/api/globals.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,6 @@ changes:
351351
description: No longer behind `--experimental-global-webcrypto` CLI flag.
352352
-->
353353

354-
> Stability: 1 - Experimental. Disable this API with the
355-
> [`--no-experimental-global-webcrypto`][] CLI flag.
356-
357354
A browser-compatible implementation of {Crypto}. This global is available
358355
only if the Node.js binary was compiled with including support for the
359356
`node:crypto` module.
@@ -370,9 +367,6 @@ changes:
370367
description: No longer behind `--experimental-global-webcrypto` CLI flag.
371368
-->
372369

373-
> Stability: 1 - Experimental. Disable this API with the
374-
> [`--no-experimental-global-webcrypto`][] CLI flag.
375-
376370
A browser-compatible implementation of the [Web Crypto API][].
377371

378372
## `CryptoKey`
@@ -387,9 +381,6 @@ changes:
387381
description: No longer behind `--experimental-global-webcrypto` CLI flag.
388382
-->
389383

390-
> Stability: 1 - Experimental. Disable this API with the
391-
> [`--no-experimental-global-webcrypto`][] CLI flag.
392-
393384
A browser-compatible implementation of {CryptoKey}. This global is available
394385
only if the Node.js binary was compiled with including support for the
395386
`node:crypto` module.
@@ -829,9 +820,6 @@ changes:
829820
description: No longer behind `--experimental-global-webcrypto` CLI flag.
830821
-->
831822

832-
> Stability: 1 - Experimental. Disable this API with the
833-
> [`--no-experimental-global-webcrypto`][] CLI flag.
834-
835823
A browser-compatible implementation of {SubtleCrypto}. This global is available
836824
only if the Node.js binary was compiled with including support for the
837825
`node:crypto` module.
@@ -973,7 +961,6 @@ A browser-compatible implementation of [`WritableStreamDefaultWriter`][].
973961
[Web Crypto API]: webcrypto.md
974962
[`--no-experimental-fetch`]: cli.md#--no-experimental-fetch
975963
[`--no-experimental-global-customevent`]: cli.md#--no-experimental-global-customevent
976-
[`--no-experimental-global-webcrypto`]: cli.md#--no-experimental-global-webcrypto
977964
[`AbortController`]: https://developer.mozilla.org/en-US/docs/Web/API/AbortController
978965
[`ByteLengthQueuingStrategy`]: webstreams.md#class-bytelengthqueuingstrategy
979966
[`CompressionStream`]: webstreams.md#class-compressionstream

doc/node.1

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ Requires Node.js to be built with
140140
.It Fl -enable-source-maps
141141
Enable Source Map V3 support for stack traces.
142142
.
143-
.It Fl -experimental-global-webcrypto
144-
Expose the Web Crypto API on the global scope.
145-
.
146143
.It Fl -experimental-import-meta-resolve
147144
Enable experimental ES modules support for import.meta.resolve().
148145
.
@@ -166,9 +163,6 @@ Disable experimental support for the Fetch API.
166163
.It Fl -no-experimental-global-customevent
167164
Disable exposition of the CustomEvent on the global scope.
168165
.
169-
.It Fl -no-experimental-global-webcrypto
170-
Disable exposition of the Web Crypto API on the global scope.
171-
.
172166
.It Fl -no-experimental-repl-await
173167
Disable top-level await keyword support in REPL.
174168
.

lib/internal/bootstrap/browser.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const {
44
ObjectDefineProperty,
5+
ObjectGetOwnPropertyDescriptor,
56
globalThis,
67
} = primordials;
78

@@ -13,6 +14,10 @@ const {
1314
defineReplaceableLazyAttribute,
1415
exposeLazyInterfaces,
1516
} = require('internal/util');
17+
const {
18+
ERR_INVALID_THIS,
19+
ERR_NO_CRYPTO,
20+
} = require('internal/errors').codes;
1621
const config = internalBinding('config');
1722

1823
// https://console.spec.whatwg.org/#console-namespace
@@ -143,3 +148,30 @@ exposeLazyInterfaces(
143148
[
144149
'CompressionStream', 'DecompressionStream',
145150
]);
151+
152+
// Web Crypto API
153+
if (config.hasOpenSSL) {
154+
defineReplaceableLazyAttribute(
155+
globalThis,
156+
'internal/crypto/webcrypto',
157+
['crypto'],
158+
false,
159+
function cryptoThisCheck() {
160+
if (this !== globalThis && this != null)
161+
throw new ERR_INVALID_THIS(
162+
'nullish or must be the global object');
163+
}
164+
);
165+
exposeLazyInterfaces(
166+
globalThis, 'internal/crypto/webcrypto',
167+
['Crypto', 'CryptoKey', 'SubtleCrypto']
168+
);
169+
} else {
170+
ObjectDefineProperty(globalThis, 'crypto',
171+
{ __proto__: null, ...ObjectGetOwnPropertyDescriptor({
172+
get crypto() {
173+
throw new ERR_NO_CRYPTO();
174+
}
175+
}, 'crypto') });
176+
177+
}

lib/internal/crypto/webcrypto.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const {
55
JSONParse,
66
JSONStringify,
77
ObjectDefineProperties,
8-
ObjectDefineProperty,
98
ReflectApply,
109
ReflectConstruct,
1110
SafeSet,
@@ -29,10 +28,6 @@ const {
2928
validateString,
3029
} = require('internal/validators');
3130

32-
const {
33-
getOptionValue,
34-
} = require('internal/options');
35-
3631
const { TextDecoder, TextEncoder } = require('internal/encoding');
3732

3833
const {
@@ -790,18 +785,6 @@ ObjectDefineProperties(
790785
},
791786
});
792787

793-
if (getOptionValue('--no-experimental-global-webcrypto')) {
794-
// For backward compatibility, keep exposing CryptoKey in the Crypto prototype
795-
// when using the flag.
796-
ObjectDefineProperty(Crypto.prototype, 'CryptoKey', {
797-
__proto__: null,
798-
enumerable: true,
799-
configurable: true,
800-
writable: true,
801-
value: CryptoKey,
802-
});
803-
}
804-
805788
ObjectDefineProperties(
806789
SubtleCrypto.prototype, {
807790
[SymbolToStringTag]: {

lib/internal/main/eval_string.js

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

3838
if (isUsingCryptoIdentifier && !shouldDefineCrypto) {
3939
// This is taken from `addBuiltinLibsToObject`.

lib/internal/process/pre_execution.js

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const {
44
NumberParseInt,
55
ObjectDefineProperties,
66
ObjectDefineProperty,
7-
ObjectGetOwnPropertyDescriptor,
87
SafeMap,
98
StringPrototypeStartsWith,
109
globalThis,
@@ -18,14 +17,10 @@ const { reconnectZeroFillToggle } = require('internal/buffer');
1817
const {
1918
defineOperation,
2019
exposeInterface,
21-
exposeLazyInterfaces,
22-
defineReplaceableLazyAttribute,
2320
} = require('internal/util');
2421

2522
const {
26-
ERR_INVALID_THIS,
2723
ERR_MANIFEST_ASSERT_INTEGRITY,
28-
ERR_NO_CRYPTO,
2924
} = require('internal/errors').codes;
3025
const assert = require('internal/assert');
3126
const {
@@ -64,7 +59,6 @@ function prepareExecution(options) {
6459
setupInspectorHooks();
6560
setupWarningHandler();
6661
setupFetch();
67-
setupWebCrypto();
6862
setupCustomEvent();
6963

7064
// Resolve the coverage directory to an absolute path, and
@@ -269,41 +263,6 @@ function setupFetch() {
269263
});
270264
}
271265

272-
// TODO(aduh95): move this to internal/bootstrap/browser when the CLI flag is
273-
// removed.
274-
function setupWebCrypto() {
275-
if (process.config.variables.node_no_browser_globals ||
276-
getOptionValue('--no-experimental-global-webcrypto')) {
277-
return;
278-
}
279-
280-
if (internalBinding('config').hasOpenSSL) {
281-
defineReplaceableLazyAttribute(
282-
globalThis,
283-
'internal/crypto/webcrypto',
284-
['crypto'],
285-
false,
286-
function cryptoThisCheck() {
287-
if (this !== globalThis && this != null)
288-
throw new ERR_INVALID_THIS(
289-
'nullish or must be the global object');
290-
}
291-
);
292-
exposeLazyInterfaces(
293-
globalThis, 'internal/crypto/webcrypto',
294-
['Crypto', 'CryptoKey', 'SubtleCrypto']
295-
);
296-
} else {
297-
ObjectDefineProperty(globalThis, 'crypto',
298-
{ __proto__: null, ...ObjectGetOwnPropertyDescriptor({
299-
get crypto() {
300-
throw new ERR_NO_CRYPTO();
301-
}
302-
}, 'crypto') });
303-
304-
}
305-
}
306-
307266
// TODO(daeyeon): move this to internal/bootstrap/browser when the CLI flag is
308267
// removed.
309268
function setupCustomEvent() {

src/node_options.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,6 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
365365
&EnvironmentOptions::experimental_global_customevent,
366366
kAllowedInEnvvar,
367367
true);
368-
AddOption("--experimental-global-webcrypto",
369-
"expose experimental Web Crypto API on the global scope",
370-
&EnvironmentOptions::experimental_global_web_crypto,
371-
kAllowedInEnvvar,
372-
true);
373368
AddOption("--experimental-json-modules", "", NoOp{}, kAllowedInEnvvar);
374369
AddOption("--experimental-loader",
375370
"use the specified module as a custom loader",

src/node_options.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ class EnvironmentOptions : public Options {
112112
bool enable_source_maps = false;
113113
bool experimental_fetch = true;
114114
bool experimental_global_customevent = true;
115-
bool experimental_global_web_crypto = true;
116115
bool experimental_https_modules = false;
117116
bool experimental_wasm_modules = false;
118117
bool experimental_import_meta_resolve = false;

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)