use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class Console method assertMethod.
/**
* This method writes an error message to the console if the
* assertion is false. If the assertion is true, nothing happens.
* @param cx the JavaScript context
* @param thisObj the scriptable
* @param args the arguments passed into the method
* @param funObj the function
*/
@JsxFunction(functionName = "assert")
public static void assertMethod(final Context cx, final Scriptable thisObj, final Object[] args, final Function funObj) {
if (args.length < 1 || ScriptRuntime.toBoolean(args[0])) {
return;
}
if (args.length == 1) {
log(cx, thisObj, new String[] { "Assertion failed" }, null);
return;
}
final Object[] data;
final Object first = args[1];
if (first instanceof CharSequence || first instanceof ScriptableObject && ("String".equals(((Scriptable) first).getClassName()))) {
data = new Object[args.length - 1];
data[0] = "Assertion failed: " + first;
System.arraycopy(args, 2, data, 1, data.length - 1);
} else {
data = new Object[args.length];
data[0] = "Assertion failed:";
System.arraycopy(args, 1, data, 1, data.length - 1);
}
log(cx, thisObj, data, null);
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class ApplicationCache method dispatchEvent.
/**
* Dispatches an event into the event system (standards-conformant browsers only). See
* <a href="https://developer.mozilla.org/en-US/docs/DOM/element.dispatchEvent">the Gecko
* DOM reference</a> for more information.
*
* @param event the event to be dispatched
* @return {@code false} if at least one of the event handlers which handled the event
* called <tt>preventDefault</tt>; {@code true} otherwise
*/
@Override
@JsxFunction
public boolean dispatchEvent(final Event event) {
event.setTarget(this);
final ScriptResult result = fireEvent(event);
return !event.isAborted(result);
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class URLSearchParams method append.
/**
* The append() method of the URLSearchParams interface appends a specified
* key/value pair as a new search parameter.
*
* @param name The name of the parameter to append.
* @param value The value of the parameter to append.
*/
@JsxFunction
public void append(final String name, final String value) {
String search = url_.getSearch();
final List<NameValuePair> pairs;
if (search == null || search.isEmpty()) {
pairs = new ArrayList<>(1);
} else {
search = UrlUtils.decode(search);
pairs = splitQuery(search);
}
pairs.add(new NameValuePair(name, value));
try {
url_.setSearch(pairs);
} catch (final MalformedURLException e) {
LOG.error(e.getMessage(), e);
}
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class URLSearchParams method getAll.
/**
* The getAll() method of the URLSearchParams interface returns all the values
* associated with a given search parameter as an array.
*
* @param name The name of the parameter to return.
* @return An array of USVStrings.
*/
@JsxFunction
public Scriptable getAll(final String name) {
final List<NameValuePair> splitted = splitQuery();
final List<String> result = new ArrayList<>(splitted.size());
for (final NameValuePair param : splitted) {
if (param.getName().equals(name)) {
result.add(param.getValue());
}
}
return Context.getCurrentContext().newArray(getWindow(this), result.toArray());
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class HTMLCollectionFrames method scrollTo.
/**
* Scrolls to the specified location on the page.
* @param x the horizontal position to scroll to
* @param y the vertical position to scroll to
*/
@JsxFunction
public void scrollTo(final int x, final int y) {
final HTMLElement body = document_.getBody();
if (body != null) {
body.setScrollLeft(x);
body.setScrollTop(y);
final Event event = new Event(body, Event.TYPE_SCROLL);
body.fireEvent(event);
}
}
Aggregations