-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts (most of) commits c039e52 and 908f27d. Per #3659, the performance of dom-selector is currently too slow. Closes #3659.
- Loading branch information
Showing
7 changed files
with
137 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,47 @@ | ||
"use strict"; | ||
|
||
const domSelector = require("@asamuzakjp/dom-selector"); | ||
const { wrapperForImpl } = require("../generated/utils"); | ||
|
||
exports.matchesDontThrow = (selectors, elementImpl) => { | ||
const element = wrapperForImpl(elementImpl); | ||
try { | ||
return domSelector.matches(selectors, element); | ||
} catch { | ||
return false; | ||
const nwsapi = require("nwsapi"); | ||
|
||
const idlUtils = require("../generated/utils"); | ||
|
||
function initNwsapi(node) { | ||
const { _globalObject, _ownerDocument } = node; | ||
|
||
return nwsapi({ | ||
document: idlUtils.wrapperForImpl(_ownerDocument), | ||
DOMException: _globalObject.DOMException | ||
}); | ||
} | ||
|
||
exports.matchesDontThrow = (elImpl, selector) => { | ||
const document = elImpl._ownerDocument; | ||
|
||
if (!document._nwsapiDontThrow) { | ||
document._nwsapiDontThrow = initNwsapi(elImpl); | ||
document._nwsapiDontThrow.configure({ | ||
LOGERRORS: false, | ||
VERBOSITY: false, | ||
IDS_DUPES: true, | ||
MIXEDCASE: true | ||
}); | ||
} | ||
}; | ||
|
||
exports.matches = (selectors, elementImpl) => { | ||
const element = wrapperForImpl(elementImpl); | ||
return domSelector.matches(selectors, element); | ||
return document._nwsapiDontThrow.match(selector, idlUtils.wrapperForImpl(elImpl)); | ||
}; | ||
|
||
exports.closest = (selectors, elementImpl) => { | ||
const element = wrapperForImpl(elementImpl); | ||
return domSelector.closest(selectors, element); | ||
}; | ||
// nwsapi gets `document.documentElement` at creation-time, so we have to initialize lazily, since in the initial | ||
// stages of Document initialization, there is no documentElement present yet. | ||
exports.addNwsapi = parentNode => { | ||
const document = parentNode._ownerDocument; | ||
|
||
exports.querySelector = (selectors, parentNodeImpl) => { | ||
const node = wrapperForImpl(parentNodeImpl); | ||
return domSelector.querySelector(selectors, node); | ||
}; | ||
if (!document._nwsapi) { | ||
document._nwsapi = initNwsapi(parentNode); | ||
document._nwsapi.configure({ | ||
LOGERRORS: false, | ||
IDS_DUPES: true, | ||
MIXEDCASE: true | ||
}); | ||
} | ||
|
||
exports.querySelectorAll = (selectors, parentNodeImpl) => { | ||
const node = wrapperForImpl(parentNodeImpl); | ||
return domSelector.querySelectorAll(selectors, node); | ||
return document._nwsapi; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.