Skip to content

Commit 1a8aa50

Browse files
panvajuanarbol
authored andcommitted
crypto: fix CryptoKey WebIDL conformance
PR-URL: #45855 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent c643645 commit 1a8aa50

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/internal/crypto/keys.js

+18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {
44
ArrayFrom,
55
ArrayPrototypeSlice,
66
ObjectDefineProperty,
7+
ObjectDefineProperties,
78
ObjectSetPrototypeOf,
89
Symbol,
910
Uint8Array,
@@ -38,6 +39,7 @@ const {
3839
ERR_ILLEGAL_CONSTRUCTOR,
3940
ERR_INVALID_ARG_TYPE,
4041
ERR_INVALID_ARG_VALUE,
42+
ERR_INVALID_THIS,
4143
}
4244
} = require('internal/errors');
4345

@@ -61,6 +63,7 @@ const {
6163

6264
const {
6365
customInspectSymbol: kInspect,
66+
kEnumerableProperty,
6467
} = require('internal/util');
6568

6669
const { inspect } = require('internal/util/inspect');
@@ -657,18 +660,26 @@ class CryptoKey extends JSTransferable {
657660
}
658661

659662
get type() {
663+
if (!(this instanceof CryptoKey))
664+
throw new ERR_INVALID_THIS('CryptoKey');
660665
return this[kKeyObject].type;
661666
}
662667

663668
get extractable() {
669+
if (!(this instanceof CryptoKey))
670+
throw new ERR_INVALID_THIS('CryptoKey');
664671
return this[kExtractable];
665672
}
666673

667674
get algorithm() {
675+
if (!(this instanceof CryptoKey))
676+
throw new ERR_INVALID_THIS('CryptoKey');
668677
return this[kAlgorithm];
669678
}
670679

671680
get usages() {
681+
if (!(this instanceof CryptoKey))
682+
throw new ERR_INVALID_THIS('CryptoKey');
672683
return ArrayFrom(this[kKeyUsages]);
673684
}
674685

@@ -697,6 +708,13 @@ class CryptoKey extends JSTransferable {
697708
}
698709
}
699710

711+
ObjectDefineProperties(CryptoKey.prototype, {
712+
type: kEnumerableProperty,
713+
extractable: kEnumerableProperty,
714+
algorithm: kEnumerableProperty,
715+
usages: kEnumerableProperty,
716+
});
717+
700718
// All internal code must use new InternalCryptoKey to create
701719
// CryptoKey instances. The CryptoKey class is exposed to end
702720
// user code but is not permitted to be constructed directly.

0 commit comments

Comments
 (0)