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

@@ -21,6 +21,12 @@ class FlutterQjs {
/// Max stack size for quickjs.
final int? stackSize;
/// Max stack size for quickjs.
final int? timeout;
/// Max memory for quickjs.
final int? memoryLimit;
/// Message Port for event loop. Close it to stop dispatching event loop.
ReceivePort port = ReceivePort();
@@ -33,6 +39,8 @@ class FlutterQjs {
FlutterQjs({
this.moduleHandler,
this.stackSize,
this.timeout,
this.memoryLimit,
this.hostPromiseRejectionHandler,
});
@@ -104,9 +112,11 @@ class FlutterQjs {
}
return err;
}
}, port);
}, timeout ?? 0, port);
final stackSize = this.stackSize ?? 0;
if (stackSize > 0) jsSetMaxStackSize(rt, stackSize);
final memoryLimit = this.memoryLimit ?? 0;
if (memoryLimit > 0) jsSetMemoryLimit(rt, memoryLimit);
_rt = rt;
_ctx = jsNewContext(rt);
}