diff --git a/experiments/modern/src/Emitter.js b/experiments/modern/src/Emitter.js index 3bbeedb2..c4cadcfa 100644 --- a/experiments/modern/src/Emitter.js +++ b/experiments/modern/src/Emitter.js @@ -17,12 +17,12 @@ class Emitter { }; } - async trigger(eventName, ...args) { - await Promise.all(this._globalHooks.map(cb => cb(eventName, args))); + trigger(eventName, ...args) { + this._globalHooks.map(cb => cb(eventName, args)); if (this._hooks[eventName] == null) { return; } - await Promise.all(this._hooks[eventName].map(cb => cb(...args))); + this._hooks[eventName].map(cb => cb(...args)); } listenToAll(cb) { diff --git a/experiments/modern/src/maki-interpreter/interpreter.js b/experiments/modern/src/maki-interpreter/interpreter.js index 5f98ad53..e7a39c1a 100644 --- a/experiments/modern/src/maki-interpreter/interpreter.js +++ b/experiments/modern/src/maki-interpreter/interpreter.js @@ -3,7 +3,7 @@ const { getClass, getFormattedId } = require("./objects"); const interpret = require("./virtualMachine"); const { printCommand } = require("./prettyPrinter"); -async function main({ runtime, data, system, log, logger }) { +function main({ runtime, data, system, log, logger }) { const program = parse(data); // Replace class hashes with actual JavaScript classes from the runtime @@ -29,10 +29,8 @@ async function main({ runtime, data, system, log, logger }) { // const logger = log ? printCommand : logger; // TODO: Handle disposing of this. // TODO: Handle passing in variables. - variable.hook(method.name, async () => { - // Remove this await when we can run the VM synchronously. - // See GitHub issue #814 - await interpret(commandOffset, program, [], { logger }); + variable.hook(method.name, () => { + interpret(commandOffset, program, [], { logger }); }); }); @@ -44,7 +42,7 @@ async function main({ runtime, data, system, log, logger }) { // Set the System global // TODO: We could confirm that this variable has the "system" flag set. program.variables[0].setValue(system); - await system.js_start(); + system.js_start(); } module.exports = main; diff --git a/experiments/modern/src/maki-interpreter/interpreter.test.js b/experiments/modern/src/maki-interpreter/interpreter.test.js index a43790a6..9bfdc716 100644 --- a/experiments/modern/src/maki-interpreter/interpreter.test.js +++ b/experiments/modern/src/maki-interpreter/interpreter.test.js @@ -5,13 +5,11 @@ const runtime = require("../runtime"); const interpret = require("./interpreter"); const { VERSIONS } = require("./testConstants"); -async function runFile(version, fileName) { +function runFile(version, fileName) { const relativePath = `../../resources/maki_compiler/${version}/${fileName}`; const system = new System(); const data = fs.readFileSync(path.join(__dirname, relativePath)); - // Remove this await when we can run the VM synchronously. - // See GitHub issue #814 - await interpret({ runtime, data, system, log: false }); + interpret({ runtime, data, system, log: false }); } // The basicTest.m file that jberg prepared follows a convention for what a @@ -40,10 +38,8 @@ describe("can call messageBox with hello World", () => { VERSIONS.WINAMP_5_66, ]; versions.forEach(version => { - test(`with bytecode compiled by ${version}`, async () => { - // Remove this await when we can run the VM synchronously. - // See GitHub issue #814 - await runFile(version, "hello_world.maki"); + test(`with bytecode compiled by ${version}`, () => { + runFile(version, "hello_world.maki"); expect(mockMessageBox).toHaveBeenCalledTimes(1); expect(mockMessageBox).toHaveBeenCalledWith( "Hello World", @@ -66,10 +62,8 @@ describe("can use basic operators", () => { ]; versions.forEach(version => { - test(`with basic test bytecode compiled by ${version}`, async () => { - // Remove this await when we can run the VM synchronously. - // See GitHub issue #814 - await runFile(version, "basicTests.maki"); + test(`with basic test bytecode compiled by ${version}`, () => { + runFile(version, "basicTests.maki"); expect(mockMessageBox.mock.calls).toEqual( [ "2 + 2 = 4", @@ -147,10 +141,8 @@ describe("can use simple functions", () => { ]; versions.forEach(version => { - test(`with bytecode compiled by ${version}`, async () => { - // Remove this await when we can run the VM synchronously. - // See GitHub issue #814 - await runFile(version, "simpleFunctions.maki"); + test(`with bytecode compiled by ${version}`, () => { + runFile(version, "simpleFunctions.maki"); expect(mockMessageBox.mock.calls).toEqual( [ "simple custom function", diff --git a/experiments/modern/src/maki-interpreter/variable.js b/experiments/modern/src/maki-interpreter/variable.js index 39f5bd84..e0a60162 100644 --- a/experiments/modern/src/maki-interpreter/variable.js +++ b/experiments/modern/src/maki-interpreter/variable.js @@ -17,13 +17,9 @@ class Variable { this._unsubscribeFromValue(); } if (this.typeName === "OBJECT") { - this._unsubscribeFromValue = value.js_listenToAll( - async (eventName, args) => { - // Remove this await when we can run the VM synchronously. - // See GitHub issue #814 - await this._emitter.trigger(eventName, args); - } - ); + this._unsubscribeFromValue = value.js_listenToAll((eventName, args) => { + this._emitter.trigger(eventName, args); + }); } this._value = value; } diff --git a/experiments/modern/src/maki-interpreter/virtualMachine.js b/experiments/modern/src/maki-interpreter/virtualMachine.js index b79f40ab..e0e2b354 100644 --- a/experiments/modern/src/maki-interpreter/virtualMachine.js +++ b/experiments/modern/src/maki-interpreter/virtualMachine.js @@ -10,7 +10,7 @@ function coerceTypes(var1, var2, val1, val2) { return val1; } -async function interpret(start, program, stack = [], { logger = null }) { +function interpret(start, program, stack = [], { logger = null }) { const { commands, methods, variables, classes } = program; function twoArgCoercingOperator(operator) { @@ -37,9 +37,7 @@ async function interpret(start, program, stack = [], { logger = null }) { const command = commands[i]; // Print some debug info if (logger) { - // Remove this await when we can run the VM synchronously. - // See GitHub issue #814 - await logger({ i, command, stack, variables, program }); + logger({ i, command, stack, variables, program }); } switch (command.opcode) { @@ -144,9 +142,7 @@ async function interpret(start, program, stack = [], { logger = null }) { // callGlobal case 25: { const offset = command.arg; - // Remove this await when we can run the VM synchronously. - // See GitHub issue #814 - const value = await interpret(offset, program, stack, { + const value = interpret(offset, program, stack, { logger, }); stack.push(value); diff --git a/experiments/modern/src/runtime/MakiObject.js b/experiments/modern/src/runtime/MakiObject.js index 9a89c477..41a34807 100644 --- a/experiments/modern/src/runtime/MakiObject.js +++ b/experiments/modern/src/runtime/MakiObject.js @@ -5,10 +5,8 @@ class MakiObject { this._emitter = new Emitter(); } - async js_trigger(eventName, ...args) { - // Remove this await when we can run the VM synchronously. - // See GitHub issue #814 - await this._emitter.trigger(eventName, args); + js_trigger(eventName, ...args) { + this._emitter.trigger(eventName, args); } js_listenToAll(cb) { diff --git a/experiments/modern/src/runtime/System.js b/experiments/modern/src/runtime/System.js index 5d551bfe..db24d8f5 100644 --- a/experiments/modern/src/runtime/System.js +++ b/experiments/modern/src/runtime/System.js @@ -12,10 +12,8 @@ class System extends MakiObject { return "System"; } - async js_start() { - // Remove this await when we can run the VM synchronously. - // See GitHub issue #814 - await this.js_trigger("onScriptLoaded"); + js_start() { + this.js_trigger("onScriptLoaded"); } getScriptGroup() {