-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexception-handler.ts
More file actions
23 lines (21 loc) · 864 Bytes
/
Copy pathexception-handler.ts
File metadata and controls
23 lines (21 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { VM } from './vm.js';
import { Environment } from './environment.js';
export class ExceptionHandler {
constructor(private vm: VM) {}
public handleException(exception: any, targetFrameCount: number): boolean {
while (this.vm.fp >= targetFrameCount) {
const currentFrame = this.vm.frames[this.vm.fp];
if (currentFrame.catchHandlers.length > 0) {
const handler = currentFrame.catchHandlers.pop()!;
this.vm.sp = handler.stackDepth;
currentFrame.ip = handler.catchIp;
this.vm.stack[this.vm.sp++] = exception;
return true;
}
if (currentFrame.env.isCaptured) currentFrame.env = new Environment(null);
this.vm.sp = currentFrame.basePointer;
this.vm.fp--;
}
return false;
}
}