Title: [113553] trunk/Source/_javascript_Core
Revision
113553
Author
[email protected]
Date
2012-04-08 13:50:50 -0700 (Sun, 08 Apr 2012)

Log Message

Command-line jsc's exception handling should be rationalized
https://bugs.webkit.org/show_bug.cgi?id=83437

Reviewed by Dan Bernstein.
        
- If an exception is thrown during run() execution, it is now propagated,
  so that it will terminate program execution unless it is caught.
          
- If program execution terminates with an exception, the exception is now
  always printed.
          
- When printing the exception, the backtrace is now also printed if one is
  available. It will only not be available if you use something akin to my
  favorite line of code, 'throw "error"', since primitives don't have
  properties and hence we cannot attach a "stack" property to them.

* jsc.cpp:
(functionRun):
(runWithScripts):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (113552 => 113553)


--- trunk/Source/_javascript_Core/ChangeLog	2012-04-08 20:46:12 UTC (rev 113552)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-04-08 20:50:50 UTC (rev 113553)
@@ -1,3 +1,25 @@
+2012-04-08  Filip Pizlo  <[email protected]>
+
+        Command-line jsc's exception handling should be rationalized
+        https://bugs.webkit.org/show_bug.cgi?id=83437
+
+        Reviewed by Dan Bernstein.
+        
+        - If an exception is thrown during run() execution, it is now propagated,
+          so that it will terminate program execution unless it is caught.
+          
+        - If program execution terminates with an exception, the exception is now
+          always printed.
+          
+        - When printing the exception, the backtrace is now also printed if one is
+          available. It will only not be available if you use something akin to my
+          favorite line of code, 'throw "error"', since primitives don't have
+          properties and hence we cannot attach a "stack" property to them.
+
+        * jsc.cpp:
+        (functionRun):
+        (runWithScripts):
+
 2012-04-04  Filip Pizlo  <[email protected]>
 
         Forced OSR exits should lead to recompilation based on count, not rate

Modified: trunk/Source/_javascript_Core/jsc.cpp (113552 => 113553)


--- trunk/Source/_javascript_Core/jsc.cpp	2012-04-08 20:46:12 UTC (rev 113552)
+++ trunk/Source/_javascript_Core/jsc.cpp	2012-04-08 20:50:50 UTC (rev 113553)
@@ -321,11 +321,17 @@
 
     GlobalObject* globalObject = GlobalObject::create(exec->globalData(), GlobalObject::createStructure(exec->globalData(), jsNull()), Vector<UString>());
 
+    JSValue exception;
     StopWatch stopWatch;
     stopWatch.start();
-    evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), jscSource(script.data(), fileName));
+    evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), jscSource(script.data(), fileName), JSValue(), &exception);
     stopWatch.stop();
 
+    if (!!exception) {
+        throwError(globalObject->globalExec(), exception);
+        return JSValue::encode(jsUndefined());
+    }
+    
     return JSValue::encode(jsNumber(stopWatch.getElapsedMS()));
 }
 
@@ -522,11 +528,14 @@
         JSValue evaluationException;
         JSValue returnValue = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), jscSource(script, fileName), JSValue(), &evaluationException);
         success = success && !evaluationException;
-        if (dump) {
-            if (evaluationException)
-                printf("Exception: %s\n", evaluationException.toString(globalObject->globalExec())->value(globalObject->globalExec()).utf8().data());
-            else
-                printf("End: %s\n", returnValue.toString(globalObject->globalExec())->value(globalObject->globalExec()).utf8().data());
+        if (dump && !evaluationException)
+            printf("End: %s\n", returnValue.toString(globalObject->globalExec())->value(globalObject->globalExec()).utf8().data());
+        if (evaluationException) {
+            printf("Exception: %s\n", evaluationException.toString(globalObject->globalExec())->value(globalObject->globalExec()).utf8().data());
+            Identifier stackID(globalObject->globalExec(), "stack");
+            JSValue stackValue = evaluationException.get(globalObject->globalExec(), stackID);
+            if (!stackValue.isUndefinedOrNull())
+                printf("%s\n", stackValue.toString(globalObject->globalExec())->value(globalObject->globalExec()).utf8().data());
         }
 
         globalData.stopSampling();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to