diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/Context.java b/mozilla/js/rhino/src/org/mozilla/javascript/Context.java index 4de761cf744..8d40e6e84d4 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/Context.java +++ b/mozilla/js/rhino/src/org/mozilla/javascript/Context.java @@ -294,10 +294,16 @@ public class Context public static final int FEATURE_WARNING_AS_ERROR = 12; /** - * Controls whether private and protected members can be accessed + * Enables enhanced access to Java. + * Specifically, controls whether private and protected members can be + * accessed, and whether scripts can catch all Java exceptions. + *

+ * Note that this feature should only be enabled for trusted scripts. + *

+ * By default {@link #hasFeature(int)} returns false. * @since 1.7 Release 1 */ - public static final int FEATURE_ACCESS_PRIVATE_MEMBERS = 13; + public static final int FEATURE_ENHANCED_JAVA_ACCESS = 13; public static final String languageVersionProperty = "language version"; @@ -1762,7 +1768,12 @@ public class Context } // special handling of Error so scripts would not catch them if (e instanceof Error) { - throw (Error)e; + Context cx = getContext(); + if (cx == null || + !cx.hasFeature(Context.FEATURE_ENHANCED_JAVA_ACCESS)) + { + throw (Error)e; + } } if (e instanceof RhinoException) { throw (RhinoException)e; @@ -2149,7 +2160,7 @@ public class Context * @see #FEATURE_LOCATION_INFORMATION_IN_ERROR * @see #FEATURE_STRICT_MODE * @see #FEATURE_WARNING_AS_ERROR - * @see #FEATURE_ACCESS_PRIVATE_MEMBERS + * @see #FEATURE_ENHANCED_JAVA_ACCESS */ public boolean hasFeature(int featureIndex) { diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/ContextFactory.java b/mozilla/js/rhino/src/org/mozilla/javascript/ContextFactory.java index 22d78f299a2..7e90322dd86 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/ContextFactory.java +++ b/mozilla/js/rhino/src/org/mozilla/javascript/ContextFactory.java @@ -288,7 +288,7 @@ public class ContextFactory case Context.FEATURE_WARNING_AS_ERROR: return false; - case Context.FEATURE_ACCESS_PRIVATE_MEMBERS: + case Context.FEATURE_ENHANCED_JAVA_ACCESS: return false; } // It is a bug to call the method with unknown featureIndex diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/JavaMembers.java b/mozilla/js/rhino/src/org/mozilla/javascript/JavaMembers.java index d7d99553fa5..b01c256113b 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/JavaMembers.java +++ b/mozilla/js/rhino/src/org/mozilla/javascript/JavaMembers.java @@ -73,7 +73,7 @@ class JavaMembers cl.getName()); } this.includePrivate = cx.hasFeature( - Context.FEATURE_ACCESS_PRIVATE_MEMBERS); + Context.FEATURE_ENHANCED_JAVA_ACCESS); this.members = new Hashtable(23); this.staticMembers = new Hashtable(7); this.cl = cl; diff --git a/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/JavaAcessibilityTest.java b/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/JavaAcessibilityTest.java index fbbd13842e6..b6cf3cafa1b 100644 --- a/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/JavaAcessibilityTest.java +++ b/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/JavaAcessibilityTest.java @@ -27,7 +27,7 @@ public class JavaAcessibilityTest extends TestCase { private ContextFactory contextFactory = new ShellContextFactory() { protected boolean hasFeature(Context cx, int featureIndex) { - if (featureIndex == Context.FEATURE_ACCESS_PRIVATE_MEMBERS) + if (featureIndex == Context.FEATURE_ENHANCED_JAVA_ACCESS) return true; return super.hasFeature(cx, featureIndex); } diff --git a/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/PrivateAccessClass.java b/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/PrivateAccessClass.java index 916812492e1..08f95a3f939 100644 --- a/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/PrivateAccessClass.java +++ b/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/PrivateAccessClass.java @@ -38,7 +38,7 @@ package org.mozilla.javascript.tests; /** * A class with private/protected/package private members, to test the Rhino - * feature Context.FEATURE_ACCESS_PRIVATE_MEMBERS, that allows bypassing Java + * feature Context.FEATURE_ENHANCED_JAVA_ACCESS, that allows bypassing Java * member access restrictions. * @author Donna Malayeri */ @@ -73,5 +73,17 @@ public class PrivateAccessClass int packagePrivateMethod() { return 3; } private int privateMethod() { return 4; } - protected int protectedMethod() { return 5; } + protected int protectedMethod() { return 5; } + + /* + * Suppress warnings about unused private members. + */ + public int referenceToPrivateMembers() { + PrivateAccessClass pac = new PrivateAccessClass(); + PrivateAccessClass pac2 = new PrivateAccessClass(2); + PrivateNestedClass pnc = new PrivateNestedClass(); + System.out.println(privateString); + return pnc.privateInt + staticPrivateInt + staticPrivateMethod() + + pac.privateMethod(); + } }