use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class XSLTProcessor method transformToFragment.
/**
* Transforms the node source applying the stylesheet given by the importStylesheet() function.
* The owner document of the output node owns the returned document fragment.
* @param source the node to be transformed
* @param output This document is used to generate the output
* @return the result of the transformation
*/
@JsxFunction
public DocumentFragment transformToFragment(final Node source, final Object output) {
final SgmlPage page = (SgmlPage) ((Document) output).getDomNodeOrDie();
final DomDocumentFragment fragment = page.createDocumentFragment();
final DocumentFragment rv = new DocumentFragment();
rv.setPrototype(getPrototype(rv.getClass()));
rv.setParentScope(getParentScope());
rv.setDomNode(fragment);
transform(source, fragment);
return rv;
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class WorkerJob method postMessage.
/**
* Posts a message to the {@link Worker} in the page's context.
* @param message the message
*/
@JsxFunction
public void postMessage(final Object message) {
final MessageEvent event = new MessageEvent();
event.initMessageEvent(Event.TYPE_MESSAGE, false, false, message, origin_, "", owningWindow_, Undefined.instance);
event.setParentScope(owningWindow_);
event.setPrototype(owningWindow_.getPrototype(event.getClass()));
if (LOG.isDebugEnabled()) {
LOG.debug("[DedicatedWorker] postMessage: {}" + message);
}
final JavaScriptEngine jsEngine = (JavaScriptEngine) owningWindow_.getWebWindow().getWebClient().getJavaScriptEngine();
final ContextAction<Object> action = cx -> {
worker_.getEventListenersContainer().executeCapturingListeners(event, null);
final Object[] args = { event };
worker_.getEventListenersContainer().executeBubblingListeners(event, args);
return null;
};
final ContextFactory cf = jsEngine.getContextFactory();
final JavaScriptJob job = new WorkerJob(cf, action, "postMessage: " + Context.toString(message));
final HtmlPage page = (HtmlPage) owningWindow_.getDocument().getPage();
owningWindow_.getWebWindow().getJobManager().addJob(job, page);
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction 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.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class MediaDevices method getUserMedia.
@JsxFunction
public Object getUserMedia() {
final Scriptable scope = ScriptableObject.getTopLevelScope(this);
final LambdaConstructor ctor = (LambdaConstructor) getProperty(scope, "Promise");
final LambdaFunction reject = (LambdaFunction) getProperty(ctor, "reject");
return reject.call(Context.getCurrentContext(), this, ctor, new Object[] { new DOMException("HtmlUnit does not support media streaming.", DOMException.NOT_FOUND_ERR) });
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class XMLDOMCharacterData method insertData.
/**
* Inserts a string at the specified offset.
* @param offset the offset, in characters, at which to insert the supplied string data
* @param data the data that is to be inserted into the existing string
*/
@JsxFunction
public void insertData(final int offset, final String data) {
if (data == null || "null".equals(data)) {
throw Context.reportRuntimeError("Type mismatch.");
}
if (data.isEmpty()) {
return;
}
if (offset < 0) {
throw Context.reportRuntimeError("The offset must be 0 or a positive number that is not greater than the " + "number of characters in the data.");
}
final DomCharacterData domCharacterData = getDomNodeOrDie();
if (offset > domCharacterData.getLength()) {
throw Context.reportRuntimeError("The offset must be 0 or a positive number that is not greater than the " + "number of characters in the data.");
}
domCharacterData.insertData(offset, data);
}
Aggregations