mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05: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:
1 parent
97a8e055be
commit
f7dba5bef7
3 files changed
+14
-10
No files matched your search
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user