1
0
فهرست منبع

Better handling of JavaScript exceptions.

Their wrapper has saner message and it actually appears in stacktrace.
Herbert Vojčík 13 سال پیش
والد
کامیت
257e075b71
4فایلهای تغییر یافته به همراه21 افزوده شده و 12 حذف شده
  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:",
 selector: "exception:",
 fn: function (anException){
 fn: function (anException){
 var self=this;
 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)})}
 return self}, function($ctx1) {$ctx1.fill(self,"exception:",{anException:anException}, smalltalk.JavaScriptException)})}
 }),
 }),
 smalltalk.JavaScriptException);
 smalltalk.JavaScriptException);
@@ -161,7 +162,9 @@ smalltalk.method({
 selector: "messageText",
 selector: "messageText",
 fn: function (){
 fn: function (){
 var self=this;
 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)})}
 }, function($ctx1) {$ctx1.fill(self,"messageText",{}, smalltalk.JavaScriptException)})}
 }),
 }),
 smalltalk.JavaScriptException);
 smalltalk.JavaScriptException);

+ 9 - 6
js/Kernel-Exceptions.js

@@ -213,11 +213,12 @@ selector: "exception:",
 category: 'accessing',
 category: 'accessing',
 fn: function (anException){
 fn: function (anException){
 var self=this;
 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)})},
 return self}, function($ctx1) {$ctx1.fill(self,"exception:",{anException:anException}, smalltalk.JavaScriptException)})},
 args: ["anException"],
 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: []
 referencedClasses: []
 }),
 }),
 smalltalk.JavaScriptException);
 smalltalk.JavaScriptException);
@@ -229,11 +230,13 @@ selector: "messageText",
 category: 'accessing',
 category: 'accessing',
 fn: function (){
 fn: function (){
 var self=this;
 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)})},
 }, function($ctx1) {$ctx1.fill(self,"messageText",{}, smalltalk.JavaScriptException)})},
 args: [],
 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: []
 referencedClasses: []
 }),
 }),
 smalltalk.JavaScriptException);
 smalltalk.JavaScriptException);

+ 5 - 3
js/boot.js

@@ -529,14 +529,16 @@ function Smalltalk() {
 				if(error.smalltalkError) {
 				if(error.smalltalkError) {
 					handleError(error);
 					handleError(error);
                 } else {
                 } 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
 				// Reset the context stack in any case
 				st.thisContext = undefined;
 				st.thisContext = undefined;
                 // Throw the exception anyway, as we want to stop
                 // Throw the exception anyway, as we want to stop
                 // the execution to avoid infinite loops
                 // the execution to avoid infinite loops
-				throw(error);
+				throw error;
 			}
 			}
 		}
 		}
 	};
 	};

+ 2 - 1
st/Kernel-Exceptions.st

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