From b1cee59fcbb012491735296be3d9d640890a489d Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Thu, 22 Dec 2022 10:54:38 +0900 Subject: [PATCH] fix(ext): Add checks for owning properties in for-in loops (#17139) In the for-in loops, there were a few places where we forgot to check if objects owned some properties, so I added them. --- ext/crypto/00_crypto.js | 7 +++++++ ext/web/13_message_port.js | 2 +- ext/webidl/00_webidl.js | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ext/crypto/00_crypto.js b/ext/crypto/00_crypto.js index f56bfb6c0d..044cc1f267 100644 --- a/ext/crypto/00_crypto.js +++ b/ext/crypto/00_crypto.js @@ -29,6 +29,7 @@ JSONStringify, MathCeil, ObjectAssign, + ObjectPrototypeHasOwnProperty, ObjectPrototypeIsPrototypeOf, StringPrototypeToLowerCase, StringPrototypeToUpperCase, @@ -211,6 +212,9 @@ // 5. let desiredType = undefined; for (const key in registeredAlgorithms) { + if (!ObjectPrototypeHasOwnProperty(registeredAlgorithms, key)) { + continue; + } if ( StringPrototypeToUpperCase(key) === StringPrototypeToUpperCase(algName) ) { @@ -242,6 +246,9 @@ const dict = simpleAlgorithmDictionaries[desiredType]; // 10. for (const member in dict) { + if (!ObjectPrototypeHasOwnProperty(dict, member)) { + continue; + } const idlType = dict[member]; const idlValue = normalizedAlgorithm[member]; // 3. diff --git a/ext/web/13_message_port.js b/ext/web/13_message_port.js index 7ec8dc9f95..847daba26f 100644 --- a/ext/web/13_message_port.js +++ b/ext/web/13_message_port.js @@ -231,7 +231,7 @@ transferredArrayBuffers, }); - for (const i in arrayBufferIdsInTransferables) { + for (let i = 0; i < arrayBufferIdsInTransferables.length; ++i) { const id = arrayBufferIdsInTransferables[i]; transferables[id] = transferredArrayBuffers[i]; } diff --git a/ext/webidl/00_webidl.js b/ext/webidl/00_webidl.js index dafade99dd..c7825b8a21 100644 --- a/ext/webidl/00_webidl.js +++ b/ext/webidl/00_webidl.js @@ -1013,6 +1013,9 @@ function configurePrototype(prototype) { const descriptors = ObjectGetOwnPropertyDescriptors(prototype.prototype); for (const key in descriptors) { + if (!ObjectPrototypeHasOwnProperty(descriptors, key)) { + continue; + } if (key === "constructor") continue; const descriptor = descriptors[key]; if (