From c8ed32b8d256058cedea100ffb899ae8b8dd8428 Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Thu, 8 Jul 2021 17:35:50 -0500 Subject: [PATCH] js+ir: check whether thread status after running addon block Fixes "breakpoint" block working unreliably --- src/compiler/irgen.js | 1 + src/compiler/jsexecute.js | 5 ++++- src/compiler/jsgen.js | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/compiler/irgen.js b/src/compiler/irgen.js index b5864de0..8614c20e 100644 --- a/src/compiler/irgen.js +++ b/src/compiler/irgen.js @@ -1120,6 +1120,7 @@ class ScriptTreeGenerator { const addonBlock = this.runtime.getAddonBlock(procedureCode); if (addonBlock) { + this.script.yields = true; const args = {}; for (let i = 0; i < paramIds.length; i++) { let value; diff --git a/src/compiler/jsexecute.js b/src/compiler/jsexecute.js index 6e2091c1..2d9005ef 100644 --- a/src/compiler/jsexecute.js +++ b/src/compiler/jsexecute.js @@ -203,7 +203,7 @@ const executeInCompatibilityLayer = function*(inputs, blockFunction, useFlags) { * @param {string} blockId The ID of the block being run * @param {object} args The arguments to pass to the block */ -const callAddonBlock = (procedureCode, blockId, args) => { +const callAddonBlock = function*(procedureCode, blockId, args) { const addonBlock = thread.target.runtime.getAddonBlock(procedureCode); if (addonBlock) { const target = thread.target; @@ -214,6 +214,9 @@ const callAddonBlock = (procedureCode, blockId, args) => { }, target }); + if (thread.status === Thread.STATUS_PROMISE_WAIT) { + yield; + } } }; diff --git a/src/compiler/jsgen.js b/src/compiler/jsgen.js index cbe82f95..d176b3eb 100644 --- a/src/compiler/jsgen.js +++ b/src/compiler/jsgen.js @@ -658,7 +658,8 @@ class JSGenerator { descendStackedBlock (node) { switch (node.kind) { case 'addons.call': - this.source += `callAddonBlock("${sanitize(node.code)}","${sanitize(node.blockId)}",{`; + this.source += `yield* callAddonBlock("${sanitize(node.code)}","${sanitize(node.blockId)}",{`; + this.yielded(); for (const argumentName of Object.keys(node.arguments)) { const argumentValue = node.arguments[argumentName]; this.source += `"${sanitize(argumentName)}":${this.descendInput(argumentValue).asSafe()},`;