host promise rejection

This commit is contained in:
ekibun
2021-01-23 01:19:56 +08:00
parent c7da8abb67
commit 1589f87194
6 changed files with 107 additions and 27 deletions

View File

@@ -100,6 +100,7 @@ void main() async {
moduleHandler: (name) {
return "export default '${new DateTime.now()}'";
},
hostPromiseRejectionHandler: (_) {},
);
qjs.dispatch();
await testEvaluate(qjs);
@@ -112,6 +113,7 @@ void main() async {
moduleHandler: (name) async {
return "export default '${new DateTime.now()}'";
},
hostPromiseRejectionHandler: (_) {},
);
await testEvaluate(qjs);
qjs.close();
@@ -141,4 +143,22 @@ void main() async {
}
qjs.close();
});
test('host promise rejection', () async {
final completer = Completer();
final qjs = FlutterQjs(
hostPromiseRejectionHandler: (reason) {
completer.complete(reason);
},
);
qjs.dispatch();
qjs.evaluate(
"(() => { Promise.resolve().then(() => { throw 'unhandle' }) })()",
name: "<eval>");
Future.delayed(Duration(seconds: 10)).then((value) {
if (!completer.isCompleted) completer.completeError("not host reject");
});
expect(await completer.future, "unhandle",
reason: "host promise rejection");
qjs.close();
});
}