From 3251c8c83882bc42e972120fa0a0d1802e851d71 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Wed, 9 Oct 2024 13:19:44 +0530 Subject: [PATCH] Revert "Revert "Fix: AXE-570 Fixed a11yEngineErrors being accessed on undefined"" --- lib/core/public/load.js | 5 ++++- lib/core/public/run-rules.js | 5 ++++- lib/core/utils/merge-results.js | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/core/public/load.js b/lib/core/public/load.js index e80d3d8f..0d7e0caf 100644 --- a/lib/core/public/load.js +++ b/lib/core/public/load.js @@ -42,7 +42,10 @@ function runCommand(data, keepalive, callback) { //a11y-engine iframe rules error merging logic const errors = a11yEngine.getErrors(); if (Object.keys(errors).length !== 0) { - if (results[results.length - 1].a11yEngineErrors) { + if ( + results.length > 0 && + results[results.length - 1]?.a11yEngineErrors + ) { const error = results.pop(); delete error.a11yEngineErrors; const mergedErrors = mergeErrors(error, errors); diff --git a/lib/core/public/run-rules.js b/lib/core/public/run-rules.js index 8e04c13d..9193d437 100644 --- a/lib/core/public/run-rules.js +++ b/lib/core/public/run-rules.js @@ -67,7 +67,10 @@ export default function runRules(context, options, resolve, reject) { // after should only run once, so ensure we are in the top level window if (context.initiator) { // Return a11y-engine errors when at top level window - if (results[results.length - 1].a11yEngineErrors) { + if ( + results.length > 0 && + results[results.length - 1]?.a11yEngineErrors + ) { const error = results.pop(); delete error.a11yEngineErrors; a11yEngine.mergeErrors(error); diff --git a/lib/core/utils/merge-results.js b/lib/core/utils/merge-results.js index 0e627713..79aa935b 100644 --- a/lib/core/utils/merge-results.js +++ b/lib/core/utils/merge-results.js @@ -86,7 +86,7 @@ function mergeResults(frameResults, options) { const frameSpec = getFrameSpec(frameResult); // Extract existing errors and merge with new ones - if (results[results.length - 1].a11yEngineErrors) { + if (results.length > 0 && results[results.length - 1]?.a11yEngineErrors) { const error = results.pop(); delete error.a11yEngineErrors; mergedErrors = mergeErrors(mergedErrors, error, frameSpec);