Modifying apis to accomodate existing tests.

This commit is contained in:
kchadha 2018-03-14 15:09:45 -04:00
parent 22be2b15f3
commit 0d55e4c74f

View file

@ -178,10 +178,15 @@ class VirtualMachine extends EventEmitter {
/** /**
* Load a Scratch project from a .sb, .sb2, .sb3 or json string. * 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. * @return {!Promise} Promise that resolves after targets are installed.
*/ */
loadProject (input) { 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 // Clear the current runtime
this.clear(); this.clear();
@ -248,6 +253,17 @@ class VirtualMachine extends EventEmitter {
return JSON.stringify(sb3.serialize(this.runtime)); 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. * Load a project from a Scratch JSON representation.
* @param {string} projectJSON JSON string representing a project. * @param {string} projectJSON JSON string representing a project.