use of com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable in project htmlunit by HtmlUnit.
the class HtmlPage method cloneNode.
/**
* {@inheritDoc}
*/
@Override
public HtmlPage cloneNode(final boolean deep) {
// we need the ScriptObject clone before cloning the kids.
final HtmlPage result = (HtmlPage) super.cloneNode(false);
if (getWebClient().isJavaScriptEnabled()) {
final HtmlUnitScriptable jsObjClone = ((HtmlUnitScriptable) getScriptableObject()).clone();
jsObjClone.setDomNode(result);
}
// if deep, clone the kids too, and re initialize parts of the clone
if (deep) {
synchronized (lock_) {
result.attributeListeners_ = null;
}
result.selectionRanges_ = new ArrayList<>(3);
result.afterLoadActions_ = new ArrayList<>();
result.frameElements_ = new TreeSet<>(documentPositionComparator);
for (DomNode child = getFirstChild(); child != null; child = child.getNextSibling()) {
result.appendChild(child.cloneNode(true));
}
}
return result;
}
use of com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable in project htmlunit by HtmlUnit.
the class DomNode method getScriptableObject.
/**
* <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
*
* Returns the JavaScript object that corresponds to this node, lazily initializing a new one if necessary.
*
* The logic of when and where the JavaScript object is created needs a clean up: functions using
* a DOM node's JavaScript object should not have to check if they should create it first.
*
* @param <T> the object type
* @return the JavaScript object that corresponds to this node
*/
@SuppressWarnings("unchecked")
public <T> T getScriptableObject() {
if (scriptObject_ == null) {
final SgmlPage page = getPage();
if (this == page) {
final StringBuilder msg = new StringBuilder("No script object associated with the Page.");
// because this is a strange case we like to provide as much info as possible
msg.append(" class: '").append(page.getClass().getName()).append('\'');
try {
msg.append(" url: '").append(page.getUrl()).append("' content: ").append(page.getWebResponse().getContentAsString());
} catch (final Exception e) {
// ok bad luck with detail
msg.append(" no details: '").append(e).append('\'');
}
throw new IllegalStateException(msg.toString());
}
final Object o = page.getScriptableObject();
if (o instanceof HtmlUnitScriptable) {
scriptObject_ = ((HtmlUnitScriptable) o).makeScriptableFor(this);
}
}
return (T) scriptObject_;
}
use of com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable in project htmlunit by HtmlUnit.
the class RowContainer method moveRow.
/**
* Moves the row at the specified source index to the specified target index, returning
* the row that was moved.
* @param sourceIndex the index of the row to move
* @param targetIndex the index to move the row to
* @return the row that was moved
*/
@JsxFunction(IE)
public Object moveRow(final int sourceIndex, final int targetIndex) {
final HTMLCollection rows = (HTMLCollection) getRows();
final int rowCount = rows.getLength();
final boolean sourceIndexValid = sourceIndex >= 0 && sourceIndex < rowCount;
final boolean targetIndexValid = targetIndex >= 0 && targetIndex < rowCount;
if (sourceIndexValid && targetIndexValid) {
final HtmlUnitScriptable sourceRow = (HtmlUnitScriptable) rows.item(Integer.valueOf(sourceIndex));
final HtmlUnitScriptable targetRow = (HtmlUnitScriptable) rows.item(Integer.valueOf(targetIndex));
targetRow.getDomNodeOrDie().insertBefore(sourceRow.getDomNodeOrDie());
return sourceRow;
}
return null;
}
use of com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable in project htmlunit by HtmlUnit.
the class Intl method define.
private void define(final Class<? extends HtmlUnitScriptable> c, final BrowserVersion browserVersion) {
try {
final ClassConfiguration config = AbstractJavaScriptConfiguration.getClassConfiguration(c, browserVersion);
final HtmlUnitScriptable prototype = JavaScriptEngine.configureClass(config, this, browserVersion);
final FunctionObject functionObject = new RecursiveFunctionObject(c.getSimpleName(), config.getJsConstructor(), this);
if (c == V8BreakIterator.class) {
prototype.setClassName("v8BreakIterator");
}
functionObject.addAsConstructor(this, prototype);
} catch (final Exception e) {
throw Context.throwAsScriptRuntimeEx(e);
}
}
use of com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable in project htmlunit by HtmlUnit.
the class RowContainer method deleteRow.
/**
* Deletes the row at the specified index.
* @see <a href="http://msdn.microsoft.com/en-us/library/ms536408.aspx">MSDN Documentation</a>
* @param rowIndex the zero-based index of the row to delete
*/
@JsxFunction
public void deleteRow(int rowIndex) {
final HTMLCollection rows = (HTMLCollection) getRows();
final int rowCount = rows.getLength();
if (rowIndex == -1) {
rowIndex = rowCount - 1;
}
final boolean rowIndexValid = rowIndex >= 0 && rowIndex < rowCount;
if (rowIndexValid) {
final HtmlUnitScriptable row = (HtmlUnitScriptable) rows.item(Integer.valueOf(rowIndex));
row.getDomNodeOrDie().remove();
}
}
Aggregations