use of net.sourceforge.htmlunit.corejs.javascript.LambdaConstructor in project htmlunit by HtmlUnit.
the class Blob method text.
/**
* @return a Promise that resolves with a string containing the
* contents of the blob, interpreted as UTF-8.
*/
@JsxFunction({ CHROME, EDGE, FF, FF_ESR })
public Object text() {
final Scriptable scope = ScriptableObject.getTopLevelScope(this);
final LambdaConstructor ctor = (LambdaConstructor) getProperty(scope, "Promise");
try {
final LambdaFunction resolve = (LambdaFunction) getProperty(ctor, "resolve");
return resolve.call(Context.getCurrentContext(), this, ctor, new Object[] { getBackend().getText() });
} catch (final IOException e) {
final LambdaFunction reject = (LambdaFunction) getProperty(ctor, "reject");
return reject.call(Context.getCurrentContext(), this, ctor, new Object[] { e.getMessage() });
}
}
use of net.sourceforge.htmlunit.corejs.javascript.LambdaConstructor 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;
}
use of net.sourceforge.htmlunit.corejs.javascript.LambdaConstructor in project htmlunit by HtmlUnit.
the class FontFaceSet method load.
/**
* @param font a font specification using the CSS value syntax, e.g. "italic bold 16px Roboto"
* @param text limit the font faces to those whose Unicode range contains at least one
* of the characters in text. This does not check for individual glyph coverage.
* @return a Promise of an Array of FontFace loaded. The promise is fulfilled
* when all the fonts are loaded; it is rejected if one of the fonts failed to load.
*/
@JsxFunction
public Object load(final String font, final String text) {
final Scriptable scope = ScriptableObject.getTopLevelScope(this);
final LambdaConstructor ctor = (LambdaConstructor) getProperty(scope, "Promise");
final LambdaFunction resolve = (LambdaFunction) getProperty(ctor, "resolve");
return resolve.call(Context.getCurrentContext(), this, ctor, new Object[] { "" });
}
use of net.sourceforge.htmlunit.corejs.javascript.LambdaConstructor 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 net.sourceforge.htmlunit.corejs.javascript.LambdaConstructor in project htmlunit by HtmlUnit.
the class AudioContext method decodeAudioData.
/**
* The decodeAudioData() method of the BaseAudioContext Interface is used to asynchronously
* decode audio file data contained in an ArrayBuffer. In this case the ArrayBuffer is
* loaded from XMLHttpRequest and FileReader.
* The decoded AudioBuffer is resampled to the AudioContext's sampling rate,
* then passed to a callback or promise.
* @param buffer An ArrayBuffer containing the audio data to be decoded, usually grabbed
* from XMLHttpRequest, WindowOrWorkerGlobalScope.fetch() or FileReader
* @param success A callback function to be invoked when the decoding successfully finishes.
* The single argument to this callback is an AudioBuffer representing the decodedData
* (the decoded PCM audio data). Usually you'll want to put the decoded data into
* an AudioBufferSourceNode, from which it can be played and manipulated how you want.
* @param error An optional error callback, to be invoked if an error occurs
* when the audio data is being decoded.
* @return the promise or null
*/
@JsxFunction
public Object decodeAudioData(final NativeArrayBuffer buffer, final Function success, final Function error) {
final Window window = getWindow();
final HtmlPage owningPage = (HtmlPage) window.getDocument().getPage();
final JavaScriptEngine jsEngine = (JavaScriptEngine) window.getWebWindow().getWebClient().getJavaScriptEngine();
if (error != null) {
jsEngine.addPostponedAction(new PostponedAction(owningPage, "AudioContext.decodeAudioData") {
@Override
public void execute() throws Exception {
jsEngine.callFunction(owningPage, error, getParentScope(), AudioContext.this, new Object[] {});
}
});
return null;
}
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[] {});
}
Aggregations