Skip to content

Commit

Permalink
Merge branch 'TurboWarp:develop' into blockShape
Browse files Browse the repository at this point in the history
  • Loading branch information
AshimeeAlt authored Jul 30, 2024
2 parents 7d550e7 + 658ef8a commit 2cc7c5c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 7 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
10 changes: 6 additions & 4 deletions src/io/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const KEY_NAME = {
};

/**
* An array of the names of scratch keys.
* @type {Array<string>}
* A set of the names of Scratch keys.
* @type {Set<string>}
*/
const KEY_NAME_LIST = Object.keys(KEY_NAME).map(name => KEY_NAME[name]);
const KEY_NAME_SET = new Set(Object.values(KEY_NAME));

class Keyboard {
constructor (runtime) {
Expand Down Expand Up @@ -121,7 +121,9 @@ class Keyboard {
keyArg = Cast.toString(keyArg);

// If the arg matches a special key name, return it.
if (KEY_NAME_LIST.includes(keyArg)) {
// No special keys have a name that is only 1 character long, so we can avoid the lookup
// entirely in the most common case.
if (keyArg.length > 1 && KEY_NAME_SET.has(keyArg)) {
return keyArg;
}

Expand Down
9 changes: 9 additions & 0 deletions src/virtual-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,15 @@ class VirtualMachine extends EventEmitter {
zip.file('project.json', projectJson);
this._addFileDescsToZip(this.serializeAssets(), zip);

// Use a fixed modification date for the files in the zip instead of letting JSZip use the
// current time to avoid a very small metadata leak and make zipping deterministic. The magic
// number is from the first TurboWarp/scratch-vm commit after forking
// (4a93dab4fa3704ab7a1374b9794026b3330f3433).
const date = new Date(1591657163000);
for (const file of Object.values(zip.files)) {
file.date = date;
}

return zip;
}

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();
});
});
14 changes: 14 additions & 0 deletions test/integration/tw_deterministic_sb3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const {test} = require('tap');
const VM = require('../../src/virtual-machine');

test('saveProjectSb3 is deterministic over time', t => {
const vm = new VM();
Promise.all([
vm.saveProjectSb3('nodebuffer'),
// Zip modification time is only accurate to the second
new Promise(resolve => setTimeout(resolve, 1000)).then(() => vm.saveProjectSb3('nodebuffer'))
]).then(([a, b]) => {
t.same(a, b);
t.end();
});
});

0 comments on commit 2cc7c5c

Please sign in to comment.