use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor in project htmlunit by HtmlUnit.
the class ProgressEvent method jsConstructor.
/**
* {@inheritDoc}
*/
@Override
@JsxConstructor({ CHROME, EDGE, FF, FF_ESR })
public void jsConstructor(final String type, final ScriptableObject details) {
super.jsConstructor(type, details);
if (details != null && !Undefined.isUndefined(details)) {
final Object lengthComputable = details.get("lengthComputable");
if (lengthComputable instanceof Boolean) {
lengthComputable_ = (Boolean) lengthComputable;
} else {
lengthComputable_ = Boolean.parseBoolean(lengthComputable.toString());
}
final Object loaded = details.get("loaded");
if (loaded instanceof Long) {
loaded_ = loaded;
} else if (loaded instanceof Double) {
loaded_ = ((Double) loaded).longValue();
} else {
try {
loaded_ = Long.parseLong(loaded.toString());
} catch (final NumberFormatException e) {
// ignore
}
}
final Object total = details.get("total");
if (total instanceof Long) {
total_ = (Long) total;
} else if (total instanceof Double) {
total_ = ((Double) total).longValue();
} else {
try {
total_ = Long.parseLong(details.get("total").toString());
} catch (final NumberFormatException e) {
// ignore
}
}
}
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor in project htmlunit by HtmlUnit.
the class ImageData method jsConstructor.
/**
* JavaScript constructor.
* @param cx the current context
* @param args the arguments to the WebSocket constructor
* @param ctorObj the function object
* @param inNewExpr Is new or not
* @return the java object to allow JavaScript to access
*/
@JsxConstructor({ CHROME, EDGE, FF, FF_ESR })
public static Scriptable jsConstructor(final Context cx, final Object[] args, final Function ctorObj, final boolean inNewExpr) {
if (args.length < 2) {
throw Context.reportRuntimeError("ImageData ctor - too less arguments");
}
NativeUint8ClampedArray data = null;
final int width;
final int height;
if (args[0] instanceof NativeUint8ClampedArray) {
data = (NativeUint8ClampedArray) args[0];
if (data.getArrayLength() % 4 != 0) {
throw Context.reportRuntimeError("ImageData ctor - data length mod 4 not zero");
}
width = (int) ScriptRuntime.toInteger(args[1]);
if (args.length < 3) {
height = data.getArrayLength() / 4 / width;
if (data.getArrayLength() != 4 * width * height) {
throw Context.reportRuntimeError("ImageData ctor - width not correct");
}
} else {
height = (int) ScriptRuntime.toInteger(args[2]);
}
if (data.getArrayLength() != 4 * width * height) {
throw Context.reportRuntimeError("ImageData ctor - width/height not correct");
}
} else {
width = (int) ScriptRuntime.toInteger(args[0]);
height = (int) ScriptRuntime.toInteger(args[1]);
}
if (width < 0) {
throw Context.reportRuntimeError("ImageData ctor - width negative");
}
if (height < 0) {
throw Context.reportRuntimeError("ImageData ctor - height negative");
}
final ImageData result = new ImageData(null, 0, 0, width, height);
if (data != null) {
final byte[] bytes = data.getBuffer().getBuffer();
System.arraycopy(bytes, 0, result.bytes_, 0, Math.min(bytes.length, result.bytes_.length));
}
return result;
}
Aggregations