improve usability (#5753)

This commit is contained in:
Alex Lam S.L
2022-12-02 04:14:07 +02:00
committed by GitHub
parent 59e385591c
commit 650e63c8aa
3 changed files with 17 additions and 4 deletions

View File

@@ -207,7 +207,11 @@ function JS_Parse_Error(message, filename, line, col, pos) {
this.line = line;
this.col = col;
this.pos = pos;
configure_error_stack(this, new SyntaxError(message, filename, line, col));
try {
throw new SyntaxError(message, filename, line, col);
} catch (cause) {
configure_error_stack(this, cause);
}
}
JS_Parse_Error.prototype = Object.create(SyntaxError.prototype);
JS_Parse_Error.prototype.constructor = JS_Parse_Error;

View File

@@ -65,8 +65,12 @@ function configure_error_stack(ex, cause) {
var msg = "" + cause.message;
cause = null;
var index = stack.indexOf(msg);
if (index >= 0) index += msg.length;
index = stack.indexOf("\n", index) + 1;
if (index < 0) {
index = 0;
} else {
index += msg.length;
index = stack.indexOf("\n", index) + 1;
}
stack = stack.slice(0, index) + stack.slice(stack.indexOf("\n", index) + 1);
}
return stack;
@@ -77,7 +81,11 @@ function configure_error_stack(ex, cause) {
function DefaultsError(msg, defs) {
this.message = msg;
this.defs = defs;
configure_error_stack(this, new Error(msg));
try {
throw new Error(msg);
} catch (cause) {
configure_error_stack(this, cause);
}
}
DefaultsError.prototype = Object.create(Error.prototype);
DefaultsError.prototype.constructor = DefaultsError;