Browse Source

Better handling of JavaScript exceptions.

Their wrapper has saner message and it actually appears in stacktrace.
Herbert Vojčík 11 years ago
parent
commit
257e075b71
4 changed files with 21 additions and 12 deletions
  1. 5 2
      js/Kernel-Exceptions.deploy.js
  2. 9 6
      js/Kernel-Exceptions.js
  3. 5 3
      js/boot.js
  4. 2 1
      st/Kernel-Exceptions.st

+ 5 - 2
js/Kernel-Exceptions.deploy.js

@@ -150,7 +150,8 @@ smalltalk.method({
 selector: "exception:",
 fn: function (anException){
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
self["@exception"]=anException;
+return smalltalk.withContext(function($ctx1) { 
_st(anException)._messageText_(_st(anException)._basicAt_("message"));
+self["@exception"]=anException;
 return self}, function($ctx1) {$ctx1.fill(self,"exception:",{anException:anException}, smalltalk.JavaScriptException)})}
 }),
 smalltalk.JavaScriptException);
@@ -161,7 +162,9 @@ smalltalk.method({
 selector: "messageText",
 fn: function (){
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
return "A JavaScript exception occured while in the Smalltalk stack!";
+return smalltalk.withContext(function($ctx1) { 
var $1;
+$1=_st("JavaScript exception: ").__comma(_st(_st(self)._exception())._messageText());
+return $1;
 }, function($ctx1) {$ctx1.fill(self,"messageText",{}, smalltalk.JavaScriptException)})}
 }),
 smalltalk.JavaScriptException);

+ 9 - 6
js/Kernel-Exceptions.js

@@ -213,11 +213,12 @@ selector: "exception:",
 category: 'accessing',
 fn: function (anException){
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
self["@exception"]=anException;
+return smalltalk.withContext(function($ctx1) { 
_st(anException)._messageText_(_st(anException)._basicAt_("message"));
+self["@exception"]=anException;
 return self}, function($ctx1) {$ctx1.fill(self,"exception:",{anException:anException}, smalltalk.JavaScriptException)})},
 args: ["anException"],
-source: "exception: anException\x0a\x09exception := anException",
-messageSends: [],
+source: "exception: anException\x0a\x09anException messageText: (anException basicAt: 'message').\x0a\x09exception := anException",
+messageSends: ["messageText:", "basicAt:"],
 referencedClasses: []
 }),
 smalltalk.JavaScriptException);
@@ -229,11 +230,13 @@ selector: "messageText",
 category: 'accessing',
 fn: function (){
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
return "A JavaScript exception occured while in the Smalltalk stack!";
+return smalltalk.withContext(function($ctx1) { 
var $1;
+$1=_st("JavaScript exception: ").__comma(_st(_st(self)._exception())._messageText());
+return $1;
 }, function($ctx1) {$ctx1.fill(self,"messageText",{}, smalltalk.JavaScriptException)})},
 args: [],
-source: "messageText\x0a\x09^ 'A JavaScript exception occured while in the Smalltalk stack!'",
-messageSends: [],
+source: "messageText\x0a\x09^ 'JavaScript exception: ', self exception messageText",
+messageSends: [",", "messageText", "exception"],
 referencedClasses: []
 }),
 smalltalk.JavaScriptException);

+ 5 - 3
js/boot.js

@@ -529,14 +529,16 @@ function Smalltalk() {
 				if(error.smalltalkError) {
 					handleError(error);
                 } else {
-
-                    handleError(smalltalk.JavaScriptException._on_context_(error, smalltalk.thisContext));
+                    var wrapperError = st.JavaScriptException._on_(error);
+                    try {wrapperError._signal()} catch(ex) {}
+                    wrapperError._context_(st.getThisContext());
+                    handleError(wrapperError);
                 }
 				// Reset the context stack in any case
 				st.thisContext = undefined;
                 // Throw the exception anyway, as we want to stop
                 // the execution to avoid infinite loops
-				throw(error);
+				throw error;
 			}
 		}
 	};

+ 2 - 1
st/Kernel-Exceptions.st

@@ -83,11 +83,12 @@ exception
 !
 
 exception: anException
+	anException messageText: (anException basicAt: 'message').
 	exception := anException
 !
 
 messageText
-	^ 'A JavaScript exception occured while in the Smalltalk stack!!'
+	^ 'JavaScript exception: ', self exception messageText
 ! !
 
 !JavaScriptException class methodsFor: 'instance creation'!