Renames Exceptions wrap/unwrap to toJava/toJs

Change-Id: Ibcdc229c3290a8208cc40203a43551c337d434f9
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/RuntimeConstants.java b/dev/core/src/com/google/gwt/dev/jjs/ast/RuntimeConstants.java
index c1f2e80..47042ba 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/RuntimeConstants.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/RuntimeConstants.java
@@ -57,8 +57,8 @@
 
   public static final String EXCEPTIONS_CHECK_NOT_NULL = "Exceptions.checkNotNull";
   public static final String EXCEPTIONS_MAKE_ASSERTION_ERROR_ = "Exceptions.makeAssertionError";
-  public static final String EXCEPTIONS_UNWRAP = "Exceptions.unwrap";
-  public static final String EXCEPTIONS_WRAP = "Exceptions.wrap";
+  public static final String EXCEPTIONS_TO_JS = "Exceptions.toJs";
+  public static final String EXCEPTIONS_TO_JAVA = "Exceptions.toJava";
 
   public static final String GWT_IS_SCRIPT = "GWT.isScript";
 
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/CatchBlockNormalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/CatchBlockNormalizer.java
index f89d434..c0c067c 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/CatchBlockNormalizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/CatchBlockNormalizer.java
@@ -52,7 +52,7 @@
    * Collapses all multi-catch blocks into a single catch block.
    */
   private class CollapseCatchBlocks extends JModVisitor {
-    JMethod wrapMethod = program.getIndexedMethod(RuntimeConstants.EXCEPTIONS_WRAP);
+    JMethod wrapMethod = program.getIndexedMethod(RuntimeConstants.EXCEPTIONS_TO_JAVA);
 
     @Override
     public void endVisit(JMethodBody x, Context ctx) {
@@ -78,7 +78,7 @@
       JBlock newCatchBlock = new JBlock(catchInfo);
 
       {
-        // $e = Exceptions.wrap($e)
+        // $e = Exceptions.toJava($e)
         JMethodCall call =
             new JMethodCall(catchInfo, null, wrapMethod, exceptionVariable.makeRef(catchInfo));
         newCatchBlock.addStmt(
@@ -140,12 +140,12 @@
     }
   }
 
-  private class UnwrapJavaScriptExceptionVisitor extends JModVisitor {
-    JMethod unwrapMethod = program.getIndexedMethod(RuntimeConstants.EXCEPTIONS_UNWRAP);
+  private class UnwrapThrowableVisitor extends JModVisitor {
+    JMethod unwrapMethod = program.getIndexedMethod(RuntimeConstants.EXCEPTIONS_TO_JS);
 
     @Override
     public void endVisit(JThrowStatement x, Context ctx) {
-      // throw x; -> throw Exceptions.unwrap(x);
+      // throw x; -> throw Exceptions.toJs(x);
       ctx.replaceMe(createUnwrappedThrow(x));
     }
 
@@ -175,7 +175,7 @@
   private void execImpl() {
     CollapseCatchBlocks collapser = new CollapseCatchBlocks();
     collapser.accept(program);
-    UnwrapJavaScriptExceptionVisitor unwrapper = new UnwrapJavaScriptExceptionVisitor();
+    UnwrapThrowableVisitor unwrapper = new UnwrapThrowableVisitor();
     unwrapper.accept(program);
   }
 
diff --git a/dev/core/src/com/google/gwt/dev/js/JsStackEmulator.java b/dev/core/src/com/google/gwt/dev/js/JsStackEmulator.java
index 0faa7ad..44c917d 100644
--- a/dev/core/src/com/google/gwt/dev/js/JsStackEmulator.java
+++ b/dev/core/src/com/google/gwt/dev/js/JsStackEmulator.java
@@ -82,7 +82,7 @@
 
   /**
    * Resets the global stack depth to the local stack index and top stack frame
-   * after calls to Exceptions.wrap. This is created by
+   * after calls to Exceptions.toJava. This is created by
    * {@link EntryExitVisitor#visit(JsCatch, JsContext)}.
    */
   private class CatchStackReset extends JsModVisitor {
@@ -113,7 +113,7 @@
   }
 
   private boolean isExceptionWrappingCode(JsExprStmt x) {
-    // Looking for e = wrap(e);
+    // Looking for e = Exceptions.toJava(e);
     JsExpression expr = x.getExpression();
 
     if (!(expr instanceof JsBinaryOperation)) {
@@ -136,7 +136,7 @@
       return false;
     }
 
-    // caughtFunction is the JsFunction translated from Exceptions.wrap
+    // caughtFunction is the JsFunction translated from Exceptions.toJava
     if (name != wrapFunctionName) {
       return false;
     }
@@ -204,7 +204,7 @@
    * try {
    *   foo();
    * } catch (e) {
-   *   e = wrap(e);
+   *   e = Exceptions.toJava(e);
    *   $stackDepth = stackIndex;
    *   throw e;
    * } finally {
@@ -458,26 +458,26 @@
 
     private JsCatch makeSyntheticCatchBlock(JsTry x) {
       /*
-       * catch (e) { e = wrap(e); throw unwrap(e); }
+       * catch (e) { e = Exceptions.toJava(e); throw Exceptions.toJs(e); }
        */
       SourceInfo info = x.getSourceInfo();
 
       JsCatch c = new JsCatch(info, currentFunction.getScope(), "e");
       JsName paramName = c.getParameter().getName();
 
-      // wrap(e)
+      // Exceptiobs.toJava(e)
       JsInvocation wrapCall = new JsInvocation(info, wrapFunctionName.makeRef(info),
           paramName.makeRef(info));
 
-      // e = wrap(e)
+      // e = Exceptions.toJava(e)
       JsBinaryOperation asg = new JsBinaryOperation(info, JsBinaryOperator.ASG,
           paramName.makeRef(info), wrapCall);
 
-      // unwrap(e)
+      // Exceptions.toJs(e)
       JsInvocation unwrapCall =
           new JsInvocation(info, unwrapFunctionName.makeRef(info), paramName.makeRef(info));
 
-      // throw unwrap(e)
+      // throw Exceptions.toJs(e)
       JsThrow throwStatement = new JsThrow(info, unwrapCall);
 
       JsBlock body = new JsBlock(info);
@@ -1012,9 +1012,9 @@
 
   private void execImpl() {
     wrapFunctionName =
-        JsUtils.getJsNameForMethod(jjsmap, jprogram, RuntimeConstants.EXCEPTIONS_WRAP);
+        JsUtils.getJsNameForMethod(jjsmap, jprogram, RuntimeConstants.EXCEPTIONS_TO_JAVA);
     unwrapFunctionName =
-        JsUtils.getJsNameForMethod(jjsmap, jprogram, RuntimeConstants.EXCEPTIONS_UNWRAP);
+        JsUtils.getJsNameForMethod(jjsmap, jprogram, RuntimeConstants.EXCEPTIONS_TO_JS);
     if (wrapFunctionName == null) {
       // No exceptions caught? Weird, but possible.
       return;
diff --git a/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Exceptions.java b/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Exceptions.java
index 487047b..eb90822 100644
--- a/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Exceptions.java
+++ b/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Exceptions.java
@@ -26,7 +26,7 @@
 final class Exceptions {
 
   @DoNotInline // This frame can be useful in understanding the native stack
-  static Object wrap(Object e) {
+  static Object toJava(Object e) {
     // Although this is impossible to happen in code generated from Java (as we always unwrap
     // before throwing), there are code out there where the Java exception is instantiated and
     // thrown in native code, hence we may receive it already wrapped.
@@ -43,7 +43,7 @@
   }
 
   @DoNotInline // This method shouldn't be inlined and pruned as JsStackEmulator needs it.
-  static native Object unwrap(Object t)/*-{
+  static native Object toJs(Object t)/*-{
     return t.@Throwable::backingJsObject;
   }-*/;
 
diff --git a/dev/core/test/com/google/gwt/dev/jjs/JavaAstConstructor.java b/dev/core/test/com/google/gwt/dev/jjs/JavaAstConstructor.java
index 0bf25ef..322f5f0 100644
--- a/dev/core/test/com/google/gwt/dev/jjs/JavaAstConstructor.java
+++ b/dev/core/test/com/google/gwt/dev/jjs/JavaAstConstructor.java
@@ -210,8 +210,8 @@
       return Joiner.on("\n").join(
           "package com.google.gwt.lang;",
           "public class Exceptions { ",
-          "  static Object wrap(Object e) { return e; }",
-          "  static Object unwrap(Object e) { return e; }",
+          "  static Object toJava(Object e) { return e; }",
+          "  static Object toJs(Object e) { return e; }",
           "  static RuntimeException makeAssertionError() { return new RuntimeException(); }",
           "  static Throwable safeClose(AutoCloseable resource, Throwable mainException) {",
           "    return mainException;", "  }",
diff --git a/dev/core/test/com/google/gwt/dev/js/JsStackEmulatorTest.java b/dev/core/test/com/google/gwt/dev/js/JsStackEmulatorTest.java
index de2ad5d..1114d41 100644
--- a/dev/core/test/com/google/gwt/dev/js/JsStackEmulatorTest.java
+++ b/dev/core/test/com/google/gwt/dev/js/JsStackEmulatorTest.java
@@ -146,7 +146,7 @@
     checkOnModuleLoad(program, "function onModuleLoad(){" +
         "var stackIndex;$stack[stackIndex=++$stackDepth]=onModuleLoad;" +
         "$location[stackIndex]='EntryPoint.java:'+'3',$clinit_EntryPoint();" +
-        "throw unwrap(($location[stackIndex]='EntryPoint.java:'+'4',new RuntimeException))" +
+        "throw toJs(($location[stackIndex]='EntryPoint.java:'+'4',new RuntimeException))" +
         "}");
   }
 
@@ -170,7 +170,7 @@
     checkOnModuleLoad(program, "function onModuleLoad(){" +
         "var stackIndex;$stack[stackIndex=++$stackDepth]=onModuleLoad;" +
         "$location[stackIndex]='EntryPoint.java:'+'6',$clinit_EntryPoint();" +
-        "throw unwrap(new RuntimeException(" +
+        "throw toJs(new RuntimeException(" +
         "($tmp=($location[stackIndex]='EntryPoint.java:'+'4',thing).toString()," +
         "$location[stackIndex]='EntryPoint.java:'+'7',$tmp)))" +
         "}");
@@ -201,7 +201,7 @@
     checkOnModuleLoad(program, "function onModuleLoad(){" +
         "var stackIndex;$stack[stackIndex=++$stackDepth]=onModuleLoad;" +
         "$location[stackIndex]='EntryPoint.java:'+'7',$clinit_EntryPoint();" +
-        "throw unwrap(($tmp=($location[stackIndex]='EntryPoint.java:'+'5',factory)," +
+        "throw toJs(($tmp=($location[stackIndex]='EntryPoint.java:'+'5',factory)," +
         "$location[stackIndex]='EntryPoint.java:'+'8',$tmp).makeException())" +
         "}");
   }
@@ -226,12 +226,12 @@
     checkOnModuleLoad(program, "function onModuleLoad(){" +
         "var stackIndex;$stack[stackIndex=++$stackDepth]=onModuleLoad;" +
         "$location[stackIndex]='EntryPoint.java:'+'3',$clinit_EntryPoint();var e,s;" +
-        "try{throw unwrap(($location[stackIndex]='EntryPoint.java:'+'5',new RuntimeException))" +
-        "}catch($e0){$e0=wrap($e0);" +
+        "try{throw toJs(($location[stackIndex]='EntryPoint.java:'+'5',new RuntimeException))" +
+        "}catch($e0){$e0=toJava($e0);" +
         "$stackDepth=($location[stackIndex]='EntryPoint.java:'+'6',stackIndex);" +
         "if(instanceOf($e0,'java.lang.RuntimeException')){" +
         "e=$e0;s=($location[stackIndex]='EntryPoint.java:'+'7',e).getMessage()}" +
-        "else throw unwrap(($location[stackIndex]='EntryPoint.java:'+'6',$e0))}" +
+        "else throw toJs(($location[stackIndex]='EntryPoint.java:'+'6',$e0))}" +
         "$stackDepth=stackIndex-1" +
         "}");
   }
diff --git a/user/test/com/google/gwt/core/client/impl/StackTraceNativeTest.java b/user/test/com/google/gwt/core/client/impl/StackTraceNativeTest.java
index d800a6c..9b915a2 100644
--- a/user/test/com/google/gwt/core/client/impl/StackTraceNativeTest.java
+++ b/user/test/com/google/gwt/core/client/impl/StackTraceNativeTest.java
@@ -88,7 +88,7 @@
     };
 
     final String[] limited_wrap = {
-        Impl.getNameOf("@com.google.gwt.lang.Exceptions::wrap(*)"),
+        Impl.getNameOf("@com.google.gwt.lang.Exceptions::toJava(*)"),
         Impl.getNameOf("@com.google.gwt.core.client.impl.StackTraceExamples::getLiveException(*)"),
         Impl.getNameOf("@com.google.gwt.core.client.impl.StackTraceTestBase::assertJse(*)"),
     };