From cd63c87f07ee344a7fa5ca62bcc42da9e81aadfb Mon Sep 17 00:00:00 2001 From: Muffin Date: Tue, 11 Feb 2025 00:49:36 -0600 Subject: [PATCH] js: reset variable types after compatibility layer call Fixes https://github.com/TurboWarp/scratch-vm/issues/245 --- src/compiler/jsgen.js | 2 ++ .../tw-compatibility-layer-type-barrier.sb3 | Bin 0 -> 2890 bytes ...ibility-layer-type-barrier.sb3.tw-snapshot | 34 ++++++++++++++++++ ...ibility-layer-type-barrier.sb3.tw-snapshot | 34 ++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 test/fixtures/execute/tw-compatibility-layer-type-barrier.sb3 create mode 100644 test/snapshot/__snapshots__/tw-compatibility-layer-type-barrier.sb3.tw-snapshot create mode 100644 test/snapshot/__snapshots__/warp-timer/tw-compatibility-layer-type-barrier.sb3.tw-snapshot diff --git a/src/compiler/jsgen.js b/src/compiler/jsgen.js index 914e5cc7..10387a79 100644 --- a/src/compiler/jsgen.js +++ b/src/compiler/jsgen.js @@ -1342,6 +1342,8 @@ class JSGenerator { const opcodeFunction = this.evaluateOnce(`runtime.getOpcodeFunction("${sanitize(opcode)}")`); result += `}, ${opcodeFunction}, ${this.isWarp}, ${setFlags}, "${sanitize(node.id)}", ${frameName})`; + this.yielded(); + return result; } diff --git a/test/fixtures/execute/tw-compatibility-layer-type-barrier.sb3 b/test/fixtures/execute/tw-compatibility-layer-type-barrier.sb3 new file mode 100644 index 0000000000000000000000000000000000000000..635f80d5d92fccbd4c860a95ad46d3021b0c81da GIT binary patch literal 2890 zcma);XHXN^9>oJBNa&K#q)JUdF@#V85_$r46T}C zE7eEXY((;!Q!orrT;xo4Oo*1p`8?WON-2C`O!3NT;9FLQ3jH}`odLS4gXYO1I(T=c z31q_eWbLMs%@Y?rB?96Kyu4Ws!E@KADbv8B!N*7@ftg-!8J~*^gfm1r2jSO0Q#HF9 z?0l3OyA)<80RA?N6U!4xyOVqJ%k~eO!hrfAsV5V~UU3Y*d2|L6;Sz%F$(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at zg-FU?iKvF^K^i1tk>Wf_IuY6~EFtK*v(qxod{%cV1G%tHxWC=SF#D~h{i;JD$j2IZ&Loehk)Lf8PrW}uAYA%tsEzoGM5h7sIAFX^z2zh0Z z29W}ZWZiv{{l~2`wWG1n5hEjKEoJMBvm|z^k_0qA_+9yD$&9__IlPRMRzRhIF%ciUVMb84Gd#CX)u6YjL zdc9bZ#AMDi1!3 zDYuH5)gKrun+N=zzzR+=1f&JAR{QI+3$RsD1z@KR#Zw^+NdG zb?vZALZ4E+TMF)%kAo!3T)6pR!+lHDzk3ufmKi(zwt4@7Kp}^*i8j&pRoYNy=be7c zwdt^0q{&mUFY5811LO|pmAHVzZL`5X1O1F)JbQgwp8#jY)?>LPwNXn` zsYqx10!RI=^AZ3X>d0h}i$LKPl{pElBWd#Q^P?}DjbR5y%H=*3P#$cT5_-U8k| zTJ|tZvnwRu|JBNWKokc0D0!kyUtd!7Oq)%>gR+vr+v)L1x{179`=O`tWHtULmjWJg zMW@QYw$`I^K|5zEc*617>hBehUT?FO&oVa$FWz$xwRMgHIm2gTdjjVm1ExCspH5#w z-a9UKNa*~&n~(r4p-va?jfd=R2I?HOB~BfIXL`2QlarTsNG#UoOw3Tg|L>K@K>6GG wd&~S)`74M1lCcB-9hH7{{1pO!Ies{H{5MFjHV3i(RIwc2_s2i(XHdX@0XjAoxc~qF literal 0 HcmV?d00001 diff --git a/test/snapshot/__snapshots__/tw-compatibility-layer-type-barrier.sb3.tw-snapshot b/test/snapshot/__snapshots__/tw-compatibility-layer-type-barrier.sb3.tw-snapshot new file mode 100644 index 00000000..1ffc985c --- /dev/null +++ b/test/snapshot/__snapshots__/tw-compatibility-layer-type-barrier.sb3.tw-snapshot @@ -0,0 +1,34 @@ +// TW Snapshot +// Input SHA-256: 7be6188a713254fa9b1f4ca207fbb6116aad958f321cd54f4f07f49a9f2c1a58 + +// 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 = stage.variables["`jEk@4|i[#Fk?(8x)AV.-my variable"]; +const b2 = runtime.getOpcodeFunction("looks_sayforsecs"); +return function* genXYZ () { +yield* executeInCompatibilityLayer({"MESSAGE":"plan 1",}, b0, false, false, "c", null); +b1.value = (0 + 0); +yield* executeInCompatibilityLayer({"MESSAGE":"Hello!","SECS":0.1,}, b2, false, false, "d", null); +if (((((+b1.value || 0) + 2) || 0) === 2)) { +yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "i", null); +} +yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "m", null); +retire(); return; +}; }) + +// Sprite1 script +(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage(); +const b0 = stage.variables["`jEk@4|i[#Fk?(8x)AV.-my variable"]; +return function* genXYZ () { +thread.timer = timer(); +var a0 = Math.max(0, 1000 * 0); +runtime.requestRedraw(); +yield; +while (thread.timer.timeElapsed() < a0) { +yield; +} +thread.timer = null; +b0.value = "string"; +retire(); return; +}; }) diff --git a/test/snapshot/__snapshots__/warp-timer/tw-compatibility-layer-type-barrier.sb3.tw-snapshot b/test/snapshot/__snapshots__/warp-timer/tw-compatibility-layer-type-barrier.sb3.tw-snapshot new file mode 100644 index 00000000..1ffc985c --- /dev/null +++ b/test/snapshot/__snapshots__/warp-timer/tw-compatibility-layer-type-barrier.sb3.tw-snapshot @@ -0,0 +1,34 @@ +// TW Snapshot +// Input SHA-256: 7be6188a713254fa9b1f4ca207fbb6116aad958f321cd54f4f07f49a9f2c1a58 + +// 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 = stage.variables["`jEk@4|i[#Fk?(8x)AV.-my variable"]; +const b2 = runtime.getOpcodeFunction("looks_sayforsecs"); +return function* genXYZ () { +yield* executeInCompatibilityLayer({"MESSAGE":"plan 1",}, b0, false, false, "c", null); +b1.value = (0 + 0); +yield* executeInCompatibilityLayer({"MESSAGE":"Hello!","SECS":0.1,}, b2, false, false, "d", null); +if (((((+b1.value || 0) + 2) || 0) === 2)) { +yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "i", null); +} +yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "m", null); +retire(); return; +}; }) + +// Sprite1 script +(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage(); +const b0 = stage.variables["`jEk@4|i[#Fk?(8x)AV.-my variable"]; +return function* genXYZ () { +thread.timer = timer(); +var a0 = Math.max(0, 1000 * 0); +runtime.requestRedraw(); +yield; +while (thread.timer.timeElapsed() < a0) { +yield; +} +thread.timer = null; +b0.value = "string"; +retire(); return; +}; })