Do not record location for inlined code in JsStackEmulator.

Stack trace deobfuscation and reporting mix information about
the function appearing in the stack trace and the instrumented
line number and this to do not correspond to the location of
the actual code.

Now the stack frame for the inlined function will not appear in the
stack if its source code is from a different file; a better solution
would be to artificially add an "inlined" stack frame so that both
the call location and the inlined callee location appear in the stack
frame.

Change-Id: I93b821a37b8447dd28254e8da02d90bda1e56db2
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 e85bd62..3b130fa 100644
--- a/dev/core/src/com/google/gwt/dev/js/JsStackEmulator.java
+++ b/dev/core/src/com/google/gwt/dev/js/JsStackEmulator.java
@@ -576,7 +576,7 @@
           return;
         }
         if (recordLineNumbers) {
-          (new LocationVisitor(x)).accept(x.getBody());
+          (new LocationVisitor(x)).instrumentBody(x);
         } else {
           (new EntryExitVisitor(x)).accept(x.getBody());
         }
@@ -601,6 +601,7 @@
    */
   private class LocationVisitor extends EntryExitVisitor {
     private String lastFile;
+    private String mainFile;
     private int lastLine;
 
     /**
@@ -758,6 +759,14 @@
     }
 
     /**
+     * Instruments of the body of {@code fn} to keep track of source locations.
+     */
+    public void instrumentBody(JsFunction fn) {
+      mainFile = fn.getSourceInfo().getFileName();
+      accept(fn.getBody());
+    }
+
+    /**
      * If the invocation might be a method call, return its NameRef.
      * Otherwise, return null.
      */
@@ -813,8 +822,11 @@
       }
 
       SourceInfo locationToRecord = x.getSourceInfo();
-      if (sameAsLastLocation(locationToRecord)) {
-        return; // no change
+      if (sameAsLastLocation(locationToRecord) || !inSameFile(locationToRecord)) {
+        // Do not record inlined code from a different file as the error reporting might
+        // get the filename from the function appearing in the stack frame resulting in an unrelated
+        // and often non existing source location.
+        return;
       }
 
       JsBinaryOperation comma = new JsBinaryOperation(locationToRecord, JsBinaryOperator.COMMA,
@@ -866,6 +878,10 @@
           && (!recordFileNames || info.getFileName().equals(lastFile));
     }
 
+    private boolean inSameFile(SourceInfo info) {
+      return info.getFileName().equals(mainFile);
+    }
+
     /**
      * Wrap an expression so that we record a location after evaluating it.
      * (Requires a temporary variable.)