Search in sources :

Example 1 with Delegator

use of net.sourceforge.htmlunit.corejs.javascript.Delegator in project htmlunit by HtmlUnit.

the class Console method dir.

/**
 * Implementation of console {@code dir} function. This method does not enter recursively
 * in the passed object, nor prints the details of objects or functions.
 * @param o the object to be printed
 */
@JsxFunction
public void dir(final Object o) {
    if (o instanceof ScriptableObject) {
        final ScriptableObject obj = (ScriptableObject) o;
        final Object[] ids = obj.getIds();
        if (ids != null && ids.length > 0) {
            final StringBuilder sb = new StringBuilder();
            for (final Object id : ids) {
                final Object value = obj.get(id);
                if (value instanceof Delegator) {
                    sb.append(id).append(": ").append(((Delegator) value).getClassName()).append('\n');
                } else if (value instanceof HtmlUnitScriptable) {
                    sb.append(id).append(": ").append(((HtmlUnitScriptable) value).getClassName()).append('\n');
                } else if (value instanceof BaseFunction) {
                    sb.append(id).append(": function ").append(((BaseFunction) value).getFunctionName()).append("()\n");
                } else {
                    sb.append(id).append(": ").append(value).append('\n');
                }
            }
            getWebConsole().info(sb.toString());
        }
    }
}
Also used : HtmlUnitScriptable(com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable) BaseFunction(net.sourceforge.htmlunit.corejs.javascript.BaseFunction) ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) Delegator(net.sourceforge.htmlunit.corejs.javascript.Delegator) ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) NativeObject(net.sourceforge.htmlunit.corejs.javascript.NativeObject) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Aggregations

HtmlUnitScriptable (com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable)1 JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)1 BaseFunction (net.sourceforge.htmlunit.corejs.javascript.BaseFunction)1 Delegator (net.sourceforge.htmlunit.corejs.javascript.Delegator)1 NativeObject (net.sourceforge.htmlunit.corejs.javascript.NativeObject)1 ScriptableObject (net.sourceforge.htmlunit.corejs.javascript.ScriptableObject)1