Skip to content

Commit 3ca28cb

Browse files
panvanodejs-github-bot
authored andcommitted
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: #66237 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh>
1 parent d0cbb41 commit 3ca28cb

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎lib/internal/crypto/webcrypto.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,6 @@ class SubtleCrypto {
17591759
// Implements https://wicg.github.io/webcrypto-modern-algos/#SubtleCrypto-method-supports
17601760
static supports(operation, algorithm, lengthOrAdditionalAlgorithm = null) {
17611761
emitExperimentalWarning('The supports Web Crypto API method');
1762-
if (this !== SubtleCrypto) throw new ERR_INVALID_THIS('SubtleCrypto constructor');
17631762
webidl ??= require('internal/crypto/webidl');
17641763
const prefix = "Failed to execute 'supports' on 'SubtleCrypto'";
17651764
webidl.requiredArguments(arguments.length, 2, { prefix });

‎test/parallel/test-webcrypto-constructors.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const notSubtle = Reflect.construct(function() {}, [], SubtleCrypto);
142142
// Test SubtleCrypto.supports
143143
{
144144
assert.throws(() => SubtleCrypto.supports.call(undefined), {
145-
name: 'TypeError', code: 'ERR_INVALID_THIS',
145+
name: 'TypeError', code: 'ERR_MISSING_ARGS',
146146
});
147147
}
148148

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
const assert = require('assert');
8+
const { supports } = SubtleCrypto;
9+
10+
assert.strictEqual(supports('digest', 'SHA-256'), true);
11+
for (const receiver of [undefined, null, {}, globalThis.crypto.subtle]) {
12+
assert.strictEqual(supports.call(receiver, 'digest', 'SHA-256'), true);
13+
assert.strictEqual(supports.call(receiver, 'digest', 'unknown'), false);
14+
}

0 commit comments

Comments
 (0)