add timeout and memory limit

This commit is contained in:
ekibun
2022-05-20 00:40:44 +08:00
parent 232ea07e89
commit 32aac42c19
8 changed files with 426 additions and 316 deletions

View File

@@ -121,6 +121,36 @@ void main() async {
stderr.write(result.stderr);
expect(result.exitCode, 0);
});
test('infinite loop', () async {
final qjs = FlutterQjs(
timeout: 1000,
);
qjs.dispatch();
var result = await qjs.evaluate('1');
expect(result, 1, reason: 'eval module');
try {
await qjs.evaluate('while(true) {}');
throw 'Error not throw';
} on JSError catch (e) {
expect(e.message, startsWith('InternalError: interrupted'),
reason: 'throw interrupted');
}
await qjs.close();
});
test('memory leak', () async {
final qjs = FlutterQjs(
memoryLimit: 1000000,
);
qjs.dispatch();
try {
await qjs.evaluate('new Array(1000000).fill(0)');
throw 'Error not throw';
} on JSError catch (e) {
expect(e.message, startsWith('InternalError: out of memory'),
reason: 'throw interrupted');
}
await qjs.close();
});
test('module', () async {
final qjs = IsolateQjs(
moduleHandler: (name) async {