8012164: Error.stack needs trimming

Reviewed-by: lagergren, jlaskey
diff --git a/nashorn/src/jdk/nashorn/internal/objects/NativeError.java b/nashorn/src/jdk/nashorn/internal/objects/NativeError.java
index 433f931..5473c8e 100644
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeError.java
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeError.java
@@ -32,6 +32,7 @@
 import java.lang.invoke.MethodHandles;
 import java.util.ArrayList;
 import java.util.List;
+import jdk.nashorn.internal.codegen.CompilerConstants;
 import jdk.nashorn.internal.objects.annotations.Attribute;
 import jdk.nashorn.internal.objects.annotations.Constructor;
 import jdk.nashorn.internal.objects.annotations.Function;
@@ -248,7 +249,13 @@
             final List<StackTraceElement> filtered = new ArrayList<>();
             for (final StackTraceElement st : frames) {
                 if (ECMAErrors.isScriptFrame(st)) {
-                    filtered.add(st);
+                    final String className = "<" + st.getFileName() + ">";
+                    String methodName = st.getMethodName();
+                    if (methodName.equals(CompilerConstants.RUN_SCRIPT.symbolName())) {
+                        methodName = "<program>";
+                    }
+                    filtered.add(new StackTraceElement(className, methodName,
+                            st.getFileName(), st.getLineNumber()));
                 }
             }
             res = filtered.toArray();
diff --git a/nashorn/test/script/basic/JDK-8012164.js b/nashorn/test/script/basic/JDK-8012164.js
new file mode 100644
index 0000000..9134d14
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8012164.js
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+/**
+ * JDK-8012164: Error.stack needs trimming
+ *
+ * @test
+ * @run
+ */
+
+function func() {
+   error();
+}
+
+function error() {
+  try {
+      throw new Error('foo');
+  } catch (e) {
+      for (i in e.stack) {
+          print(e.stack[i]);
+      }
+  }
+}
+
+func();
diff --git a/nashorn/test/script/basic/JDK-8012164.js.EXPECTED b/nashorn/test/script/basic/JDK-8012164.js.EXPECTED
new file mode 100644
index 0000000..e70edea
--- /dev/null
+++ b/nashorn/test/script/basic/JDK-8012164.js.EXPECTED
@@ -0,0 +1,3 @@
+<test/script/basic/JDK-8012164.js>.error(test/script/basic/JDK-8012164.js:38)
+<test/script/basic/JDK-8012164.js>.func(test/script/basic/JDK-8012164.js:33)
+<test/script/basic/JDK-8012164.js>.<program>(test/script/basic/JDK-8012164.js:46)
diff --git a/nashorn/test/script/basic/NASHORN-108.js.EXPECTED b/nashorn/test/script/basic/NASHORN-108.js.EXPECTED
index 59e90f6..066c8ff 100644
--- a/nashorn/test/script/basic/NASHORN-108.js.EXPECTED
+++ b/nashorn/test/script/basic/NASHORN-108.js.EXPECTED
@@ -1,3 +1,3 @@
-runScript 33
-runScript 32
+<program> 33
+<program> 32
 done
diff --git a/nashorn/test/script/basic/NASHORN-109.js.EXPECTED b/nashorn/test/script/basic/NASHORN-109.js.EXPECTED
index fca137e..9de7b322 100644
--- a/nashorn/test/script/basic/NASHORN-109.js.EXPECTED
+++ b/nashorn/test/script/basic/NASHORN-109.js.EXPECTED
@@ -1,2 +1,2 @@
-runScript 33
+<program> 33
 done
diff --git a/nashorn/test/script/basic/errorstack.js.EXPECTED b/nashorn/test/script/basic/errorstack.js.EXPECTED
index bb85d4e..8ddae4d 100644
--- a/nashorn/test/script/basic/errorstack.js.EXPECTED
+++ b/nashorn/test/script/basic/errorstack.js.EXPECTED
@@ -1,4 +1,4 @@
 func3 : 40
 func2 : 36
 func1 : 32
-runScript : 44
+<program> : 44