diff --git a/lib/internal/process/pre_execution.js b/lib/internal/process/pre_execution.js index c3e84854ccefdd..4c44927fb0c15a 100644 --- a/lib/internal/process/pre_execution.js +++ b/lib/internal/process/pre_execution.js @@ -23,6 +23,7 @@ const { } = require('internal/util'); const { + ERR_INVALID_THIS, ERR_MANIFEST_ASSERT_INTEGRITY, ERR_NO_CRYPTO, } = require('internal/errors').codes; @@ -278,7 +279,15 @@ function setupWebCrypto() { if (internalBinding('config').hasOpenSSL) { defineReplaceableLazyAttribute( - globalThis, 'internal/crypto/webcrypto', ['crypto'], false + globalThis, + 'internal/crypto/webcrypto', + ['crypto'], + false, + function cryptoThisCheck() { + if (this !== globalThis && this != null) + throw new ERR_INVALID_THIS( + 'nullish or must be the global object'); + } ); exposeLazyInterfaces( globalThis, 'internal/crypto/webcrypto', diff --git a/lib/internal/util.js b/lib/internal/util.js index 38002b421376ec..6f86d0013ebc03 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -552,7 +552,7 @@ function defineLazyProperties(target, id, keys, enumerable = true) { ObjectDefineProperties(target, descriptors); } -function defineReplaceableLazyAttribute(target, id, keys, writable = true) { +function defineReplaceableLazyAttribute(target, id, keys, writable = true, check) { let mod; for (let i = 0; i < keys.length; i++) { const key = keys[i]; @@ -560,6 +560,9 @@ function defineReplaceableLazyAttribute(target, id, keys, writable = true) { let setterCalled = false; function get() { + if (check !== undefined) { + check.call(this); + } if (setterCalled) { return value; } diff --git a/test/wpt/status/WebCryptoAPI.json b/test/wpt/status/WebCryptoAPI.json index 78a79a71920c6f..bd1db9eba685b7 100644 --- a/test/wpt/status/WebCryptoAPI.json +++ b/test/wpt/status/WebCryptoAPI.json @@ -17,13 +17,5 @@ }, "historical.any.js": { "skip": "Not relevant in Node.js context" - }, - "idlharness.https.any.js": { - "fail": { - "expected": [ - "CryptoKey interface: existence and properties of interface object", - "Window interface: attribute crypto" - ] - } } }