Skip to content

Commit

Permalink
Don't rely on callerScope to yield
Browse files Browse the repository at this point in the history
  • Loading branch information
mmun committed Sep 11, 2017
1 parent c7f052f commit c18b621
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions packages/@glimmer/runtime/lib/compiled/opcodes/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ APPEND_OPCODES.add(Op.InvokeYield, vm => {
let { stack } = vm;

let handle = check(stack.pop(), CheckOption(CheckHandle));
let _scope = check(stack.pop(), CheckOption(CheckScope)) as Option<Scope>; // FIXME(mmun): shouldn't need to cast this
let scope = check(stack.pop(), CheckOption(CheckScope)) as Option<Scope>; // FIXME(mmun): shouldn't need to cast this
let table = check(stack.pop(), CheckOption(CheckBlockSymbolTable));

assert(table === null || (table && typeof table === 'object' && Array.isArray(table.parameters)), stackAssert('Option<BlockSymbolTable>', table));
Expand All @@ -154,32 +154,30 @@ APPEND_OPCODES.add(Op.InvokeYield, vm => {

// To balance the pop{Frame,Scope}
vm.pushFrame();
let blockScope = vm.scope().getCallerScope()!;
vm.pushScope(blockScope);

vm.pushScope(scope!); // Could be null but it doesnt matter as it is immediatelly popped.
return;
}

let locals = table.parameters;
let localsCount = locals.length;
let invokingScope = scope!;

// If necessary, create a child scope
{
let blockScope = vm.scope().getCallerScope()!;
if (localsCount > 0) {
blockScope = blockScope.child();
}
vm.pushScope(blockScope);
}
let locals = table.parameters;
let localsCount = locals.length;

let scope = vm.scope();
if (localsCount > 0) {
invokingScope = invokingScope.child();

for (let i=0; i<localsCount; i++) {
scope.bindSymbol(locals![i], args.at(i));
for (let i=0; i<localsCount; i++) {
invokingScope.bindSymbol(locals![i], args.at(i));
}
}
}

args.clear();

vm.pushFrame();
vm.pushScope(invokingScope);
vm.call(handle!);
});

Expand Down

0 comments on commit c18b621

Please sign in to comment.