From d018bba8e03e863fc1fdee312fd0059e639f86f7 Mon Sep 17 00:00:00 2001 From: desean Date: Sun, 18 Feb 2024 10:47:18 -0500 Subject: [PATCH 1/2] Fix for javascript error location --- static/js/languages/javascript/runner.js | 25 ++++++++++++++++++++++-- static/js/runtime/microvm.js | 4 ++-- static/js/runtime/runtime.js | 4 ++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/static/js/languages/javascript/runner.js b/static/js/languages/javascript/runner.js index 7c2cdfba..1aad8fff 100644 --- a/static/js/languages/javascript/runner.js +++ b/static/js/languages/javascript/runner.js @@ -34,7 +34,7 @@ this.Runner = class Runner { return window.eval(program); } catch (error) { err = error; - if (err.stack != null) { + if (err.stack != null) { line = err.stack.split(".js:"); file = line[0]; line = line[1]; @@ -54,7 +54,28 @@ this.Runner = class Runner { }; } } - throw err.message; + //If the file is this file that isn't the true line number for this error + if(file.match(/javascript\/runner/) ){ + return new Promise((resolve,reject)=>{ + let blob = new Blob([program]) + let url = URL.createObjectURL(blob) + + let w = new Worker(url) + let waiting = true + w.onerror = (e)=>{ + this.microvm.context.location = { + token: { + line: e.lineno, + column: e.colno + } + }; + waiting = false + reject(e.message); + } + }) + }else{ + throw err.message + } } } diff --git a/static/js/runtime/microvm.js b/static/js/runtime/microvm.js index 7c38e981..4e200c9e 100644 --- a/static/js/runtime/microvm.js +++ b/static/js/runtime/microvm.js @@ -211,14 +211,14 @@ this.MicroVM = class MicroVM { return this.context.global[key] = value; } - run(program, timeout = 3000, filename = "", callback) { + async run(program, timeout = 3000, filename = "", callback) { var err, res; this.program = program; this.error_info = null; this.context.timeout = Date.now() + timeout; this.context.stack_size = 0; try { - res = this.runner.run(this.program, filename, callback); + res = await this.runner.run(this.program, filename, callback); this.storage_service.check(); if (res != null) { return this.runner.toString(res); diff --git a/static/js/runtime/runtime.js b/static/js/runtime/runtime.js index 6fb71b34..b5f39e31 100644 --- a/static/js/runtime/runtime.js +++ b/static/js/runtime/runtime.js @@ -37,7 +37,7 @@ this.Runtime = class Runtime { return this.connections.push(connection); } - updateSource(file, src, reinit = false) { + async updateSource(file, src, reinit = false) { var err, init; if (this.vm == null) { return false; @@ -49,7 +49,7 @@ this.Runtime = class Runtime { this.audio.cancelBeeps(); this.screen.clear(); try { - this.vm.run(src, 3000, file); + await this.vm.run(src, 3000, file); this.listener.postMessage({ name: "compile_success", file: file From a34b78a10bbd659df641d3cb03e68be632927115 Mon Sep 17 00:00:00 2001 From: desean Date: Sun, 18 Feb 2024 11:05:10 -0500 Subject: [PATCH 2/2] . --- static/js/languages/javascript/runner.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/static/js/languages/javascript/runner.js b/static/js/languages/javascript/runner.js index 1aad8fff..21fcd998 100644 --- a/static/js/languages/javascript/runner.js +++ b/static/js/languages/javascript/runner.js @@ -59,9 +59,7 @@ this.Runner = class Runner { return new Promise((resolve,reject)=>{ let blob = new Blob([program]) let url = URL.createObjectURL(blob) - let w = new Worker(url) - let waiting = true w.onerror = (e)=>{ this.microvm.context.location = { token: { @@ -69,7 +67,6 @@ this.Runner = class Runner { column: e.colno } }; - waiting = false reject(e.message); } })