-
Notifications
You must be signed in to change notification settings - Fork 775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: avoid memory issues by doing better cleanup #4059
Changes from 4 commits
b4ed75c
dda5b09
dbf9716
2177955
04a7d4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import memoize from './memoize'; | ||
|
||
/** | ||
* Determines if a document node is XHTML | ||
* @method isXHTML | ||
* @memberof axe.utils | ||
* @param {Node} doc a document node | ||
* @return {Boolean} | ||
*/ | ||
function isXHTML(doc) { | ||
if (!doc.createElement) { | ||
const isXHTML = memoize(doc => { | ||
if (!doc?.createElement) { | ||
return false; | ||
} | ||
return doc.createElement('A').localName === 'A'; | ||
} | ||
}); | ||
|
||
export default isXHTML; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import caches from '../base/cache'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any particular reason you called this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heatwave 🌞 |
||
import { matchesExpression, convertSelector } from './matches'; | ||
import { getNodesMatchingExpression } from './selector-cache'; | ||
|
||
|
@@ -19,17 +20,20 @@ function createLocalVariables( | |
return retVal; | ||
} | ||
|
||
/** | ||
* Allocating new objects in createLocalVariables is quite expensive given | ||
* that matchExpressions is in the hot path. | ||
* | ||
* Keep track of previously allocated objects to avoid useless allocations | ||
* and garbage collection. This is intentionally shared between calls of | ||
* matchExpressions. | ||
*/ | ||
const recycledLocalVariables = []; | ||
|
||
function matchExpressions(domTree, expressions, filter) { | ||
/** | ||
* Allocating new objects in createLocalVariables is quite expensive given | ||
* that matchExpressions is in the hot path. | ||
* | ||
* Keep track of previously allocated objects to avoid useless allocations | ||
* and garbage collection. This is intentionally shared between calls of | ||
* matchExpressions. | ||
*/ | ||
const recycledLocalVariables = caches.get( | ||
'qsa.recycledLocalVariables', | ||
() => [] | ||
); | ||
|
||
const stack = []; | ||
const vNodes = Array.isArray(domTree) ? domTree : [domTree]; | ||
let currentLevel = createLocalVariables( | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -18,6 +18,7 @@ describe('region', function () { | |||||
afterEach(function () { | ||||||
fixture.innerHTML = ''; | ||||||
checkContext.reset(); | ||||||
axe.reset(); | ||||||
}); | ||||||
|
||||||
it('should return true when content is inside the region', function () { | ||||||
|
@@ -28,6 +29,23 @@ describe('region', function () { | |||||
assert.isTrue(checkEvaluate.apply(checkContext, checkArgs)); | ||||||
}); | ||||||
|
||||||
it('should return true when the region was removed from standards', () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
axe.configure({ | ||||||
standards: { | ||||||
ariaRoles: { | ||||||
feed: { | ||||||
type: 'landmark' | ||||||
} | ||||||
} | ||||||
} | ||||||
}); | ||||||
var checkArgs = checkSetup( | ||||||
'<div role="feed" id="target">This is random content.</div>' + | ||||||
'<div role="main"><h1 id="mainheader">Introduction</h1></div>' | ||||||
); | ||||||
assert.isTrue(checkEvaluate.apply(checkContext, checkArgs)); | ||||||
}); | ||||||
|
||||||
it('should return false when img content is outside the region', function () { | ||||||
var checkArgs = checkSetup( | ||||||
'<img id="target" src="data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"><div role="main"><h1 id="mainheader" tabindex="0">Introduction</h1></div>' | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.