mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
crypto: fix globalThis.crypto this check
PR-URL: https://github.com/nodejs/node/pull/45857 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
e8b56fb152
commit
3f3966cb82
@ -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',
|
||||
|
@ -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) {
|
||||
FunctionPrototypeCall(check, this);
|
||||
}
|
||||
if (setterCalled) {
|
||||
return value;
|
||||
}
|
||||
|
@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user