use of com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable in project htmlunit by HtmlUnit.
the class RowContainer method insertRow.
/**
* Inserts a new row at the given position.
* @param index the index where the row should be inserted (0 <= index <= nbRows)
* @return the inserted row
*/
public Object insertRow(final int index) {
final HTMLCollection rows = (HTMLCollection) getRows();
final int rowCount = rows.getLength();
final DomElement newRow = ((HtmlPage) getDomNodeOrDie().getPage()).createElement("tr");
if (rowCount == 0) {
getDomNodeOrDie().appendChild(newRow);
} else if (index == rowCount) {
final HtmlUnitScriptable row = (HtmlUnitScriptable) rows.item(Integer.valueOf(index - 1));
row.getDomNodeOrDie().getParentNode().appendChild(newRow);
} else {
final HtmlUnitScriptable row = (HtmlUnitScriptable) rows.item(Integer.valueOf(index));
// if at the end, then in the same "sub-container" as the last existing row
if (index > rowCount - 1) {
row.getDomNodeOrDie().getParentNode().appendChild(newRow);
} else {
row.getDomNodeOrDie().insertBefore(newRow);
}
}
return getScriptableFor(newRow);
}
use of com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable 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());
}
}
}
use of com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable in project htmlunit by HtmlUnit.
the class XMLDocument method makeScriptableFor.
/**
* {@inheritDoc}
*/
@Override
public HtmlUnitScriptable makeScriptableFor(final DomNode domNode) {
final HtmlUnitScriptable scriptable;
// TODO: cleanup, getScriptObject() should be used!!!
if (domNode instanceof DomElement && !(domNode instanceof HtmlElement)) {
if (domNode instanceof SvgElement) {
final Class<? extends HtmlUnitScriptable> javaScriptClass = ((JavaScriptEngine) getWindow().getWebWindow().getWebClient().getJavaScriptEngine()).getJavaScriptClass(domNode.getClass());
try {
scriptable = javaScriptClass.newInstance();
} catch (final Exception e) {
throw Context.throwAsScriptRuntimeEx(e);
}
} else {
scriptable = new Element();
}
} else if (domNode instanceof DomAttr) {
scriptable = new Attr();
} else {
return super.makeScriptableFor(domNode);
}
scriptable.setPrototype(getPrototype(scriptable.getClass()));
scriptable.setParentScope(getParentScope());
scriptable.setDomNode(domNode);
return scriptable;
}
Aggregations