JSObject.makeDeferredPromise constructor

JSObject.makeDeferredPromise(
  1. JSContext context,
  2. JSResolve? resolve,
  3. JSReject? reject, {
  4. bool autoDispose = true,
})

Creates a JavaScript promise object by invoking the provided executor. resolve (JSObjectRef*) A pointer to a JSObjectRef in which to store the resolve function for the new promise. Pass NULL if you do not care to store the resolve callback. reject (JSObjectRef*) A pointer to a JSObjectRef in which to store the reject function for the new promise. Pass NULL if you do not care to store the reject callback. exception (JSValueRef*) A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.

Implementation

JSObject.makeDeferredPromise(
  this.context,
  JSResolve? resolve,
  JSReject? reject, {
  bool autoDispose = true,
}) {
  final JSException exception = JSException.create(context);
  _ref = JSObjectMakeDeferredPromise(
    context.ref,
    resolve?.ref ?? nullptr,
    resolve?.ref ?? nullptr,
    exception.ref,
  );
  if (exception.shouldThrow) throw exception.error;
  attach(calloc.nativeFree, _ref.cast(), autoDispose: autoDispose);
}