зеркало из https://github.com/mozilla/pjs.git
Changing Context.newObject to use ScriptRuntime.getExistingCtor to get constructor Function instance. In this way Context.newObject will throw the same set of exceptions that other parts of Rhino will throw on bad access to constructor.
With this change NotAFunctionException is no longer used so it is deprecated and changed to extend from Error not Exception for source compatibility: otherwise compiler will complain about unreachable catch handler.
This commit is contained in:
Родитель
4c14c37359
Коммит
9db4ab159d
|
@ -10,7 +10,6 @@ apiClasses=\
|
|||
src/org/mozilla/javascript/FunctionObject.java,\
|
||||
src/org/mozilla/javascript/ImporterTopLevel.java,\
|
||||
src/org/mozilla/javascript/JavaScriptException.java,\
|
||||
src/org/mozilla/javascript/NotAFunctionException.java,\
|
||||
src/org/mozilla/javascript/PropertyException.java,\
|
||||
src/org/mozilla/javascript/Script.java,\
|
||||
src/org/mozilla/javascript/Scriptable.java,\
|
||||
|
|
|
@ -1045,19 +1045,15 @@ public class Context {
|
|||
* @param scope the scope to search for the constructor and to evaluate
|
||||
* against
|
||||
* @return the new object
|
||||
* @exception PropertyException if "Object" cannot be found in
|
||||
* the scope
|
||||
* @exception NotAFunctionException if the "Object" found in the scope
|
||||
* is not a function
|
||||
* @exception EvaluatorException if "Object" cannot be found in
|
||||
* the scope or is not a function
|
||||
* @exception JavaScriptException if an uncaught JavaScript exception
|
||||
* occurred while creating the object
|
||||
*/
|
||||
public Scriptable newObject(Scriptable scope)
|
||||
throws PropertyException,
|
||||
NotAFunctionException,
|
||||
JavaScriptException
|
||||
throws EvaluatorException, JavaScriptException
|
||||
{
|
||||
return newObject(scope, "Object", null);
|
||||
return newObject(scope, "Object", ScriptRuntime.emptyArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1069,19 +1065,15 @@ public class Context {
|
|||
* @param scope the scope to search for the constructor and to evaluate against
|
||||
* @param constructorName the name of the constructor to call
|
||||
* @return the new object
|
||||
* @exception PropertyException if a property with the constructor
|
||||
* name cannot be found in the scope
|
||||
* @exception NotAFunctionException if the property found in the scope
|
||||
* is not a function
|
||||
* @exception EvaluatorException if a property with the constructor
|
||||
* name cannot be found in the scope or is not a function
|
||||
* @exception JavaScriptException if an uncaught JavaScript exception
|
||||
* occurred while creating the object
|
||||
*/
|
||||
public Scriptable newObject(Scriptable scope, String constructorName)
|
||||
throws PropertyException,
|
||||
NotAFunctionException,
|
||||
JavaScriptException
|
||||
throws EvaluatorException, JavaScriptException
|
||||
{
|
||||
return newObject(scope, constructorName, null);
|
||||
return newObject(scope, constructorName, ScriptRuntime.emptyArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1102,33 +1094,20 @@ public class Context {
|
|||
* @param constructorName the name of the constructor to call
|
||||
* @param args the array of arguments for the constructor
|
||||
* @return the new object
|
||||
* @exception PropertyException if a property with the constructor
|
||||
* name cannot be found in the scope
|
||||
* @exception NotAFunctionException if the property found in the scope
|
||||
* is not a function
|
||||
* @exception EvaluatorException if a property with the constructor
|
||||
* name cannot be found in the scope or is not a function
|
||||
* @exception JavaScriptException if an uncaught JavaScript exception
|
||||
* occurs while creating the object
|
||||
*/
|
||||
public Scriptable newObject(Scriptable scope, String constructorName,
|
||||
Object[] args)
|
||||
throws PropertyException,
|
||||
NotAFunctionException,
|
||||
JavaScriptException
|
||||
throws EvaluatorException, JavaScriptException
|
||||
{
|
||||
scope = ScriptableObject.getTopLevelScope(scope);
|
||||
Object ctorVal = ScriptableObject.getProperty(scope, constructorName);
|
||||
if (ctorVal instanceof Function) {
|
||||
Function ctor = (Function) ctorVal;
|
||||
if (args == null) { args = ScriptRuntime.emptyArgs; }
|
||||
return ctor.construct(this, scope, args);
|
||||
}
|
||||
if (ctorVal == Scriptable.NOT_FOUND) {
|
||||
String message = getMessage1("msg.ctor.not.found", constructorName);
|
||||
throw new PropertyException(message);
|
||||
} else {
|
||||
String message = getMessage1("msg.not.ctor", constructorName);
|
||||
throw new NotAFunctionException(message);
|
||||
}
|
||||
Function ctor = ScriptRuntime.getExistingCtor(this, scope,
|
||||
constructorName);
|
||||
if (args == null) { args = ScriptRuntime.emptyArgs; }
|
||||
return ctor.construct(this, scope, args);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -610,15 +610,9 @@ public class NativeGlobal implements Serializable, IdFunctionMaster
|
|||
return new EcmaError((NativeError)errorObject, sourceName,
|
||||
lineNumber, columnNumber, lineSource);
|
||||
}
|
||||
catch (PropertyException x) {
|
||||
throw new RuntimeException(x.toString());
|
||||
}
|
||||
catch (JavaScriptException x) {
|
||||
throw new RuntimeException(x.toString());
|
||||
}
|
||||
catch (NotAFunctionException x) {
|
||||
throw new RuntimeException(x.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,52 +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):
|
||||
* Norris Boyd
|
||||
*
|
||||
* 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 call is attempted on an object that is not a function.
|
||||
*/
|
||||
public class NotAFunctionException extends Exception {
|
||||
|
||||
public NotAFunctionException() {
|
||||
}
|
||||
|
||||
public NotAFunctionException(String detail) {
|
||||
super(detail);
|
||||
}
|
||||
|
||||
}
|
Загрузка…
Ссылка в новой задаче