Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for javascript error location #217

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions static/js/languages/javascript/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -54,7 +54,25 @@ 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)
w.onerror = (e)=>{
this.microvm.context.location = {
token: {
line: e.lineno,
column: e.colno
}
};
reject(e.message);
}
})
}else{
throw err.message
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions static/js/runtime/microvm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions static/js/runtime/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down