From 0d55e4c74f203149b932413cf6acb3211fdb8b38 Mon Sep 17 00:00:00 2001 From: kchadha Date: Wed, 14 Mar 2018 15:09:45 -0400 Subject: [PATCH] Modifying apis to accomodate existing tests. --- src/virtual-machine.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 903be5f7e..3e928c8c4 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -178,10 +178,15 @@ class VirtualMachine extends EventEmitter { /** * Load a Scratch project from a .sb, .sb2, .sb3 or json string. - * @param {Buffer} input A buffe or json string representing the project to load. + * @param {string | object} input A json string, object, or ArrayBuffer representing the project to load. * @return {!Promise} Promise that resolves after targets are installed. */ loadProject (input) { + if (typeof input === 'object' && !(input instanceof ArrayBuffer)) { + // validate expects a string or buffer as input + input = JSON.stringify(input); + } + // Clear the current runtime this.clear(); @@ -248,6 +253,17 @@ class VirtualMachine extends EventEmitter { return JSON.stringify(sb3.serialize(this.runtime)); } + // TODO do we still need this function? Keeping it here so as not to introduce + // a breaking change. + /** + * Load a project from a Scratch JSON representation. + * @param {string} json JSON string representing a project. + * @returns {Promise} Promise that resolves after the project has loaded + */ + fromJSON (json) { + return this.loadProject(json); + } + /** * Load a project from a Scratch JSON representation. * @param {string} projectJSON JSON string representing a project.