Fri, 17 Jan 2014 20:09:47 +0530
8032060: PropertyMap of Error objects is not stable
Reviewed-by: jlaskey, hannesw
1.1 --- a/src/jdk/nashorn/internal/objects/Global.java Thu Jan 16 22:50:53 2014 +0530 1.2 +++ b/src/jdk/nashorn/internal/objects/Global.java Fri Jan 17 20:09:47 2014 +0530 1.3 @@ -1705,8 +1705,25 @@ 1.4 initScripting(env); 1.5 } 1.6 1.7 - if (Context.DEBUG && System.getSecurityManager() == null) { 1.8 - initDebug(); 1.9 + if (Context.DEBUG) { 1.10 + boolean debugOkay; 1.11 + final SecurityManager sm = System.getSecurityManager(); 1.12 + if (sm != null) { 1.13 + try { 1.14 + sm.checkPermission(new RuntimePermission(Context.NASHORN_DEBUG_MODE)); 1.15 + debugOkay = true; 1.16 + } catch (final SecurityException ignored) { 1.17 + // if no permission, don't initialize Debug object 1.18 + debugOkay = false; 1.19 + } 1.20 + 1.21 + } else { 1.22 + debugOkay = true; 1.23 + } 1.24 + 1.25 + if (debugOkay) { 1.26 + initDebug(); 1.27 + } 1.28 } 1.29 1.30 copyBuiltins();
2.1 --- a/src/jdk/nashorn/internal/objects/NativeError.java Thu Jan 16 22:50:53 2014 +0530 2.2 +++ b/src/jdk/nashorn/internal/objects/NativeError.java Fri Jan 17 20:09:47 2014 +0530 2.3 @@ -85,6 +85,10 @@ 2.4 @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE) 2.5 public Object message; 2.6 2.7 + /** Nashorn extension: underlying exception */ 2.8 + @Property(attributes = Attribute.NOT_ENUMERABLE) 2.9 + public Object nashornException; 2.10 + 2.11 // initialized by nasgen 2.12 private static PropertyMap $nasgenmap$; 2.13
3.1 --- a/src/jdk/nashorn/internal/objects/NativeEvalError.java Thu Jan 16 22:50:53 2014 +0530 3.2 +++ b/src/jdk/nashorn/internal/objects/NativeEvalError.java Fri Jan 17 20:09:47 2014 +0530 3.3 @@ -55,6 +55,10 @@ 3.4 @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE) 3.5 public Object message; 3.6 3.7 + /** Nashorn extension: underlying exception */ 3.8 + @Property(attributes = Attribute.NOT_ENUMERABLE) 3.9 + public Object nashornException; 3.10 + 3.11 // initialized by nasgen 3.12 private static PropertyMap $nasgenmap$; 3.13
4.1 --- a/src/jdk/nashorn/internal/objects/NativeRangeError.java Thu Jan 16 22:50:53 2014 +0530 4.2 +++ b/src/jdk/nashorn/internal/objects/NativeRangeError.java Fri Jan 17 20:09:47 2014 +0530 4.3 @@ -55,6 +55,10 @@ 4.4 @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE) 4.5 public Object message; 4.6 4.7 + /** Nashorn extension: underlying exception */ 4.8 + @Property(attributes = Attribute.NOT_ENUMERABLE) 4.9 + public Object nashornException; 4.10 + 4.11 // initialized by nasgen 4.12 private static PropertyMap $nasgenmap$; 4.13
5.1 --- a/src/jdk/nashorn/internal/objects/NativeReferenceError.java Thu Jan 16 22:50:53 2014 +0530 5.2 +++ b/src/jdk/nashorn/internal/objects/NativeReferenceError.java Fri Jan 17 20:09:47 2014 +0530 5.3 @@ -55,6 +55,10 @@ 5.4 @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE) 5.5 public Object message; 5.6 5.7 + /** Nashorn extension: underlying exception */ 5.8 + @Property(attributes = Attribute.NOT_ENUMERABLE) 5.9 + public Object nashornException; 5.10 + 5.11 // initialized by nasgen 5.12 private static PropertyMap $nasgenmap$; 5.13
6.1 --- a/src/jdk/nashorn/internal/objects/NativeSyntaxError.java Thu Jan 16 22:50:53 2014 +0530 6.2 +++ b/src/jdk/nashorn/internal/objects/NativeSyntaxError.java Fri Jan 17 20:09:47 2014 +0530 6.3 @@ -55,6 +55,10 @@ 6.4 @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE) 6.5 public Object message; 6.6 6.7 + /** Nashorn extension: underlying exception */ 6.8 + @Property(attributes = Attribute.NOT_ENUMERABLE) 6.9 + public Object nashornException; 6.10 + 6.11 // initialized by nasgen 6.12 private static PropertyMap $nasgenmap$; 6.13
7.1 --- a/src/jdk/nashorn/internal/objects/NativeTypeError.java Thu Jan 16 22:50:53 2014 +0530 7.2 +++ b/src/jdk/nashorn/internal/objects/NativeTypeError.java Fri Jan 17 20:09:47 2014 +0530 7.3 @@ -55,6 +55,10 @@ 7.4 @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE) 7.5 public Object message; 7.6 7.7 + /** Nashorn extension: underlying exception */ 7.8 + @Property(attributes = Attribute.NOT_ENUMERABLE) 7.9 + public Object nashornException; 7.10 + 7.11 // initialized by nasgen 7.12 private static PropertyMap $nasgenmap$; 7.13
8.1 --- a/src/jdk/nashorn/internal/objects/NativeURIError.java Thu Jan 16 22:50:53 2014 +0530 8.2 +++ b/src/jdk/nashorn/internal/objects/NativeURIError.java Fri Jan 17 20:09:47 2014 +0530 8.3 @@ -54,6 +54,10 @@ 8.4 @Property(attributes = Attribute.NOT_ENUMERABLE, where = Where.PROTOTYPE) 8.5 public Object message; 8.6 8.7 + /** Nashorn extension: underlying exception */ 8.8 + @Property(attributes = Attribute.NOT_ENUMERABLE) 8.9 + public Object nashornException; 8.10 + 8.11 // initialized by nasgen 8.12 private static PropertyMap $nasgenmap$; 8.13
9.1 --- a/src/jdk/nashorn/internal/runtime/Context.java Thu Jan 16 22:50:53 2014 +0530 9.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java Fri Jan 17 20:09:47 2014 +0530 9.3 @@ -91,6 +91,11 @@ 9.4 */ 9.5 public static final String NASHORN_JAVA_REFLECTION = "nashorn.JavaReflection"; 9.6 9.7 + /** 9.8 + * Permission to enable nashorn debug mode. 9.9 + */ 9.10 + public static final String NASHORN_DEBUG_MODE = "nashorn.debugMode"; 9.11 + 9.12 // nashorn load psuedo URL prefixes 9.13 private static final String LOAD_CLASSPATH = "classpath:"; 9.14 private static final String LOAD_FX = "fx:";
10.1 --- a/src/jdk/nashorn/internal/runtime/ECMAException.java Thu Jan 16 22:50:53 2014 +0530 10.2 +++ b/src/jdk/nashorn/internal/runtime/ECMAException.java Fri Jan 17 20:09:47 2014 +0530 10.3 @@ -33,7 +33,6 @@ 10.4 import jdk.nashorn.api.scripting.NashornException; 10.5 import jdk.nashorn.internal.codegen.CompilerConstants.Call; 10.6 import jdk.nashorn.internal.codegen.CompilerConstants.FieldAccess; 10.7 -import jdk.nashorn.internal.objects.NativeError; 10.8 10.9 /** 10.10 * Exception used to implement ECMAScript "throw" from scripts. The actual thrown
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/test/script/trusted/JDK-8032060.js Fri Jan 17 20:09:47 2014 +0530 11.3 @@ -0,0 +1,72 @@ 11.4 +/* 11.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.7 + * 11.8 + * This code is free software; you can redistribute it and/or modify it 11.9 + * under the terms of the GNU General Public License version 2 only, as 11.10 + * published by the Free Software Foundation. 11.11 + * 11.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 11.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11.15 + * version 2 for more details (a copy is included in the LICENSE file that 11.16 + * accompanied this code). 11.17 + * 11.18 + * You should have received a copy of the GNU General Public License version 11.19 + * 2 along with this work; if not, write to the Free Software Foundation, 11.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 11.21 + * 11.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 11.23 + * or visit www.oracle.com if you need additional information or have any 11.24 + * questions. 11.25 + */ 11.26 + 11.27 +/** 11.28 + * JDK-8032060: PropertyMap of Error objects is not stable 11.29 + * 11.30 + * @test 11.31 + * @option -Dnashorn.debug=true 11.32 + * @fork 11.33 + * @run 11.34 + */ 11.35 + 11.36 +function checkMap(e1, e2) { 11.37 + if (! Debug.identical(Debug.map(e1), Debug.map(e2))) { 11.38 + fail("e1 and e2 have different maps"); 11.39 + } 11.40 + 11.41 + var m1, m2; 11.42 + 11.43 + try { 11.44 + throw e1 11.45 + } catch (e) { 11.46 + m1 = Debug.map(e) 11.47 + } 11.48 + 11.49 + try { 11.50 + throw e2 11.51 + } catch (e) { 11.52 + m2 = Debug.map(e) 11.53 + } 11.54 + 11.55 + if (! Debug.identical(m1, m2)) { 11.56 + fail("e1 and e2 have different maps after being thrown"); 11.57 + } 11.58 +} 11.59 + 11.60 +checkMap(new Error(), new Error()); 11.61 +checkMap(new EvalError(), new EvalError()); 11.62 +checkMap(new RangeError(), new RangeError()); 11.63 +checkMap(new ReferenceError(), new ReferenceError()); 11.64 +checkMap(new SyntaxError(), new SyntaxError()); 11.65 +checkMap(new TypeError(), new TypeError()); 11.66 +checkMap(new URIError(), new URIError()); 11.67 + 11.68 +// now try with message param 11.69 +checkMap(new Error("x"), new Error("y")); 11.70 +checkMap(new EvalError("x"), new EvalError("y")); 11.71 +checkMap(new RangeError("x"), new RangeError("y")); 11.72 +checkMap(new ReferenceError("x"), new ReferenceError("y")); 11.73 +checkMap(new SyntaxError("x"), new SyntaxError("y")); 11.74 +checkMap(new TypeError("x"), new TypeError("y")); 11.75 +checkMap(new URIError("x"), new URIError("y"));