making exceptions be of the right type so I can inject the continuation mark set

This commit is contained in:
Danny Yoo 2011-08-30 11:58:54 -04:00
parent bec99ec7b9
commit 579911f41f
2 changed files with 71 additions and 60 deletions

View File

@ -9,23 +9,26 @@
// Error type exports
var InternalError = function(val, contMarks) {
this.val = val;
this.contMarks = contMarks || false;
var RacketError = function(message, racketError) {
Error.call(this, message);
this.message = message;
this.racketError = racketError;
};
RacketError.prototype = baselib.heir(Error.prototype);
var isRacketError = baselib.makeClassPredicate(RacketError);
var SchemeError = function(val) {
this.val = val;
};
// // Error type exports
// var InternalError = function(val, contMarks) {
// this.val = val;
// this.contMarks = contMarks || false;
// };
var IncompleteExn = function(constructor, msg, otherArgs) {
this.constructor = constructor;
this.msg = msg;
this.otherArgs = otherArgs;
};
// var IncompleteExn = function(constructor, msg, otherArgs) {
// this.constructor = constructor;
// this.msg = msg;
// this.otherArgs = otherArgs;
// };
// (define-struct exn (message continuation-mark-set))
@ -47,6 +50,7 @@
var ExnFailContractArity = baselib.structs.makeStructureType(
'exn:fail:contract:arity', ExnFailContract, 0, 0, false, false);
// exn:fail:contract (id)
var ExnFailContractVariable = baselib.structs.makeStructureType(
'exn:fail:contract:variable', ExnFailContract, 1, 0, false, false);
@ -71,8 +75,8 @@
// value to allow integration with systems that don't recognize Racket error
// structures.
var raise = function(MACHINE, e) {
if (Exn.predicate(e)) {
e.message = Exn.accessor(e, 0);
if (isRacketError(e) && Exn.predicate(e.racketError)) {
e.message = Exn.accessor(e.racketError, 0);
}
if (typeof(window.console) !== 'undefined' &&
@ -88,11 +92,13 @@
var raiseUnboundToplevelError = function(MACHINE, name) {
var message = baselib.format.format("Not bound: ~a", [name]);
raise(MACHINE,
new Error(
baselib.format.format(
"Not bound: ~a",
[name])));
new RacketError(
message,
ExnFailContractVariable.constructor(message,
undefined,
baselib.symbols.makeSymbol(name))));
};
@ -101,70 +107,74 @@
expectedTypeName,
argumentOffset,
actualValue) {
var message;
if (argumentOffset !== undefined) {
raise(MACHINE,
new Error(
baselib.format.format(
message = baselib.format.format(
"~a: expected ~a as argument ~e but received ~e",
[callerName,
expectedTypeName,
(argumentOffset + 1),
actualValue])));
actualValue]);
raise(MACHINE, new RacketError(message,
ExnFailContract.constructor(message, undefined)));
} else {
raise(MACHINE,
new Error(
baselib.format.format(
message = baselib.format.format(
"~a: expected ~a but received ~e",
[callerName,
expectedTypeName,
actualValue])));
actualValue]);
raise(MACHINE, new RacketError(message,
ExnFailContract.constructor(message, undefined)));
}
};
var raiseContextExpectedValuesError = function(MACHINE, expected) {
var message = baselib.format.format("expected ~e values, received ~e values",
[expected, MACHINE.argcount]);
raise(MACHINE,
new Error(baselib.format.format(
"expected ~e values, received ~e values",
[expected, MACHINE.argcount])));
new RacketError(message,
ExnFailContract.constructor(message, undefined)));
};
var raiseArityMismatchError = function(MACHINE, proc, expected, received) {
var message = baselib.format.format("~a: expected ~e value(s), received ~e value(s)",
[proc.displayName,
expected,
received]);
raise(MACHINE,
new Error(baselib.format.format(
"~a: expected ~e value(s), received ~e value(s)",
[proc.displayName,
expected,
received])));
new RacketError(message,
ExnFailContractArity.constructor(message, undefined)));
};
var raiseOperatorApplicationError = function(MACHINE, operator) {
var message = baselib.format.format("not a procedure: ~e",
[operator]);
raise(MACHINE,
new Error(
baselib.format.format(
"not a procedure: ~e",
[operator])));
new RacketError(message,
ExnFailContract.constructor(message, undefined)));
};
var raiseOperatorIsNotClosure = function(MACHINE, operator) {
var message = baselib.format.format("not a closure: ~e",
[operator]);
raise(MACHINE,
new Error(
baselib.format.format(
"not a closure: ~e",
[operator])));
new RacketError(message,
ExnFailContract.constructor(message, undefined)));
};
var raiseOperatorIsNotPrimitiveProcedure = function(MACHINE, operator) {
var message = baselib.format.format("not a primitive procedure: ~e",
[operator]);
raise(MACHINE,
new Error(
baselib.format.format(
"not a primitive procedure: ~e",
[operator])));
new RacketError(message,
ExnFailContract.constructor(message, undefined)));
};
var raiseUnimplementedPrimitiveError = function(MACHINE, name) {
raise(MACHINE,
new Error("unimplemented kernel procedure: " + name));
var message = "unimplemented kernel procedure: " + name;
raise(MACHINE, new RacketError(message,
ExnFailContract.constructor(message, undefined)));
};
@ -178,19 +188,19 @@
//////////////////////////////////////////////////////////////////////
// Exports
exceptions.InternalError = InternalError;
exceptions.internalError = function(v, contMarks) { return new InternalError(v, contMarks); };
exceptions.isInternalError = function(x) { return x instanceof InternalError; };
exceptions.SchemeError = SchemeError;
exceptions.schemeError = function(v) { return new SchemeError(v); };
exceptions.isSchemeError = function(v) { return v instanceof SchemeError; };
exceptions.RacketError = RacketError;
exceptions.isRacketError = isRacketError;
exceptions.IncompleteExn = IncompleteExn;
exceptions.makeIncompleteExn = function(constructor, msg, args) { return new IncompleteExn(constructor, msg, args); };
exceptions.isIncompleteExn = function(x) { return x instanceof IncompleteExn; };
// exceptions.InternalError = InternalError;
// exceptions.internalError = function(v, contMarks) { return new InternalError(v, contMarks); };
// exceptions.isInternalError = function(x) { return x instanceof InternalError; };
// exceptions.IncompleteExn = IncompleteExn;
// exceptions.makeIncompleteExn = function(constructor, msg, args) { return new IncompleteExn(constructor, msg, args); };
// exceptions.isIncompleteExn = function(x) { return x instanceof IncompleteExn; };
exceptions.Exn = Exn;

View File

@ -478,9 +478,10 @@
// General error condition: just exit out
// of the trampoline and call the current error handler.
MACHINE.running = false;
if (baselib.exceptions.isExn(e)) {
if (baselib.exceptions.isRacketError(e) &&
baselib.exceptions.isExn(e.racketError)) {
contMarks = MACHINE.captureContinuationMarks();
baselib.exceptions.exnSetContMarks(e, contMarks);
baselib.exceptions.exnSetContMarks(e.racketError, contMarks);
}
MACHINE.params.currentErrorHandler(MACHINE, e);
return;