From 6eede72241823ee1292e724b5c4eccd930afc089 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Mon, 12 Dec 2022 10:20:00 +0100 Subject: [PATCH] crypto: fix CryptoKey WebIDL conformance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/45855 Reviewed-By: Antoine du Hamel Reviewed-By: Luigi Pinca Reviewed-By: Tobias Nießen --- lib/internal/crypto/keys.js | 18 ++++++++++++++++++ test/wpt/status/WebCryptoAPI.json | 4 ---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/internal/crypto/keys.js b/lib/internal/crypto/keys.js index 4303dc44fe60d7..5e4ab819af5b3d 100644 --- a/lib/internal/crypto/keys.js +++ b/lib/internal/crypto/keys.js @@ -4,6 +4,7 @@ const { ArrayFrom, ArrayPrototypeSlice, ObjectDefineProperty, + ObjectDefineProperties, ObjectSetPrototypeOf, Symbol, Uint8Array, @@ -38,6 +39,7 @@ const { ERR_ILLEGAL_CONSTRUCTOR, ERR_INVALID_ARG_TYPE, ERR_INVALID_ARG_VALUE, + ERR_INVALID_THIS, } } = require('internal/errors'); @@ -61,6 +63,7 @@ const { const { customInspectSymbol: kInspect, + kEnumerableProperty, } = require('internal/util'); const { inspect } = require('internal/util/inspect'); @@ -657,18 +660,26 @@ class CryptoKey extends JSTransferable { } get type() { + if (!(this instanceof CryptoKey)) + throw new ERR_INVALID_THIS('CryptoKey'); return this[kKeyObject].type; } get extractable() { + if (!(this instanceof CryptoKey)) + throw new ERR_INVALID_THIS('CryptoKey'); return this[kExtractable]; } get algorithm() { + if (!(this instanceof CryptoKey)) + throw new ERR_INVALID_THIS('CryptoKey'); return this[kAlgorithm]; } get usages() { + if (!(this instanceof CryptoKey)) + throw new ERR_INVALID_THIS('CryptoKey'); return ArrayFrom(this[kKeyUsages]); } @@ -697,6 +708,13 @@ class CryptoKey extends JSTransferable { } } +ObjectDefineProperties(CryptoKey.prototype, { + type: kEnumerableProperty, + extractable: kEnumerableProperty, + algorithm: kEnumerableProperty, + usages: kEnumerableProperty, +}); + // All internal code must use new InternalCryptoKey to create // CryptoKey instances. The CryptoKey class is exposed to end // user code but is not permitted to be constructed directly. diff --git a/test/wpt/status/WebCryptoAPI.json b/test/wpt/status/WebCryptoAPI.json index 9eb8c8a5f31bc2..876ec7388dde54 100644 --- a/test/wpt/status/WebCryptoAPI.json +++ b/test/wpt/status/WebCryptoAPI.json @@ -11,10 +11,6 @@ "Crypto interface: existence and properties of interface object", "CryptoKey interface: existence and properties of interface object", "CryptoKey interface: existence and properties of interface prototype object", - "CryptoKey interface: attribute type", - "CryptoKey interface: attribute extractable", - "CryptoKey interface: attribute algorithm", - "CryptoKey interface: attribute usages", "Window interface: attribute crypto" ] }