setjmp method
Dart-specific adaptation of C's setjmp.
Since Dart does not support returning twice from a function, this adaptation
takes a closure. It executes body synchronously.
Returns 0 if body completes normally, or the integer value provided to
longjmp if a non-local jump occurred targeting the provided env.
Implementation
int setjmp(jmp_buf env, void Function() body) {
try {
body();
return 0;
} on LongJmpException catch (e) {
if (e.env == env) {
return e.val == 0 ? 1 : e.val;
}
rethrow; // It was meant for a different jmp_buf
}
}