Skip to content

Commit 6eede72

Browse files
panvatargos
authored andcommitted
crypto: fix CryptoKey WebIDL conformance
PR-URL: #45855 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent c980286 commit 6eede72

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
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.

test/wpt/status/WebCryptoAPI.json

-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
"Crypto interface: existence and properties of interface object",
1212
"CryptoKey interface: existence and properties of interface object",
1313
"CryptoKey interface: existence and properties of interface prototype object",
14-
"CryptoKey interface: attribute type",
15-
"CryptoKey interface: attribute extractable",
16-
"CryptoKey interface: attribute algorithm",
17-
"CryptoKey interface: attribute usages",
1814
"Window interface: attribute crypto"
1915
]
2016
}

0 commit comments

Comments
 (0)