Search in sources :

Example 1 with DOMException

use of com.gargoylesoftware.htmlunit.javascript.host.dom.DOMException in project htmlunit by HtmlUnit.

the class HTMLMediaElement method play.

/**
 * Begins playback of the media.
 *
 * @return a {@link Promise} which is fulfilled when playback has been started,
 *         or is rejected if for any reason playback cannot be started
 */
@JsxFunction
public Object play() {
    if (getBrowserVersion().hasFeature(JS_PROMISE)) {
        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 play().", DOMException.NOT_FOUND_ERR) });
    }
    return Undefined.instance;
}
Also used : DOMException(com.gargoylesoftware.htmlunit.javascript.host.dom.DOMException) LambdaConstructor(net.sourceforge.htmlunit.corejs.javascript.LambdaConstructor) LambdaFunction(net.sourceforge.htmlunit.corejs.javascript.LambdaFunction) Scriptable(net.sourceforge.htmlunit.corejs.javascript.Scriptable) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 2 with DOMException

use of com.gargoylesoftware.htmlunit.javascript.host.dom.DOMException in project htmlunit by HtmlUnit.

the class XMLDocument method loadXML.

/**
 * Loads an XML document using the supplied string.
 *
 * @param strXML A string containing the XML string to load into this XML document object
 *        This string can contain an entire XML document or a well-formed fragment.
 * @return true if the load succeeded; false if the load failed
 */
public boolean loadXML(final String strXML) {
    final WebWindow webWindow = getWindow().getWebWindow();
    try {
        if (StringUtils.isEmpty(strXML) && getBrowserVersion().hasFeature(JS_DOMPARSER_EMPTY_STRING_IS_ERROR)) {
            throw new IOException("Error parsing XML '" + strXML + "'");
        }
        final WebResponse webResponse = new StringWebResponse(strXML, webWindow.getEnclosedPage().getUrl());
        final XmlPage page = new XmlPage(webResponse, webWindow, false);
        setDomNode(page);
        return true;
    } catch (final IOException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Error parsing XML\n" + strXML, e);
        }
        if (getBrowserVersion().hasFeature(JS_DOMPARSER_EXCEPTION_ON_ERROR)) {
            throw asJavaScriptException(new DOMException("Syntax Error", DOMException.SYNTAX_ERR));
        }
        if (getBrowserVersion().hasFeature(JS_DOMPARSER_PARSERERROR_ON_ERROR)) {
            try {
                final XmlPage page = createParserErrorXmlPage("Syntax Error", webWindow);
                setDomNode(page);
            } catch (final IOException eI) {
                LOG.error("Could not handle ParserError", e);
            }
        }
        return false;
    }
}
Also used : StringWebResponse(com.gargoylesoftware.htmlunit.StringWebResponse) DOMException(com.gargoylesoftware.htmlunit.javascript.host.dom.DOMException) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) StringWebResponse(com.gargoylesoftware.htmlunit.StringWebResponse) XmlPage(com.gargoylesoftware.htmlunit.xml.XmlPage) IOException(java.io.IOException) WebWindow(com.gargoylesoftware.htmlunit.WebWindow)

Example 3 with DOMException

use of com.gargoylesoftware.htmlunit.javascript.host.dom.DOMException 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) });
}
Also used : DOMException(com.gargoylesoftware.htmlunit.javascript.host.dom.DOMException) LambdaConstructor(net.sourceforge.htmlunit.corejs.javascript.LambdaConstructor) LambdaFunction(net.sourceforge.htmlunit.corejs.javascript.LambdaFunction) Scriptable(net.sourceforge.htmlunit.corejs.javascript.Scriptable) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 4 with DOMException

use of com.gargoylesoftware.htmlunit.javascript.host.dom.DOMException in project htmlunit by HtmlUnit.

the class SubtleCrypto method notImplemented.

private Object notImplemented() {
    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("Operation is not supported", DOMException.NOT_SUPPORTED_ERR) });
}
Also used : DOMException(com.gargoylesoftware.htmlunit.javascript.host.dom.DOMException) LambdaConstructor(net.sourceforge.htmlunit.corejs.javascript.LambdaConstructor) LambdaFunction(net.sourceforge.htmlunit.corejs.javascript.LambdaFunction) Scriptable(net.sourceforge.htmlunit.corejs.javascript.Scriptable) HtmlUnitScriptable(com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable)

Aggregations

DOMException (com.gargoylesoftware.htmlunit.javascript.host.dom.DOMException)4 LambdaConstructor (net.sourceforge.htmlunit.corejs.javascript.LambdaConstructor)3 LambdaFunction (net.sourceforge.htmlunit.corejs.javascript.LambdaFunction)3 Scriptable (net.sourceforge.htmlunit.corejs.javascript.Scriptable)3 JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)2 StringWebResponse (com.gargoylesoftware.htmlunit.StringWebResponse)1 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)1 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)1 HtmlUnitScriptable (com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable)1 XmlPage (com.gargoylesoftware.htmlunit.xml.XmlPage)1 IOException (java.io.IOException)1