diff --git a/lib/internal/crypto/webcrypto.js b/lib/internal/crypto/webcrypto.js index 337343cbbb3..8069efbc90b 100644 --- a/lib/internal/crypto/webcrypto.js +++ b/lib/internal/crypto/webcrypto.js @@ -1761,7 +1761,6 @@ class SubtleCrypto { // TODO(panva): Make supports() account for the active FIPS state. 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); +}