Search in sources :

Example 1 with FF

use of com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF in project htmlunit by HtmlUnit.

the class NodeList method forEach.

/**
 * Calls the {@code callback} given in parameter once for each value pair in the list, in insertion order.
 * @param callback function to execute for each element
 */
@JsxFunction({ CHROME, EDGE, FF, FF_ESR })
public void forEach(final Object callback) {
    final List<DomNode> nodes = getElements();
    final WebClient client = getWindow().getWebWindow().getWebClient();
    final HtmlUnitContextFactory cf = ((JavaScriptEngine) client.getJavaScriptEngine()).getContextFactory();
    final ContextAction<Object> contextAction = cx -> {
        final Function function = (Function) callback;
        final Scriptable scope = getParentScope();
        for (int i = 0; i < nodes.size(); i++) {
            function.call(cx, scope, NodeList.this, new Object[] { nodes.get(i).getScriptableObject(), i, NodeList.this });
        }
        return null;
    };
    cf.call(contextAction);
}
Also used : Scriptable(net.sourceforge.htmlunit.corejs.javascript.Scriptable) JsxSymbol(com.gargoylesoftware.htmlunit.javascript.configuration.JsxSymbol) HtmlUnitContextFactory(com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory) ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) DomNode(com.gargoylesoftware.htmlunit.html.DomNode) HtmlUnitScriptable(com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable) CHROME(com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME) FF(com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF) EDGE(com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE) ES6Iterator(net.sourceforge.htmlunit.corejs.javascript.ES6Iterator) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction) JsxClass(com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass) List(java.util.List) NativeArrayIterator(net.sourceforge.htmlunit.corejs.javascript.NativeArrayIterator) ContextAction(net.sourceforge.htmlunit.corejs.javascript.ContextAction) JsxConstructor(com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor) FF_ESR(com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF_ESR) WebClient(com.gargoylesoftware.htmlunit.WebClient) JavaScriptEngine(com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine) Function(net.sourceforge.htmlunit.corejs.javascript.Function) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction) Function(net.sourceforge.htmlunit.corejs.javascript.Function) DomNode(com.gargoylesoftware.htmlunit.html.DomNode) HtmlUnitContextFactory(com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory) ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) Scriptable(net.sourceforge.htmlunit.corejs.javascript.Scriptable) HtmlUnitScriptable(com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable) WebClient(com.gargoylesoftware.htmlunit.WebClient) JavaScriptEngine(com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Aggregations

WebClient (com.gargoylesoftware.htmlunit.WebClient)1 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)1 HtmlUnitContextFactory (com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory)1 HtmlUnitScriptable (com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable)1 JavaScriptEngine (com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine)1 JsxClass (com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass)1 JsxConstructor (com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor)1 JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)1 JsxSymbol (com.gargoylesoftware.htmlunit.javascript.configuration.JsxSymbol)1 CHROME (com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME)1 EDGE (com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE)1 FF (com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF)1 FF_ESR (com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF_ESR)1 List (java.util.List)1 ContextAction (net.sourceforge.htmlunit.corejs.javascript.ContextAction)1 ES6Iterator (net.sourceforge.htmlunit.corejs.javascript.ES6Iterator)1 Function (net.sourceforge.htmlunit.corejs.javascript.Function)1 NativeArrayIterator (net.sourceforge.htmlunit.corejs.javascript.NativeArrayIterator)1 Scriptable (net.sourceforge.htmlunit.corejs.javascript.Scriptable)1 ScriptableObject (net.sourceforge.htmlunit.corejs.javascript.ScriptableObject)1