/** * @return the url */ @JsxGetter public String getUrl() { if (url_ == null) { throw ScriptRuntime.typeError("invalid call"); } return url_.toString(); }
public static EcmaError typeError2(String messageId, String arg1, String arg2) { String msg = getMessage2(messageId, arg1, arg2); return typeError(msg); }
public static EcmaError typeError1(String messageId, String arg1) { String msg = getMessage1(messageId, arg1); return typeError(msg); }
public static EcmaError typeError3(String messageId, String arg1, String arg2, String arg3) { String msg = getMessage3(messageId, arg1, arg2, arg3); return typeError(msg); }
public static EcmaError typeError0(String messageId) { String msg = getMessage0(messageId); return typeError(msg); }
/** * Creates an instance. * * @param cx the current context * @param args the arguments to the ActiveXObject constructor * @param ctorObj the function object * @param inNewExpr Is new or not * @return the java object to allow JavaScript to access */ @JsxConstructor({CHROME, FF, EDGE}) public static Scriptable jsConstructor(final Context cx, final Object[] args, final Function ctorObj, final boolean inNewExpr) { throw ScriptRuntime.typeError("Illegal constructor"); }
/** * @return the url */ @JsxGetter public String getUrl() { if (url_ == null) { throw ScriptRuntime.typeError("invalid call"); } return url_.toString(); }
/** * Creates an instance. * * @param cx the current context * @param args the arguments to the ActiveXObject constructor * @param ctorObj the function object * @param inNewExpr Is new or not * @return the java object to allow JavaScript to access */ @JsxConstructor({CHROME, FF, EDGE}) public static Scriptable jsConstructor(final Context cx, final Object[] args, final Function ctorObj, final boolean inNewExpr) { throw ScriptRuntime.typeError("Illegal constructor"); }
/** * Creates an instance. * @param encoding the encoding */ @JsxConstructor public TextDecoder(final Object encoding) { if (Undefined.instance == encoding) { return; } final String enc = Context.toString(encoding); final Charset charset = ENCODINGS_.get(enc); if (charset != null) { encoding_ = charset.name(); return; } throw ScriptRuntime.typeError("Argument 1 '" + enc + "' is not a supported encoding"); }
/** * Creates an instance. * @param encoding the encoding */ @JsxConstructor public TextDecoder(final Object encoding) { if (Undefined.instance == encoding) { return; } final String enc = Context.toString(encoding); final Charset charset = ENCODINGS_.get(enc); if (charset != null) { encoding_ = charset.name(); return; } throw ScriptRuntime.typeError("Argument 1 '" + enc + "' is not a supported encoding"); }
/** * @param buffer to be decoded * @return returns the decoded string */ @JsxFunction public String decode(final Object buffer) { if (Undefined.instance == buffer) { return ""; } NativeArrayBuffer arrayBuffer = null; if (buffer instanceof NativeArrayBuffer) { arrayBuffer = (NativeArrayBuffer) buffer; } else if (buffer instanceof NativeArrayBufferView) { arrayBuffer = ((NativeArrayBufferView) buffer).getBuffer(); } if (arrayBuffer != null) { return new String(arrayBuffer.getBuffer(), Charset.forName(encoding_)); } throw ScriptRuntime.typeError("Argument 1 of TextDecoder.decode could not be" + " converted to any of: ArrayBufferView, ArrayBuffer."); } }
/** * @param buffer to be decoded * @return returns the decoded string */ @JsxFunction public String decode(final Object buffer) { if (Undefined.instance == buffer) { return ""; } NativeArrayBuffer arrayBuffer = null; if (buffer instanceof NativeArrayBuffer) { arrayBuffer = (NativeArrayBuffer) buffer; } else if (buffer instanceof NativeArrayBufferView) { arrayBuffer = ((NativeArrayBufferView) buffer).getBuffer(); } if (arrayBuffer != null) { return new String(arrayBuffer.getBuffer(), Charset.forName(encoding_)); } throw ScriptRuntime.typeError("Argument 1 of TextDecoder.decode could not be" + " converted to any of: ArrayBufferView, ArrayBuffer."); } }
/** * Sets a chunk of JavaScript to be invoked at some specified time later. * The invocation occurs only if the window is opened after the delay * and does not contain an other page than the one that originated the setTimeout. * * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout"> * MDN web docs</a> * * @param context the JavaScript context * @param thisObj the scriptable * @param args the arguments passed into the method * @param function the function * @return the id of the created timer */ @JsxFunction public static Object setTimeout(final Context context, final Scriptable thisObj, final Object[] args, final Function function) { if (args.length < 1) { throw ScriptRuntime.typeError("Function not provided"); } final int timeout = ScriptRuntime.toInt32((args.length > 1) ? args[1] : Undefined.instance); final Object[] params = (args.length > 2) ? Arrays.copyOfRange(args, 2, args.length) : ScriptRuntime.emptyArgs; return ((Window) thisObj).setTimeoutIntervalImpl(args[0], timeout, true, params); }
/** * Sets a chunk of JavaScript to be invoked each time a specified number of milliseconds has elapsed. * * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval"> * MDN web docs</a> * @param context the JavaScript context * @param thisObj the scriptable * @param args the arguments passed into the method * @param function the function * @return the id of the created interval */ @JsxFunction public static Object setInterval(final Context context, final Scriptable thisObj, final Object[] args, final Function function) { if (args.length < 1) { throw ScriptRuntime.typeError("Function not provided"); } final int timeout = ScriptRuntime.toInt32((args.length > 1) ? args[1] : Undefined.instance); final Object[] params = (args.length > 2) ? Arrays.copyOfRange(args, 2, args.length) : ScriptRuntime.emptyArgs; return ((Window) thisObj).setTimeoutIntervalImpl(args[0], timeout, false, params); }
/** * Sets a chunk of JavaScript to be invoked each time a specified number of milliseconds has elapsed. * * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval"> * MDN web docs</a> * @param context the JavaScript context * @param thisObj the scriptable * @param args the arguments passed into the method * @param function the function * @return the id of the created interval */ @JsxFunction public static Object setInterval(final Context context, final Scriptable thisObj, final Object[] args, final Function function) { if (args.length < 1) { throw ScriptRuntime.typeError("Function not provided"); } final int timeout = ScriptRuntime.toInt32((args.length > 1) ? args[1] : Undefined.instance); final Object[] params = (args.length > 2) ? Arrays.copyOfRange(args, 2, args.length) : ScriptRuntime.emptyArgs; return ((Window) thisObj).setTimeoutIntervalImpl(args[0], timeout, false, params); }
/** * Sets a chunk of JavaScript to be invoked at some specified time later. * The invocation occurs only if the window is opened after the delay * and does not contain an other page than the one that originated the setTimeout. * * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout"> * MDN web docs</a> * * @param context the JavaScript context * @param thisObj the scriptable * @param args the arguments passed into the method * @param function the function * @return the id of the created timer */ @JsxFunction public static Object setTimeout(final Context context, final Scriptable thisObj, final Object[] args, final Function function) { if (args.length < 1) { throw ScriptRuntime.typeError("Function not provided"); } final int timeout = ScriptRuntime.toInt32((args.length > 1) ? args[1] : Undefined.instance); final Object[] params = (args.length > 2) ? Arrays.copyOfRange(args, 2, args.length) : ScriptRuntime.emptyArgs; return ((Window) thisObj).setTimeoutIntervalImpl(args[0], timeout, true, params); }
/** * Creates an instance. * @param url a string representing an absolute or relative URL. * If url is a relative URL, base is required, and will be used * as the base URL. If url is an absolute URL, a given base will be ignored. * @param base a string representing the base URL to use in case url * is a relative URL. If not specified, it defaults to ''. */ @JsxConstructor({CHROME, FF, EDGE}) public URL(final String url, final Object base) { String baseStr = null; if (Undefined.instance != base) { baseStr = Context.toString(base); } try { if (StringUtils.isBlank(baseStr)) { url_ = UrlUtils.toUrlUnsafe(url); } else { final java.net.URL baseUrl = UrlUtils.toUrlUnsafe(baseStr); url_ = new java.net.URL(baseUrl, url); } } catch (final MalformedURLException e) { throw ScriptRuntime.typeError(e.toString()); } }
/** * Creates an instance. * @param url a string representing an absolute or relative URL. * If url is a relative URL, base is required, and will be used * as the base URL. If url is an absolute URL, a given base will be ignored. * @param base a string representing the base URL to use in case url * is a relative URL. If not specified, it defaults to ''. */ @JsxConstructor({CHROME, FF, EDGE}) public URL(final String url, final Object base) { String baseStr = null; if (Undefined.instance != base) { baseStr = Context.toString(base); } try { if (StringUtils.isBlank(baseStr)) { url_ = UrlUtils.toUrlUnsafe(url); } else { final java.net.URL baseUrl = UrlUtils.toUrlUnsafe(baseStr); url_ = new java.net.URL(baseUrl, url); } } catch (final MalformedURLException e) { throw ScriptRuntime.typeError(e.toString()); } }
/** * Returns true if the element would be selected by the specified selector string; otherwise, returns false. * @param context the JavaScript context * @param thisObj the scriptable * @param args the arguments passed into the method * @param function the function * @return the value */ @JsxFunction({CHROME, FF, EDGE}) public static boolean matches( final Context context, final Scriptable thisObj, final Object[] args, final Function function) { final String selectorString = (String) args[0]; if (!(thisObj instanceof Element)) { throw ScriptRuntime.typeError("Illegal invocation"); } try { final DomNode domNode = ((Element) thisObj).getDomNodeOrNull(); return domNode != null && ((DomElement) domNode).matches(selectorString); } catch (final CSSException e) { throw ScriptRuntime.constructError("SyntaxError", "An invalid or illegal selector was specified (selector: '" + selectorString + "' error: " + e.getMessage() + ")."); } }
/** * Returns true if the element would be selected by the specified selector string; otherwise, returns false. * @param context the JavaScript context * @param thisObj the scriptable * @param args the arguments passed into the method * @param function the function * @return the value */ @JsxFunction({CHROME, FF, EDGE}) public static boolean matches( final Context context, final Scriptable thisObj, final Object[] args, final Function function) { final String selectorString = (String) args[0]; if (!(thisObj instanceof Element)) { throw ScriptRuntime.typeError("Illegal invocation"); } try { final DomNode domNode = ((Element) thisObj).getDomNodeOrNull(); return domNode != null && ((DomElement) domNode).matches(selectorString); } catch (final CSSException e) { throw ScriptRuntime.constructError("SyntaxError", "An invalid or illegal selector was specified (selector: '" + selectorString + "' error: " + e.getMessage() + ")."); } }