Skip to content

Commit

Permalink
fix the error "TypeError: Cannot read properties of null (reading 'no…
Browse files Browse the repository at this point in the history
…deType')" from the cache #1974
  • Loading branch information
shunguoy committed Oct 24, 2024
1 parent a10faa0 commit 712c8d2
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const combobox_active_descendant: Rule = {
run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => {
const ruleContext = context["dom"].node as Element;
let cache = CacheUtil.getCache(ruleContext.ownerDocument, "combobox", {});
if (!cache) return null;
let cachedElem = cache[context["dom"].rolePath];
if (!cachedElem) return null;
const { popupElement, popupId } = cachedElem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const combobox_autocomplete_valid: Rule = {
run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => {
const ruleContext = context["dom"].node as Element;
let cache = CacheUtil.getCache(ruleContext.ownerDocument, "combobox", {});
if (!cache) return null;
let cachedElem = cache[context["dom"].rolePath];
if (!cachedElem) return null;
const { popupId, popupElement } = cachedElem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const combobox_design_valid: Rule = {
let key = context["dom"].rolePath;
if (key) {
let cache = CacheUtil.getCache(ruleContext.ownerDocument, "combobox", {});
if (!cache) return null;
cache[key] = {
"inputElement": editable ? ruleContext : null,
"pattern": pattern,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const combobox_focusable_elements: Rule = {
run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => {
const ruleContext = context["dom"].node as Element;
let cache = CacheUtil.getCache(ruleContext.ownerDocument, "combobox", {});
if (!cache) return null;
let cachedElem = cache[context["dom"].rolePath];
if (!cachedElem) return null;
const { popupElement, expanded } = cachedElem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const combobox_haspopup_valid: Rule = {
run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => {
const ruleContext = context["dom"].node as Element;
const cache = CacheUtil.getCache(ruleContext.ownerDocument, "combobox", {});
if (!cache) return null;
const cacheKey = context["dom"].rolePath;
const cachedElem = cache[cacheKey];
if (!cachedElem) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const combobox_popup_reference: Rule = {
run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => {
const ruleContext = context["dom"].node as Element;
const cache = CacheUtil.getCache(ruleContext.ownerDocument, "combobox", {});
if (!cache) return null;
const cacheKey = context["dom"].rolePath;
const cachedElem = cache[cacheKey];
if (!cachedElem) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const element_accesskey_unique: Rule = {
run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => {
const ruleContext = context["dom"].node as Element;
let map = CacheUtil.getCache(ruleContext.ownerDocument, "element_accesskey_unique", {});

let key = ruleContext.getAttribute("accesskey");

let passed = !(key in map);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const table_headers_related: Rule = {

let rcInfo = CacheUtil.getCache(ruleContext, "table_headers_related", null);
let tInfo = CacheUtil.getCache(parentTable, "table_headers_related", null);
let passed = rcInfo !== null && tInfo !== null && rcInfo in tInfo;
let passed = rcInfo && tInfo && rcInfo in tInfo;

if (!passed && rcInfo === "0:0" &&
CommonUtil.getInnerText(ruleContext).trim().length == 0) {
Expand Down
4 changes: 2 additions & 2 deletions accessibility-checker-engine/src/v4/util/CSSUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class CSSUtil {
}

let storedStyles = CacheUtil.getCache(elem, "RPTUtil_DefinedStyles", null);
if (!pseudoClass && storedStyles !== null) {
if (!pseudoClass && storedStyles) {
definedStyles = storedStyles["definedStyles"];
definedStylePseudo = storedStyles["definedStylePseudo"];
} else {
Expand Down Expand Up @@ -868,7 +868,7 @@ export class CSSUtil {
let walkNode = elem;
while (walkNode !== null) {
const node = CacheUtil.getCache(walkNode, "AriaUtil_AncestorWithStyles", null);
if (node !== null) return node;
if (node) return node;

const styles = CSSUtil.getDefinedStyles(walkNode);
for (const style in styleProps) {
Expand Down
2 changes: 2 additions & 0 deletions accessibility-checker-engine/src/v4/util/CacheUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class CacheUtil {
/* Return a pointer to the given global variable
* with its initial value as given */
public static getCache(cacheSpot: Element | Document | DocumentFragment, keyName, initValue) {
if (!cacheSpot) return undefined;
let cacheObj = (cacheSpot.nodeType === 9 /* Node.DOCUMENT_NODE */ || cacheSpot.nodeType === 11 /* Node.DOCUMENT_FRAGMENT_NODE */) ? cacheSpot as CacheDocument : cacheSpot as CacheElement;
if (cacheObj.aceCache === undefined) {
cacheObj.aceCache = {}
Expand All @@ -35,6 +36,7 @@ export class CacheUtil {
}

public static setCache(cacheSpot: Document | Element | DocumentFragment | ShadowRoot, globalName, value): any {
if (!cacheSpot) return undefined;
let cacheObj = (cacheSpot.nodeType === 9 /* Node.DOCUMENT_NODE */ || cacheSpot.nodeType === 11 /* Node.DOCUMENT_FRAGMENT_NODE */) ? cacheSpot as CacheDocument : cacheSpot as CacheElement;
if (cacheObj.aceCache === undefined) {
cacheObj.aceCache = {}
Expand Down
1 change: 1 addition & 0 deletions accessibility-checker-engine/src/v4/util/VisUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export class VisUtil {
* @param node
*/
public static isNodeHiddenFromAT(node: Element) : boolean {
if (!node) return false;
const vis = CacheUtil.getCache(node, "PT_NODE_HiddenFromAT", undefined);
if (vis !== undefined) return vis;

Expand Down

0 comments on commit 712c8d2

Please sign in to comment.