From a855a46aeb40a41dc30b1b0ac9356cf100e22a98 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Tue, 22 Sep 2026 22:15:29 +0200 Subject: [PATCH] crypto: allow unbound SubtleCrypto.supports Static Web IDL operations do not require an interface receiver. Signed-off-by: Filip Skokan Assisted-by: Codex PR-URL: https://github.com/nodejs/node/pull/66237 Reviewed-By: James M Snell Reviewed-By: Aviv Keller --- lib/internal/crypto/webcrypto.js | 1 - test/parallel/test-webcrypto-constructors.js | 2 +- test/parallel/test-webcrypto-supports-receiver.js | 14 ++++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-webcrypto-supports-receiver.js diff --git a/lib/internal/crypto/webcrypto.js b/lib/internal/crypto/webcrypto.js index c0a50a1b4be..4ab482a4307 100644 --- a/lib/internal/crypto/webcrypto.js +++ b/lib/internal/crypto/webcrypto.js @@ -1759,7 +1759,6 @@ class SubtleCrypto { // Implements https://wicg.github.io/webcrypto-modern-algos/#SubtleCrypto-method-supports static supports(operation, algorithm, lengthOrAdditionalAlgorithm = null) { emitExperimentalWarning('The supports Web Crypto API method'); - if (this !== SubtleCrypto) throw new ERR_INVALID_THIS('SubtleCrypto constructor'); webidl ??= require('internal/crypto/webidl'); const prefix = "Failed to execute 'supports' on 'SubtleCrypto'"; webidl.requiredArguments(arguments.length, 2, { prefix }); diff --git a/test/parallel/test-webcrypto-constructors.js b/test/parallel/test-webcrypto-constructors.js index 3d13b6c92bb..64e1a6ecbbb 100644 --- a/test/parallel/test-webcrypto-constructors.js +++ b/test/parallel/test-webcrypto-constructors.js @@ -142,7 +142,7 @@ const notSubtle = Reflect.construct(function() {}, [], SubtleCrypto); // Test SubtleCrypto.supports { assert.throws(() => SubtleCrypto.supports.call(undefined), { - name: 'TypeError', code: 'ERR_INVALID_THIS', + name: 'TypeError', code: 'ERR_MISSING_ARGS', }); } diff --git a/test/parallel/test-webcrypto-supports-receiver.js b/test/parallel/test-webcrypto-supports-receiver.js new file mode 100644 index 00000000000..8fa8ed0d405 --- /dev/null +++ b/test/parallel/test-webcrypto-supports-receiver.js @@ -0,0 +1,14 @@ +'use strict'; + +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); + +const assert = require('assert'); +const { supports } = SubtleCrypto; + +assert.strictEqual(supports('digest', 'SHA-256'), true); +for (const receiver of [undefined, null, {}, globalThis.crypto.subtle]) { + assert.strictEqual(supports.call(receiver, 'digest', 'SHA-256'), true); + assert.strictEqual(supports.call(receiver, 'digest', 'unknown'), false); +}