Commit 3ca28cb44bc for nodejs
commit 3ca28cb44bc554a6f673e4b92e6ac0e47036d415
Author: Filip Skokan <panva.ip@gmail.com>
Date: Tue Sep 22 22:15:29 2026 +0200
crypto: allow unbound SubtleCrypto.supports
Static Web IDL operations do not require an interface receiver.
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66237
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Aviv Keller <me@aviv.sh>
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);
+}