From 8ef49d0abb48ba0447350402a525d1009a5633aa Mon Sep 17 00:00:00 2001 From: "nboyd%atg.com" Date: Sat, 12 May 2001 13:15:39 +0000 Subject: [PATCH] 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 --- .../org/mozilla/javascript/IdFunction.java | 33 ++---------- .../mozilla/javascript/IdFunctionMaster.java | 54 +++++++++++++++++++ .../org/mozilla/javascript/IdScriptable.java | 6 ++- .../org/mozilla/javascript/NativeGlobal.java | 4 +- 4 files changed, 62 insertions(+), 35 deletions(-) create mode 100644 js/rhino/src/org/mozilla/javascript/IdFunctionMaster.java diff --git a/js/rhino/src/org/mozilla/javascript/IdFunction.java b/js/rhino/src/org/mozilla/javascript/IdFunction.java index 4cbe08e621f6..d02c6e6569d4 100644 --- a/js/rhino/src/org/mozilla/javascript/IdFunction.java +++ b/js/rhino/src/org/mozilla/javascript/IdFunction.java @@ -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; diff --git a/js/rhino/src/org/mozilla/javascript/IdFunctionMaster.java b/js/rhino/src/org/mozilla/javascript/IdFunctionMaster.java new file mode 100644 index 000000000000..b1deeb602a62 --- /dev/null +++ b/js/rhino/src/org/mozilla/javascript/IdFunctionMaster.java @@ -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); +} + diff --git a/js/rhino/src/org/mozilla/javascript/IdScriptable.java b/js/rhino/src/org/mozilla/javascript/IdScriptable.java index 2a7c85eae9f7..a563a22147ff 100644 --- a/js/rhino/src/org/mozilla/javascript/IdScriptable.java +++ b/js/rhino/src/org/mozilla/javascript/IdScriptable.java @@ -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. */ diff --git a/js/rhino/src/org/mozilla/javascript/NativeGlobal.java b/js/rhino/src/org/mozilla/javascript/NativeGlobal.java index fae6a8524c80..d37be3bdeea6 100644 --- a/js/rhino/src/org/mozilla/javascript/NativeGlobal.java +++ b/js/rhino/src/org/mozilla/javascript/NativeGlobal.java @@ -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";