Prechádzať zdrojové kódy

error handling extracted, nicer code

also fixes mysterious errors when errors handling disappears
after first error in handleError; now finally gets to work in any case
Herbert Vojčík 10 rokov pred
rodič
commit
5f5ed88905
1 zmenil súbory, kde vykonal 17 pridanie a 14 odobranie
  1. 17 14
      support/boot.js

+ 17 - 14
support/boot.js

@@ -861,20 +861,9 @@ function RuntimeBrik(brikz, st) {
 			try {
 				return inContext(worker, setup);
 			} catch(error) {
-				if(error.smalltalkError) {
-					handleError(error);
-				} else {
-					var errorWrapper = st.JavaScriptException._on_(error);
-					try {errorWrapper._signal();} catch(ex) {}
-					errorWrapper._context_(st.getThisContext());
-					handleError(errorWrapper);
-				}
-				// 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
-				// Update: do not throw the exception. It's really annoying.
-				// throw error;
+				handleError(error);
+			} finally {
+				st.thisContext = null;
 			}
 		}
 	};
@@ -886,11 +875,25 @@ function RuntimeBrik(brikz, st) {
 		return result;
 	}
 
+	function wrappedError(error) {
+		var errorWrapper = st.JavaScriptException._on_(error);
+		try { errorWrapper._signal(); } catch (ex) {}
+		errorWrapper._context_(st.getThisContext());
+		return errorWrapper;
+	}
+
 	/* Handles Smalltalk errors. Triggers the registered ErrorHandler
 		(See the Smalltalk class ErrorHandler and its subclasses */
 
 	function handleError(error) {
+		if (!error.smalltalkError) {
+			error = wrappedError(error);
+		}
 		st.ErrorHandler._current()._handleError_(error);
+		// Throw the exception anyway, as we want to stop
+		// the execution to avoid infinite loops
+		// Update: do not throw the exception. It's really annoying.
+		// throw error;
 	}
 
 	/* Handle thisContext pseudo variable */