From 3a4f62031829afc3fdc82dd00d4e39be17ca703d Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Thu, 22 Mar 2018 14:04:58 -0400 Subject: [PATCH] Check if loadProject input is any typed array using ArrayBuffer.isView. This allows us to pass a project's asset.data (from storage) directly instead of calling toString on it first. --- src/virtual-machine.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/virtual-machine.js b/src/virtual-machine.js index abc6b9b8d..0ce74559d 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -182,8 +182,13 @@ class VirtualMachine extends EventEmitter { * @return {!Promise} Promise that resolves after targets are installed. */ loadProject (input) { - if (typeof input === 'object' && !(input instanceof ArrayBuffer)) { + if (typeof input === 'object' && !ArrayBuffer.isView(input)) { + // If the input is an object and not any ArrayBuffer view + // (this includes all typed arrays and DataViews) + // turn the object into a JSON string, because we suspect + // this is a project.json as an object // validate expects a string or buffer as input + // TODO not sure if we need to check that it also isn't a data view input = JSON.stringify(input); }