Browse Source

Don't quit the REPL on uncaught errors

Nicolas Petton 12 years ago
parent
commit
97401bf9a6
6 changed files with 541 additions and 5 deletions
  1. 11 0
      js/Kernel.deploy.js
  2. 16 0
      js/Kernel.js
  3. 3 3
      repl/REPL.js
  4. 5 2
      repl/REPL.st
  5. 502 0
      repl/amber.js
  6. 4 0
      st/Kernel.st

+ 11 - 0
js/Kernel.deploy.js

@@ -4708,6 +4708,17 @@ return self;}
 }),
 smalltalk.Error);
 
+smalltalk.addMethod(
+'_jsStack',
+smalltalk.method({
+selector: 'jsStack',
+fn: function (){
+var self=this;
+return self.stack;
+return self;}
+}),
+smalltalk.Error);
+
 
 smalltalk.addMethod(
 '_signal_',

+ 16 - 0
js/Kernel.js

@@ -6710,6 +6710,22 @@ referencedClasses: []
 }),
 smalltalk.Error);
 
+smalltalk.addMethod(
+unescape('_jsStack'),
+smalltalk.method({
+selector: unescape('jsStack'),
+category: 'accessing',
+fn: function (){
+var self=this;
+return self.stack;
+return self;},
+args: [],
+source: unescape('jsStack%0A%09%3Creturn%20self.stack%3E'),
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.Error);
+
 
 smalltalk.addMethod(
 unescape('_signal_'),

+ 3 - 3
repl/REPL.js

@@ -76,13 +76,13 @@ category: 'actions',
 fn: function (buffer){
 var self=this;
 var result=nil;
-((($receiver = smalltalk.send(buffer, "_isEmpty", [])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){result=smalltalk.send(smalltalk.send((smalltalk.Compiler || Compiler), "_new", []), "_loadExpression_", [buffer]);return smalltalk.send((smalltalk.Transcript || Transcript), "_show_", [result]);})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){result=smalltalk.send(smalltalk.send((smalltalk.Compiler || Compiler), "_new", []), "_loadExpression_", [buffer]);return smalltalk.send((smalltalk.Transcript || Transcript), "_show_", [result]);})]));
+((($receiver = smalltalk.send(buffer, "_isEmpty", [])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return smalltalk.send(self, "_try_catch_", [(function(){result=smalltalk.send(smalltalk.send((smalltalk.Compiler || Compiler), "_new", []), "_loadExpression_", [buffer]);return smalltalk.send((smalltalk.Transcript || Transcript), "_show_", [result]);}), (function(e){return smalltalk.send(smalltalk.send((typeof process == 'undefined' ? nil : process), "_stdout", []), "_write_", [smalltalk.send(e, "_jsStack", [])]);})]);})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return smalltalk.send(self, "_try_catch_", [(function(){result=smalltalk.send(smalltalk.send((smalltalk.Compiler || Compiler), "_new", []), "_loadExpression_", [buffer]);return smalltalk.send((smalltalk.Transcript || Transcript), "_show_", [result]);}), (function(e){return smalltalk.send(smalltalk.send((typeof process == 'undefined' ? nil : process), "_stdout", []), "_write_", [smalltalk.send(e, "_jsStack", [])]);})]);})]));
 smalltalk.send(self, "_setPrompt", []);
 smalltalk.send(self['@interface'], "_prompt", []);
 return self;},
 args: ["buffer"],
-source: unescape('eval%3A%20buffer%0A%09%7C%20result%20%7C%0A%09buffer%20isEmpty%20ifFalse%3A%20%5B%0A%09%09result%20%3A%3D%20Compiler%20new%20loadExpression%3A%20buffer.%0A%09%09Transcript%20show%3A%20result%5D.%0A%09self%20setPrompt.%0A%09interface%20prompt'),
-messageSends: ["ifFalse:", "isEmpty", "loadExpression:", "new", "show:", "setPrompt", "prompt"],
+source: unescape('eval%3A%20buffer%0A%09%7C%20result%20%7C%0A%09buffer%20isEmpty%20ifFalse%3A%20%5B%0A%09%09self%20try%3A%20%5B%0A%09%09%09result%20%3A%3D%20Compiler%20new%20loadExpression%3A%20buffer.%0A%09%09%09Transcript%20show%3A%20result%5D%0A%09%09catch%3A%20%5B%3Ae%20%7C%0A%09%09%09process%20stdout%20write%3A%20e%20jsStack%5D%5D.%0A%09self%20setPrompt.%0A%09interface%20prompt'),
+messageSends: ["ifFalse:", "isEmpty", "try:catch:", "loadExpression:", "new", "show:", "write:", "stdout", "jsStack", "setPrompt", "prompt"],
 referencedClasses: ["Compiler", "Transcript"]
 }),
 smalltalk.Repl);

+ 5 - 2
repl/REPL.st

@@ -30,8 +30,11 @@ close
 eval: buffer
 	| result |
 	buffer isEmpty ifFalse: [
-		result := Compiler new loadExpression: buffer.
-		Transcript show: result].
+		self try: [
+			result := Compiler new loadExpression: buffer.
+			Transcript show: result]
+		catch: [:e |
+			process stdout write: e jsStack]].
 	self setPrompt.
 	interface prompt
 ! !

File diff suppressed because it is too large
+ 502 - 0
repl/amber.js


+ 4 - 0
st/Kernel.st

@@ -2318,6 +2318,10 @@ messageText: aString
 
 context
 	<return self.context>
+!
+
+jsStack
+	<return self.stack>
 ! !
 
 !Error methodsFor: 'signaling'!

Some files were not shown because too many files changed in this diff