Hi, Norris!

The attached patch moves the IdFunction.Master interface to the
separated file IdFunctionMaster and eliminates getParentScope from the
interface: it is simpler to set scope explicitly.

The patch assumes the changes in IdFunction.java from the previous patch
  and were produced via:

diff -uP javascript.2000-05-10 javascript

Regards, Igor
This commit is contained in:
nboyd%atg.com 2001-05-12 13:15:39 +00:00
parent bca11b5ad0
commit 8ef49d0abb
4 changed files with 62 additions and 35 deletions

View File

@ -49,26 +49,7 @@ public class IdFunction extends ScriptableObject implements Function
public static final int FUNCTION_AND_CONSTRUCTOR = 2;
/** Master for id-based functions that knows their properties and how to
** execute them
*/
public static interface Master {
/** 'thisObj' will be null if invoked as constructor, in which case
** instance of Scriptable should be returned */
public Object execMethod(int methodId, IdFunction function,
Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
throws JavaScriptException;
/** Get arity or defined argument count for method with given id.
** Should return -1 if methodId is not known or can not be used
** with execMethod call */
public int methodArity(int methodId);
public Scriptable getParentScope();
}
public IdFunction(Master master, String name, int id) {
public IdFunction(IdFunctionMaster master, String name, int id) {
this.master = master;
this.methodName = name;
this.methodId = id;
@ -164,14 +145,6 @@ public class IdFunction extends ScriptableObject implements Function
return getFunctionPrototype(getParentScope());
}
public Scriptable getParentScope() {
Scriptable result = super.getParentScope();
if (result == null) {
result = master.getParentScope();
}
return result;
}
// Copied from NativeFunction
protected Scriptable getClassPrototype() {
Object protoVal = immunePrototypeProperty;
@ -213,7 +186,7 @@ public class IdFunction extends ScriptableObject implements Function
}
}
static RuntimeException onBadMethodId(Master master, int id) {
static RuntimeException onBadMethodId(IdFunctionMaster master, int id) {
// It is program error to call id-like methods for unknown or
// non-function id
return new RuntimeException("BAD FUNCTION ID="+id+" MASTER="+master);
@ -279,7 +252,7 @@ public class IdFunction extends ScriptableObject implements Function
ID_NAME = 3,
ID_PROTOTYPE = 4;
protected /*final*/ Master master;
protected /*final*/ IdFunctionMaster master;
protected /*final*/ int methodId;
protected String methodName;

View File

@ -0,0 +1,54 @@
/* -*- 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 oqr
* 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):
* Igor Bukanov
*
* 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.
*/
package org.mozilla.javascript;
/** Master for id-based functions that knows their properties and how to
** execute them
*/
public interface IdFunctionMaster {
/** 'thisObj' will be null if invoked as constructor, in which case
** instance of Scriptable should be returned */
public Object execMethod(int methodId, IdFunction function,
Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
throws JavaScriptException;
/** Get arity or defined argument count for method with given id.
** Should return -1 if methodId is not known or can not be used
** with execMethod call */
public int methodArity(int methodId);
}

View File

@ -56,7 +56,7 @@ may override scopeInit or fillConstructorProperties methods.
*/
public abstract class IdScriptable extends ScriptableObject
implements IdFunction.Master, ScopeInitializer
implements IdFunctionMaster, ScopeInitializer
{
public boolean has(String name, Scriptable start) {
if (maxId != 0) {
@ -249,7 +249,9 @@ public abstract class IdScriptable extends ScriptableObject
** value in the permanent cache.
*/
protected Object getIdValue(int id, Scriptable start) {
return cacheIdValue(id, newIdFunction(id));
IdFunction f = newIdFunction(id);
f.setParentScope(getParentScope());
return cacheIdValue(id, f);
}
/** Set id value. */

View File

@ -50,7 +50,7 @@ import java.lang.reflect.Method;
* @author Mike Shaver
*/
public class NativeGlobal implements ScopeInitializer, IdFunction.Master {
public class NativeGlobal implements ScopeInitializer, IdFunctionMaster {
public void scopeInit(Context cx, Scriptable scope, boolean sealed) {
@ -151,8 +151,6 @@ public class NativeGlobal implements ScopeInitializer, IdFunction.Master {
return -1;
}
public Scriptable getParentScope() { return null; }
private String getMethodName(int methodId) {
switch (methodId) {
case Id_decodeURI: return "decodeURI";