From 97dd22f314a4ea5ac77ce9c178550f1a198483bf Mon Sep 17 00:00:00 2001 From: jberg Date: Fri, 2 Aug 2019 06:58:57 -0700 Subject: [PATCH] Handle MAKI functions being case insensitive (#825) --- experiments/modern/src/debugger/Variable.js | 2 +- .../src/maki-interpreter/interpreter.test.js | 2 +- .../src/maki-interpreter/prettyPrinter.js | 2 +- .../src/maki-interpreter/virtualMachine.js | 4 +++- experiments/modern/src/runtime/Button.js | 4 ++-- experiments/modern/src/runtime/Container.js | 6 +++--- experiments/modern/src/runtime/Group.js | 8 ++++---- experiments/modern/src/runtime/GuiObject.js | 17 ++++++----------- experiments/modern/src/runtime/Layout.js | 6 +++--- experiments/modern/src/runtime/MakiObject.js | 6 +++--- experiments/modern/src/runtime/System.js | 16 ++++++++-------- .../src/runtime/WinampAbstractionLayer.js | 4 ++-- 12 files changed, 37 insertions(+), 40 deletions(-) diff --git a/experiments/modern/src/debugger/Variable.js b/experiments/modern/src/debugger/Variable.js index 4079ed49..a8317caa 100644 --- a/experiments/modern/src/debugger/Variable.js +++ b/experiments/modern/src/debugger/Variable.js @@ -12,7 +12,7 @@ export default function Variable({ variable }) { if (obj == null) { type = "Unknown object"; } else { - type = obj.getClassName(); + type = obj.getclassname(); } break; case "STRING": { diff --git a/experiments/modern/src/maki-interpreter/interpreter.test.js b/experiments/modern/src/maki-interpreter/interpreter.test.js index 9bfdc716..39fb3b2e 100644 --- a/experiments/modern/src/maki-interpreter/interpreter.test.js +++ b/experiments/modern/src/maki-interpreter/interpreter.test.js @@ -24,7 +24,7 @@ beforeEach(() => { mockMessageBox = jest.fn(); // The VM depends upon the arity of this function, so we can't use // `mockMessageBox` directly. - System.prototype.messageBox = function(a, b, c, d) { + System.prototype.messagebox = function(a, b, c, d) { mockMessageBox(...arguments); }; }); diff --git a/experiments/modern/src/maki-interpreter/prettyPrinter.js b/experiments/modern/src/maki-interpreter/prettyPrinter.js index eed9be38..82cad097 100644 --- a/experiments/modern/src/maki-interpreter/prettyPrinter.js +++ b/experiments/modern/src/maki-interpreter/prettyPrinter.js @@ -14,7 +14,7 @@ function printValue(value) { if (obj == null) { type = "Unknown object"; } else { - type = obj.getClassName(); + type = obj.getclassname(); } break; case "STRING": diff --git a/experiments/modern/src/maki-interpreter/virtualMachine.js b/experiments/modern/src/maki-interpreter/virtualMachine.js index 1ec632fd..2088acd7 100644 --- a/experiments/modern/src/maki-interpreter/virtualMachine.js +++ b/experiments/modern/src/maki-interpreter/virtualMachine.js @@ -132,9 +132,11 @@ function* interpret(start, program, stack = []) { case 24: case 112: { const methodOffset = command.arg; - const { name: methodName, typeOffset: classesOffset } = methods[ + let { name: methodName, typeOffset: classesOffset } = methods[ methodOffset ]; + methodName = methodName.toLowerCase(); + const klass = classes[classesOffset]; // This is a bit awkward. Because the variables are stored on the stack // before the object, we have to find the number of arguments without diff --git a/experiments/modern/src/runtime/Button.js b/experiments/modern/src/runtime/Button.js index 574b163b..a7a180f5 100644 --- a/experiments/modern/src/runtime/Button.js +++ b/experiments/modern/src/runtime/Button.js @@ -2,12 +2,12 @@ const GuiObject = require("./GuiObject"); class Button extends GuiObject { /** - * getClassName() + * getclassname() * * Returns the class name for the object. * @ret The class name. */ - static getClassName() { + static getclassname() { return "Button"; } } diff --git a/experiments/modern/src/runtime/Container.js b/experiments/modern/src/runtime/Container.js index 62f5d5e9..6acef794 100644 --- a/experiments/modern/src/runtime/Container.js +++ b/experiments/modern/src/runtime/Container.js @@ -3,15 +3,15 @@ const { findDescendantByTypeAndId } = require("../utils"); class Container extends GuiObject { /** - * getClassName() + * getclassname() * * Returns the class name for the object. * @ret The class name. */ - static getClassName() { + static getclassname() { return "Container"; } - getLayout(id) { + getlayout(id) { return findDescendantByTypeAndId(this, "layout", id); } } diff --git a/experiments/modern/src/runtime/Group.js b/experiments/modern/src/runtime/Group.js index 3c5c323b..8249a0bd 100644 --- a/experiments/modern/src/runtime/Group.js +++ b/experiments/modern/src/runtime/Group.js @@ -2,17 +2,17 @@ const GuiObject = require("./GuiObject"); class Group extends GuiObject { /** - * getClassName() + * getclassname() * * Returns the class name for the object. * @ret The class name. */ - static getClassName() { + static getclassname() { return "Group"; } - getObject(id) { + getobject(id) { // Not sure this is correct, but it is my understanding this is just an alias - return this.findObject(id); + return this.findobject(id); } } diff --git a/experiments/modern/src/runtime/GuiObject.js b/experiments/modern/src/runtime/GuiObject.js index 39c7ed95..4090e8c8 100644 --- a/experiments/modern/src/runtime/GuiObject.js +++ b/experiments/modern/src/runtime/GuiObject.js @@ -3,38 +3,33 @@ const { findDescendantByTypeAndId } = require("../utils"); class GuiObject extends MakiObject { /** - * getClassName() + * getclassname() * * Returns the class name for the object. * @ret The class name. */ - static getClassName() { + static getclassname() { return "GuiObject"; } - findObject(id) { + findobject(id) { return findDescendantByTypeAndId(this, null, id); } init(newRoot) { newRoot.js_addChild(this); return this; } - setXmlParam(param, value) { + setxmlparam(param, value) { this.xmlNode.attributes[param] = value; return value; } - // need to force all function names to lowercase in the interpreter - // bad hack for now - setXMLParam(param, value) { - return this.setXmlParam(param, value); - } - getXmlParam(param) { + getxmlparam(param) { const attributes = this.xmlNode.attributes; if (attributes !== undefined && attributes.hasOwnProperty(param)) { return attributes[param]; } return null; } - getParent() { + getparent() { return this.parent; } } diff --git a/experiments/modern/src/runtime/Layout.js b/experiments/modern/src/runtime/Layout.js index 79f93605..2e50ec9c 100644 --- a/experiments/modern/src/runtime/Layout.js +++ b/experiments/modern/src/runtime/Layout.js @@ -3,15 +3,15 @@ const { findParentNodeOfType } = require("../utils"); class Layout extends GuiObject { /** - * getClassName() + * getclassname() * * Returns the class name for the object. * @ret The class name. */ - static getClassName() { + static getclassname() { return "Layout"; } - getContainer() { + getcontainer() { return findParentNodeOfType(this, ["container"]);; } } diff --git a/experiments/modern/src/runtime/MakiObject.js b/experiments/modern/src/runtime/MakiObject.js index 7059694b..2734fe78 100644 --- a/experiments/modern/src/runtime/MakiObject.js +++ b/experiments/modern/src/runtime/MakiObject.js @@ -43,19 +43,19 @@ class MakiObject { } /** - * getClassName() + * getclassname() * * Returns the class name for the object. * @ret The class name. */ - static getClassName() { + static getclassname() { return "Object"; } /** * getId() */ - getId() { + getid() { throw new Error("getId not implemented"); } } diff --git a/experiments/modern/src/runtime/System.js b/experiments/modern/src/runtime/System.js index bb81c3b6..8246a1a4 100644 --- a/experiments/modern/src/runtime/System.js +++ b/experiments/modern/src/runtime/System.js @@ -14,12 +14,12 @@ class System extends MakiObject { } /** - * getClassName() + * getclassname() * * Returns the class name for the object. * @ret The class name. */ - static getClassName() { + static getclassname() { return "System"; } @@ -27,22 +27,22 @@ class System extends MakiObject { this.js_trigger("onScriptLoaded"); } - getScriptGroup() { + getscriptgroup() { return this.scriptGroup; } - getContainer(id) { + getcontainer(id) { return findDescendantByTypeAndId(this.root, "container", id); } - getRuntimeVersion() { + getruntimeversion() { return "5.666"; } - getToken(str, separator, tokennum) { + gettoken(str, separator, tokennum) { return "Some Token String"; } - getParam() { + getparam() { return "Some String"; } - messageBox(message, msgtitle, flag, notanymoreId) { + messagebox(message, msgtitle, flag, notanymoreId) { console.log({ message, msgtitle, flag, notanymoreId }); } } diff --git a/experiments/modern/src/runtime/WinampAbstractionLayer.js b/experiments/modern/src/runtime/WinampAbstractionLayer.js index 0ef5e3fd..8ac71c6e 100644 --- a/experiments/modern/src/runtime/WinampAbstractionLayer.js +++ b/experiments/modern/src/runtime/WinampAbstractionLayer.js @@ -3,12 +3,12 @@ const Group = require("./Group"); // Needs to behavve like a group to work with top level scripts that call `getScriptGroup` class WinampAbstractionLayer extends Group { /** - * getClassName() + * getclassname() * * Returns the class name for the object. * @ret The class name. */ - static getClassName() { + static getclassname() { return "WinampAbstractionLayer"; } }