8012164: Error.stack needs trimming

Fri, 31 May 2013 17:39:12 +0530

author
sundar
date
Fri, 31 May 2013 17:39:12 +0530
changeset 314
b4e6cc05ce09
parent 313
11b81fa7125a
child 315
64250b3a2f2a

8012164: Error.stack needs trimming
Reviewed-by: lagergren, jlaskey

src/jdk/nashorn/internal/objects/NativeError.java file | annotate | diff | comparison | revisions
test/script/basic/JDK-8012164.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8012164.js.EXPECTED file | annotate | diff | comparison | revisions
test/script/basic/NASHORN-108.js.EXPECTED file | annotate | diff | comparison | revisions
test/script/basic/NASHORN-109.js.EXPECTED file | annotate | diff | comparison | revisions
test/script/basic/errorstack.js.EXPECTED file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/objects/NativeError.java	Fri May 31 12:58:02 2013 +0200
     1.2 +++ b/src/jdk/nashorn/internal/objects/NativeError.java	Fri May 31 17:39:12 2013 +0530
     1.3 @@ -32,6 +32,7 @@
     1.4  import java.lang.invoke.MethodHandles;
     1.5  import java.util.ArrayList;
     1.6  import java.util.List;
     1.7 +import jdk.nashorn.internal.codegen.CompilerConstants;
     1.8  import jdk.nashorn.internal.objects.annotations.Attribute;
     1.9  import jdk.nashorn.internal.objects.annotations.Constructor;
    1.10  import jdk.nashorn.internal.objects.annotations.Function;
    1.11 @@ -248,7 +249,13 @@
    1.12              final List<StackTraceElement> filtered = new ArrayList<>();
    1.13              for (final StackTraceElement st : frames) {
    1.14                  if (ECMAErrors.isScriptFrame(st)) {
    1.15 -                    filtered.add(st);
    1.16 +                    final String className = "<" + st.getFileName() + ">";
    1.17 +                    String methodName = st.getMethodName();
    1.18 +                    if (methodName.equals(CompilerConstants.RUN_SCRIPT.symbolName())) {
    1.19 +                        methodName = "<program>";
    1.20 +                    }
    1.21 +                    filtered.add(new StackTraceElement(className, methodName,
    1.22 +                            st.getFileName(), st.getLineNumber()));
    1.23                  }
    1.24              }
    1.25              res = filtered.toArray();
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/script/basic/JDK-8012164.js	Fri May 31 17:39:12 2013 +0530
     2.3 @@ -0,0 +1,46 @@
     2.4 +/*
     2.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + * 
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + * 
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + * 
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + * 
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +
    2.28 +/**
    2.29 + * JDK-8012164: Error.stack needs trimming
    2.30 + *
    2.31 + * @test
    2.32 + * @run
    2.33 + */
    2.34 +
    2.35 +function func() {
    2.36 +   error();
    2.37 +}
    2.38 +
    2.39 +function error() {
    2.40 +  try {
    2.41 +      throw new Error('foo');
    2.42 +  } catch (e) {
    2.43 +      for (i in e.stack) {
    2.44 +          print(e.stack[i]);
    2.45 +      }
    2.46 +  }
    2.47 +}
    2.48 +
    2.49 +func();
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/script/basic/JDK-8012164.js.EXPECTED	Fri May 31 17:39:12 2013 +0530
     3.3 @@ -0,0 +1,3 @@
     3.4 +<test/script/basic/JDK-8012164.js>.error(test/script/basic/JDK-8012164.js:38)
     3.5 +<test/script/basic/JDK-8012164.js>.func(test/script/basic/JDK-8012164.js:33)
     3.6 +<test/script/basic/JDK-8012164.js>.<program>(test/script/basic/JDK-8012164.js:46)
     4.1 --- a/test/script/basic/NASHORN-108.js.EXPECTED	Fri May 31 12:58:02 2013 +0200
     4.2 +++ b/test/script/basic/NASHORN-108.js.EXPECTED	Fri May 31 17:39:12 2013 +0530
     4.3 @@ -1,3 +1,3 @@
     4.4 -runScript 33
     4.5 -runScript 32
     4.6 +<program> 33
     4.7 +<program> 32
     4.8  done
     5.1 --- a/test/script/basic/NASHORN-109.js.EXPECTED	Fri May 31 12:58:02 2013 +0200
     5.2 +++ b/test/script/basic/NASHORN-109.js.EXPECTED	Fri May 31 17:39:12 2013 +0530
     5.3 @@ -1,2 +1,2 @@
     5.4 -runScript 33
     5.5 +<program> 33
     5.6  done
     6.1 --- a/test/script/basic/errorstack.js.EXPECTED	Fri May 31 12:58:02 2013 +0200
     6.2 +++ b/test/script/basic/errorstack.js.EXPECTED	Fri May 31 17:39:12 2013 +0530
     6.3 @@ -1,4 +1,4 @@
     6.4  func3 : 40
     6.5  func2 : 36
     6.6  func1 : 32
     6.7 -runScript : 44
     6.8 +<program> : 44

mercurial