Package org.htmlunit.corejs.javascript
Class UnhandledRejectionTracker
- java.lang.Object
-
- org.htmlunit.corejs.javascript.UnhandledRejectionTracker
-
public class UnhandledRejectionTracker extends java.lang.Object
This class is responsible for handling tracking of unhandled Promise rejections. These come up when a Promise is either rejected or an exception is thrown and there is no "catch" handler set up. There is one of these tracker objects for each Context class.Different frameworks will choose different ways to handle unhandled rejections. As a result, Rhino does nothing by default.
However, if "trackUnhandledPromiseRejections" is called on the Context object, then Rhino will track them in this object. It is the responsibility of the product embedding Rhino to periodically check for unhandled rejections in this class and either remove them or terminate the script and allow the context and its tracker to be garbage- collected.
Note that if "trackUnhandledPromiseRejections" is set, and rejections are not handled, then Promise objects will accumulate in this object and cause a memory leak.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
enabled
private static java.util.IdentityHashMap<NativePromise,NativePromise>
unhandled
-
Constructor Summary
Constructors Constructor Description UnhandledRejectionTracker()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
enable(boolean enabled)
java.util.List<java.lang.Object>
enumerate()
Return a collection of all of the results of any unhandled rejected promises.void
process(java.util.function.Consumer<java.lang.Object> handler)
Iterate through all the rejected promises that have not yet been handled.(package private) void
promiseHandled(NativePromise p)
(package private) void
promiseRejected(NativePromise p)
-
-
-
Field Detail
-
enabled
private boolean enabled
-
unhandled
private static final java.util.IdentityHashMap<NativePromise,NativePromise> unhandled
-
-
Method Detail
-
process
public void process(java.util.function.Consumer<java.lang.Object> handler)
Iterate through all the rejected promises that have not yet been handled. As each promise is handled by this method, it is removed from this tracker and will not appear again. This is useful for delivering unhandled promise notifications to users one time via a callback.
-
enumerate
public java.util.List<java.lang.Object> enumerate()
Return a collection of all of the results of any unhandled rejected promises. This does not remove unhandled promises from the collection, but reports the current state. It is useful for command-line tools.- Returns:
- a read-only collection of promise results. To clear them, call "process".
-
enable
void enable(boolean enabled)
-
promiseRejected
void promiseRejected(NativePromise p)
-
promiseHandled
void promiseHandled(NativePromise p)
-
-