Skip to content

Commit

Permalink
Merge pull request #1172 from glimmerjs/remove-try-catch-in-updating-vm
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue authored Oct 13, 2020
2 parents 2a5457a + 3269ca3 commit c00d700
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 30 deletions.
49 changes: 32 additions & 17 deletions packages/@glimmer/runtime/lib/vm/append.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,35 @@ export default class VM implements PublicVM, InternalVM {
/// EXECUTION

execute(initialize?: (vm: this) => void): RenderResult {
if (DEBUG) {
let hasErrored = true;
try {
let value = this._execute(initialize);

// using a boolean here to avoid breaking ergonomics of "pause on uncaught exceptions"
// which would happen with a `catch` + `throw`
hasErrored = false;

return value;
} finally {
if (hasErrored) {
// If any existing blocks are open, due to an error or something like
// that, we need to close them all and clean things up properly.
let elements = this.elements();

while (elements.hasBlocks) {
elements.popBlock();
}

resetTracking();
}
}
} else {
return this._execute(initialize);
}
}

private _execute(initialize?: (vm: this) => void): RenderResult {
if (LOCAL_SHOULD_LOG) {
console.log(`EXECUTING FROM ${this[INNER_VM].fetchRegister($pc)}`);
}
Expand All @@ -556,23 +585,9 @@ export default class VM implements PublicVM, InternalVM {

let result: RichIteratorResult<null, RenderResult>;

try {
while (true) {
result = this.next();
if (result.done) break;
}
} catch (e) {
// If any existing blocks are open, due to an error or something like
// that, we need to close them all and clean things up properly.
let elements = this.elements();

while (elements.hasBlocks) {
elements.popBlock();
}

resetTracking();

throw e;
while (true) {
result = this.next();
if (result.done) break;
}

return result.value;
Expand Down
40 changes: 27 additions & 13 deletions packages/@glimmer/runtime/lib/vm/update.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEBUG } from '@glimmer/env';
import {
Bounds,
DynamicScope,
Expand Down Expand Up @@ -41,27 +42,40 @@ export default class UpdatingVM {
}

execute(opcodes: UpdatingOpcode[], handler: ExceptionHandler) {
if (DEBUG) {
let hasErrored = true;
try {
this._execute(opcodes, handler);

// using a boolean here to avoid breaking ergonomics of "pause on uncaught exceptions"
// which would happen with a `catch` + `throw`
hasErrored = false;
} finally {
if (hasErrored) {
resetTracking();
}
}
} else {
this._execute(opcodes, handler);
}
}

private _execute(opcodes: UpdatingOpcode[], handler: ExceptionHandler) {
let { frameStack } = this;

this.try(opcodes, handler);

try {
while (true) {
if (frameStack.isEmpty()) break;

let opcode = this.frame.nextStatement();
while (true) {
if (frameStack.isEmpty()) break;

if (opcode === undefined) {
frameStack.pop();
continue;
}
let opcode = this.frame.nextStatement();

opcode.evaluate(this);
if (opcode === undefined) {
frameStack.pop();
continue;
}
} catch (e) {
resetTracking();

throw e;
opcode.evaluate(this);
}
}

Expand Down

0 comments on commit c00d700

Please sign in to comment.