diff --git a/nashorn/src/jdk/nashorn/api/scripting/NashornException.java b/nashorn/src/jdk/nashorn/api/scripting/NashornException.java index 5f73aa6289c..a5f8c24a2e6 100644 --- a/nashorn/src/jdk/nashorn/api/scripting/NashornException.java +++ b/nashorn/src/jdk/nashorn/api/scripting/NashornException.java @@ -45,11 +45,11 @@ import jdk.nashorn.internal.runtime.ScriptObject; @SuppressWarnings("serial") public abstract class NashornException extends RuntimeException { // script file name - private final String fileName; + private String fileName; // script line number - private final int line; + private int line; // script column number - private final int column; + private int column; // underlying ECMA error object - lazily initialized private Object ecmaError; @@ -124,6 +124,15 @@ public abstract class NashornException extends RuntimeException { return fileName; } + /** + * Set the source file name for this {@code NashornException} + * + * @param fileName the file name + */ + public final void setFileName(final String fileName) { + this.fileName = fileName; + } + /** * Get the line number for this {@code NashornException} * @@ -133,15 +142,33 @@ public abstract class NashornException extends RuntimeException { return line; } + /** + * Set the line number for this {@code NashornException} + * + * @param line the line number + */ + public final void setLineNumber(final int line) { + this.line = line; + } + /** * Get the column for this {@code NashornException} * - * @return the column + * @return the column number */ public final int getColumnNumber() { return column; } + /** + * Set the column for this {@code NashornException} + * + * @param column the column number + */ + public final void setColumnNumber(final int column) { + this.column = column; + } + /** * Returns array javascript stack frames from the given exception object. * @@ -208,9 +235,9 @@ public abstract class NashornException extends RuntimeException { final Object thrown = getThrown(); if (thrown instanceof ScriptObject) { - ecmaError = ScriptObjectMirror.wrap(thrown, global); + setEcmaError(ScriptObjectMirror.wrap(thrown, global)); } else { - ecmaError = thrown; + setEcmaError(thrown); } return this; @@ -225,4 +252,14 @@ public abstract class NashornException extends RuntimeException { public Object getEcmaError() { return ecmaError; } + + /** + * Return the underlying ECMA error object, if available. + * + * @param ecmaError underlying ECMA Error object's mirror or whatever was thrown + * from script such as a String, Number or a Boolean. + */ + public void setEcmaError(final Object ecmaError) { + this.ecmaError = ecmaError; + } } diff --git a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java index c3b1dbe2656..6ad92829bfe 100644 --- a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java +++ b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java @@ -2023,8 +2023,6 @@ final class CodeGenerator extends NodeOperatorVisitor (test/script/basic/JDK-8031983.js:31) +43 +Error + at (test/script/basic/JDK-8031983.js:41) +[object Object] + at (test/script/basic/JDK-8031983.js:50) diff --git a/nashorn/test/script/basic/JDK-8032004.js b/nashorn/test/script/basic/JDK-8032004.js new file mode 100644 index 00000000000..2995566c50a --- /dev/null +++ b/nashorn/test/script/basic/JDK-8032004.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2014, 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-8032004: instance property "message" of Error objects should be non-enumerable + * + * @test + * @run + */ + +function check(obj) { + if (obj.propertyIsEnumerable("message")) { + fail(obj.name + " object's message property is enumerable!"); + } +} + +check(new Error("test")); +check(new EvalError("test")); +check(new RangeError("test")); +check(new ReferenceError("test")); +check(new SyntaxError("test")); +check(new TypeError("test")); +check(new URIError("test")); diff --git a/nashorn/test/script/basic/NASHORN-111.js.EXPECTED b/nashorn/test/script/basic/NASHORN-111.js.EXPECTED index 287f25580c4..0967ef424bc 100644 --- a/nashorn/test/script/basic/NASHORN-111.js.EXPECTED +++ b/nashorn/test/script/basic/NASHORN-111.js.EXPECTED @@ -1 +1 @@ -{"message":"type error"} +{} diff --git a/nashorn/test/script/basic/NASHORN-441.js.EXPECTED b/nashorn/test/script/basic/NASHORN-441.js.EXPECTED index de9ea224be4..c0038426b2b 100644 --- a/nashorn/test/script/basic/NASHORN-441.js.EXPECTED +++ b/nashorn/test/script/basic/NASHORN-441.js.EXPECTED @@ -12,6 +12,6 @@ finally 4 try 5 rethrow 5 finally 5 -Error: try 5 thrown in line 71 +Error: try 5 thrown in line 74 try 6 finally 6