Skip to content

Commit 2849283

Browse files
committed
crypto: remove non-standard webcrypto.Crypto.prototype.CryptoKey
`CryptoKey` is already available on the global object. PR-URL: #42083 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 6de2673 commit 2849283

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

lib/internal/crypto/webcrypto.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {
55
JSONParse,
66
JSONStringify,
77
ObjectDefineProperties,
8+
ObjectDefineProperty,
89
ReflectApply,
910
ReflectConstruct,
1011
SafeSet,
@@ -28,6 +29,10 @@ const {
2829
validateString,
2930
} = require('internal/validators');
3031

32+
const {
33+
getOptionValue,
34+
} = require('internal/options');
35+
3136
const { TextDecoder, TextEncoder } = require('internal/encoding');
3237

3338
const {
@@ -792,15 +797,20 @@ ObjectDefineProperties(
792797
writable: true,
793798
value: randomUUID,
794799
},
795-
CryptoKey: {
796-
__proto__: null,
797-
enumerable: true,
798-
configurable: true,
799-
writable: true,
800-
value: CryptoKey,
801-
}
802800
});
803801

802+
if (getOptionValue('--no-experimental-global-webcrypto')) {
803+
// For backward compatibility, keep exposing CryptoKey in the Crypto prototype
804+
// when using the flag.
805+
ObjectDefineProperty(Crypto.prototype, 'CryptoKey', {
806+
__proto__: null,
807+
enumerable: true,
808+
configurable: true,
809+
writable: true,
810+
value: CryptoKey,
811+
});
812+
}
813+
804814
ObjectDefineProperties(
805815
SubtleCrypto.prototype, {
806816
[SymbolToStringTag]: {

test/parallel/test-crypto-subtle-zero-length.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const crypto = require('crypto').webcrypto;
1515
{ name: 'AES-GCM' },
1616
false,
1717
[ 'encrypt', 'decrypt' ]);
18-
assert(k instanceof crypto.CryptoKey);
18+
assert(k instanceof CryptoKey);
1919

2020
const e = await crypto.subtle.encrypt({
2121
name: 'AES-GCM',

test/parallel/test-webcrypto-keygen.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if (!common.hasCrypto)
99
const assert = require('assert');
1010
const { types: { isCryptoKey } } = require('util');
1111
const {
12-
webcrypto: { subtle, CryptoKey },
12+
webcrypto: { subtle },
1313
createSecretKey,
1414
KeyObject,
1515
} = require('crypto');

0 commit comments

Comments
 (0)