@@ -207,11 +207,10 @@ 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));
|
||||
}
|
||||
JS_Parse_Error.prototype = Object.create(Error.prototype);
|
||||
JS_Parse_Error.prototype = Object.create(SyntaxError.prototype);
|
||||
JS_Parse_Error.prototype.constructor = JS_Parse_Error;
|
||||
JS_Parse_Error.prototype.name = "SyntaxError";
|
||||
configure_error_stack(JS_Parse_Error);
|
||||
|
||||
function js_error(message, filename, line, col, pos) {
|
||||
throw new JS_Parse_Error(message, filename, line, col, pos);
|
||||
|
||||
25
lib/utils.js
25
lib/utils.js
@@ -55,28 +55,33 @@ function find_if(func, array) {
|
||||
for (var i = array.length; --i >= 0;) if (func(array[i])) return array[i];
|
||||
}
|
||||
|
||||
function configure_error_stack(fn) {
|
||||
Object.defineProperty(fn.prototype, "stack", {
|
||||
function configure_error_stack(ex, cause) {
|
||||
var stack = ex.name + ": " + ex.message;
|
||||
Object.defineProperty(ex, "stack", {
|
||||
get: function() {
|
||||
var err = new Error(this.message);
|
||||
err.name = this.name;
|
||||
try {
|
||||
throw err;
|
||||
} catch (e) {
|
||||
return e.stack;
|
||||
if (cause) {
|
||||
cause.name = "" + ex.name;
|
||||
stack = "" + cause.stack;
|
||||
var msg = "" + cause.message;
|
||||
cause = null;
|
||||
var index = stack.indexOf(msg);
|
||||
if (index >= 0) index += msg.length;
|
||||
index = stack.indexOf("\n", index) + 1;
|
||||
stack = stack.slice(0, index) + stack.slice(stack.indexOf("\n", index) + 1);
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function DefaultsError(msg, defs) {
|
||||
this.message = msg;
|
||||
this.defs = defs;
|
||||
configure_error_stack(this, new Error(msg));
|
||||
}
|
||||
DefaultsError.prototype = Object.create(Error.prototype);
|
||||
DefaultsError.prototype.constructor = DefaultsError;
|
||||
DefaultsError.prototype.name = "DefaultsError";
|
||||
configure_error_stack(DefaultsError);
|
||||
|
||||
function defaults(args, defs, croak) {
|
||||
if (croak) for (var i in args) {
|
||||
|
||||
Reference in New Issue
Block a user