Skip to content

Commit

Permalink
Expose compatibility layer stack frame on thread
Browse files Browse the repository at this point in the history
For #212
  • Loading branch information
GarboMuffin committed Jun 14, 2024
1 parent dff3c2f commit 30a614d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/compiler/compat-block-utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ const BlockUtility = require('../engine/block-utility');
class CompatibilityLayerBlockUtility extends BlockUtility {
constructor () {
super();
this._stackFrame = {};
this._startedBranch = null;
}

get stackFrame () {
return this._stackFrame;
return this.thread.compatibilityStackFrame;
}

startBranch (branchNumber, isLoop) {
Expand All @@ -33,9 +32,9 @@ class CompatibilityLayerBlockUtility extends BlockUtility {
init (thread, fakeBlockId, stackFrame) {
this.thread = thread;
this.sequencer = thread.target.runtime.sequencer;
this._stackFrame = stackFrame;
this._startedBranch = null;
thread.stack[0] = fakeBlockId;
thread.compatibilityStackFrame = stackFrame;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/engine/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class Thread {
*/
this.procedures = null;
this.executableHat = false;
this.compatibilityStackFrame = null;
}

/**
Expand Down
Binary file added test/fixtures/tw-glide.sb3
Binary file not shown.
15 changes: 15 additions & 0 deletions test/integration/tw_compat_block_utility_stackframe_exposed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const {test} = require('tap');
const fs = require('fs');
const path = require('path');
const VM = require('../../src/virtual-machine');
const Timer = require('../../src/util/timer');

test('compatibility stack frame is exposed on thread', t => {
const vm = new VM();
vm.loadProject(fs.readFileSync(path.join(__dirname, '../fixtures/tw-glide.sb3'))).then(() => {
vm.greenFlag();
vm.runtime._step();
t.ok(vm.runtime.threads[0].compatibilityStackFrame.timer instanceof Timer);
t.end();
});
});

0 comments on commit 30a614d

Please sign in to comment.