toJS property
A JSPromise that either resolves with the result of the completed
Future or rejects with its error if it is a JS value and otherwise
rejects with a JS Error that wraps its Dart error value.
The rejected object contains the original error as a JSBoxedDartObject
in the property error and the original stack trace as a String in the
property stack.
Implementation
JSPromise<T> get toJS {
return JSPromise<T>(
(JSFunction resolve, JSFunction reject) {
this.then(
(JSAny? value) {
resolve.callAsFunction(resolve, value);
return value;
},
onError: (Object error, StackTrace stackTrace) {
final jsError = _convertError(error, stackTrace);
reject.callAsFunction(reject, jsError);
return jsError;
},
);
}.toJS,
);
}