forked from scratchfoundation/scratch-vm
-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ir: Match vanilla quirks when handling variable or list fields with n…
…ull ID
- Loading branch information
1 parent
2c9d301
commit af3b751
Showing
5 changed files
with
112 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+2.65 KB
test/fixtures/execute/tw-automatic-variable-creation-literal-null-id.sb3
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const {test} = require('tap'); | ||
const VM = require('../../src/virtual-machine'); | ||
|
||
for (const compilerEnabled of [false, true]) { | ||
const prefix = compilerEnabled ? 'compiler' : 'interpreter'; | ||
test(`${prefix} - quirks when block field has literal null for variable ID`, t => { | ||
const vm = new VM(); | ||
vm.setCompilerOptions({ | ||
enabled: compilerEnabled | ||
}); | ||
t.equal(vm.runtime.compilerOptions.enabled, compilerEnabled, 'compiler options sanity check'); | ||
|
||
// The execute tests ensure that this fixture compiles and runs fine and the snapshot test ensures | ||
// it compiles correctly. This additional test will ensure that the internal variable objects are | ||
// being created with the expected properties. | ||
const fixturePath = path.join( | ||
__dirname, | ||
'../fixtures/execute/tw-automatic-variable-creation-literal-null-id.sb3' | ||
); | ||
|
||
vm.loadProject(fs.readFileSync(fixturePath)).then(() => { | ||
vm.greenFlag(); | ||
vm.runtime._step(); | ||
|
||
// Variable does not exist, should get made as local variable in sprite | ||
const variables = vm.runtime.targets[1].variables; | ||
t.equal(Object.keys(variables).length, 1, 'created 1 new variable'); | ||
|
||
// Scratch quirk - the entry in .variables should have key "null" | ||
const newVariableKey = Object.keys(variables)[0]; | ||
t.equal(newVariableKey, 'null', 'key is "null"'); | ||
|
||
// Scratch quirk - the actual variable.id should be the random string | ||
const newVariable = Object.values(variables)[0]; | ||
t.notEqual(newVariable.id, 'null', 'variable.id is not "null"'); | ||
t.type(newVariable.id, 'string', 'variable.id is a string'); | ||
|
||
t.end(); | ||
}); | ||
}); | ||
} |
13 changes: 13 additions & 0 deletions
13
test/snapshot/__snapshots__/tw-automatic-variable-creation-literal-null-id.sb3.tw-snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// TW Snapshot | ||
// Input SHA-256: 4764ae15e39b22b1a071c9ac79f8758f24ef41855802db8674e200fd26139ed0 | ||
|
||
// Sprite1 script | ||
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage(); | ||
const b0 = runtime.getOpcodeFunction("looks_say"); | ||
const b1 = target.variables["null"]; | ||
return function* genXYZ () { | ||
yield* executeInCompatibilityLayer({"MESSAGE":"plan 0",}, b0, false, false, "a", null); | ||
b1.value = 5; | ||
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "d", null); | ||
retire(); return; | ||
}; }) |
13 changes: 13 additions & 0 deletions
13
...t/__snapshots__/warp-timer/tw-automatic-variable-creation-literal-null-id.sb3.tw-snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// TW Snapshot | ||
// Input SHA-256: 4764ae15e39b22b1a071c9ac79f8758f24ef41855802db8674e200fd26139ed0 | ||
|
||
// Sprite1 script | ||
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage(); | ||
const b0 = runtime.getOpcodeFunction("looks_say"); | ||
const b1 = target.variables["null"]; | ||
return function* genXYZ () { | ||
yield* executeInCompatibilityLayer({"MESSAGE":"plan 0",}, b0, false, false, "a", null); | ||
b1.value = 5; | ||
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "d", null); | ||
retire(); return; | ||
}; }) |