More work for bug 244492: I deprecated ClassDefinitionException modified

ScriptableObject to use EvaluatorException instead.

For greater compatibility I also changed ClassDefinitionException to extend
from RuntimeException, not Exception so compilers would not complain about
"catch (ClassDefinitionException ex)" when no ClassDefinitionException is present in the called code.
This commit is contained in:
igor%mir2.org 2004-09-10 17:50:05 +00:00
Родитель 8bbc783f57
Коммит 16ae7ea84b
4 изменённых файлов: 10 добавлений и 66 удалений

Просмотреть файл

@ -1,7 +1,6 @@
apiClasses=\
src/org/mozilla/javascript/Callable.java,\
src/org/mozilla/javascript/ClassCache.java,\
src/org/mozilla/javascript/ClassDefinitionException.java,\
src/org/mozilla/javascript/ClassShutter.java,\
src/org/mozilla/javascript/CompilerEnvirons.java,\
src/org/mozilla/javascript/Context.java,\

Просмотреть файл

@ -1,48 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
// API class
package org.mozilla.javascript;
/**
* Thrown if errors are detected while attempting to define a host object
* from a Java class.
*/
public class ClassDefinitionException extends Exception {
public ClassDefinitionException(String detail) {
super(detail);
}
}

Просмотреть файл

@ -73,8 +73,6 @@ public final class LazilyLoadedCtor {
try {
ScriptableObject.defineClass(obj, cl, sealed);
isReplaced = true;
} catch (ClassDefinitionException ex) {
removeOnError = true;
} catch (InvocationTargetException ex) {
Throwable target = ex.getTargetException();
if (target instanceof RuntimeException) {

Просмотреть файл

@ -653,7 +653,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable,
*
* First, the zero-parameter constructor of the class is called to
* create the prototype. If no such constructor exists,
* a ClassDefinitionException is thrown. <p>
* a {@link EvaluatorException} is thrown. <p>
*
* Next, all methods are scanned for special prefixes that indicate that they
* have special meaning for defining JavaScript objects.
@ -695,11 +695,11 @@ public abstract class ScriptableObject implements Scriptable, Serializable,
* Java constructor, that constructor is used to define
* the JavaScript constructor. If the the class has two constructors,
* one must be the zero-argument constructor (otherwise an
* ClassDefinitionException would have already been thrown
* {@link EvaluatorException} would have already been thrown
* when the prototype was to be created). In this case
* the Java constructor with one or more parameters will be used
* to define the JavaScript constructor. If the class has three
* or more constructors, an ClassDefinitionException
* or more constructors, an {@link EvaluatorException}
* will be thrown.<p>
*
* Finally, if there is a method
@ -720,8 +720,6 @@ public abstract class ScriptableObject implements Scriptable, Serializable,
* the named class
* @exception InvocationTargetException if an exception is thrown
* during execution of methods of the named class
* @exception ClassDefinitionException if an appropriate
* constructor cannot be found to create the prototype
* @see org.mozilla.javascript.Function
* @see org.mozilla.javascript.FunctionObject
* @see org.mozilla.javascript.ScriptableObject#READONLY
@ -729,7 +727,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable,
*/
public static void defineClass(Scriptable scope, Class clazz)
throws IllegalAccessException, InstantiationException,
InvocationTargetException, ClassDefinitionException
InvocationTargetException
{
defineClass(scope, clazz, false);
}
@ -755,14 +753,12 @@ public abstract class ScriptableObject implements Scriptable, Serializable,
* the named class
* @exception InvocationTargetException if an exception is thrown
* during execution of methods of the named class
* @exception ClassDefinitionException if an appropriate
* constructor cannot be found to create the prototype
* @since 1.4R3
*/
public static void defineClass(Scriptable scope, Class clazz,
boolean sealed)
throws IllegalAccessException, InstantiationException,
InvocationTargetException, ClassDefinitionException
InvocationTargetException
{
Method[] methods = FunctionObject.getMethodList(clazz);
for (int i=0; i < methods.length; i++) {
@ -804,8 +800,8 @@ public abstract class ScriptableObject implements Scriptable, Serializable,
}
}
if (protoCtor == null) {
throw new ClassDefinitionException(
Context.getMessage1("msg.zero.arg.ctor", clazz.getName()));
throw Context.reportRuntimeError1(
"msg.zero.arg.ctor", clazz.getName());
}
Scriptable proto = (Scriptable)
@ -834,9 +830,8 @@ public abstract class ScriptableObject implements Scriptable, Serializable,
ctorMember = ctors[0];
}
if (ctorMember == null) {
throw new ClassDefinitionException(
Context.getMessage1("msg.ctor.multiple.parms",
clazz.getName()));
throw Context.reportRuntimeError1(
"msg.ctor.multiple.parms", clazz.getName());
}
}
@ -877,7 +872,7 @@ public abstract class ScriptableObject implements Scriptable, Serializable,
} else if (name.startsWith(staticFunctionPrefix)) {
prefix = staticFunctionPrefix;
if (!Modifier.isStatic(methods[i].getModifiers())) {
throw new ClassDefinitionException(
throw Context.reportRuntimeError(
"jsStaticFunction must be used with static method.");
}
} else if (name.startsWith(getterPrefix)) {