fontoxpath
Version:
A minimalistic XPath 3.1 engine in JavaScript
42 lines (35 loc) • 1.54 kB
JavaScript
const fontoxpath = require('../dist/fontoxpath');
const slimdom = require('slimdom');
function generateDom (document, depth, width, elementName) {
const rootNode = document.createElement(elementName);
document.appendChild(rootNode);
function generateChildren (parentNode, depth) {
if (depth < 0) {
return;
}
const prototypeChild = parentNode.cloneNode(false);
parentNode.appendChild(prototypeChild);
generateChildren(prototypeChild, depth - 1, elementName);
for (let i = 1; i < width; ++i) {
parentNode.appendChild(prototypeChild.cloneNode(true));
}
}
generateChildren(rootNode, depth);
return rootNode;
}
var rootNode = generateDom(slimdom.createDocument(), 5, 5, 'someElement');
// function printStatus(fn) {
// switch(%GetOptimizationStatus(fn)) {
// case 1: console.log("Function is optimized"); break;
// case 2: console.log("Function is not optimized"); break;
// case 3: console.log("Function is always optimized"); break;
// case 4: console.log("Function is never optimized"); break;
// case 6: console.log("Function is maybe deoptimized"); break;
// case 7: console.log("Function is optimized by TurboFan"); break;
// default: console.log("Unknown optimization status"); break;
// }
// }
//Fill type-info
fontoxpath.evaluateXPathToNumber('//someElement/* => count()', rootNode);
// 2 calls are needed to go from uninitialized -> pre-monomorphic -> monomorphic
fontoxpath.evaluateXPathToNumber('//someElement/* => count()', rootNode);