diff --git a/js/rhino/src/org/mozilla/javascript/BaseFunction.java b/js/rhino/src/org/mozilla/javascript/BaseFunction.java index 045bca0ff54..1306c17bbbd 100644 --- a/js/rhino/src/org/mozilla/javascript/BaseFunction.java +++ b/js/rhino/src/org/mozilla/javascript/BaseFunction.java @@ -51,7 +51,6 @@ public class BaseFunction extends IdScriptableObject implements Function static void init(Context cx, Scriptable scope, boolean sealed) { BaseFunction obj = new BaseFunction(); - obj.functionName = ""; obj.isPrototypePropertyImmune = true; obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed); } @@ -91,7 +90,7 @@ public class BaseFunction extends IdScriptableObject implements Function return ScriptRuntime.jsDelegatesTo(instance, (Scriptable)protoProp); } throw ScriptRuntime.typeError1("msg.instanceof.bad.prototype", - functionName); + getFunctionName()); } // #string_id_map# @@ -263,7 +262,8 @@ public class BaseFunction extends IdScriptableObject implements Function if (x instanceof BaseFunction) { return (BaseFunction)x; } - throw ScriptRuntime.typeError1("msg.incompat.call", f.functionName); + throw ScriptRuntime.typeError1("msg.incompat.call", + f.getFunctionName()); } /** @@ -312,7 +312,7 @@ public class BaseFunction extends IdScriptableObject implements Function // the call method if createObject returns null. throw new IllegalStateException( "Bad implementaion of call as constructor, name=" - +functionName+" in "+getClass().getName()); + +getFunctionName()+" in "+getClass().getName()); } result = (Scriptable)val; if (result.getPrototype() == null) { @@ -385,10 +385,9 @@ public class BaseFunction extends IdScriptableObject implements Function public int getLength() { return 0; } - public String getFunctionName() { - if (functionName == null) - return ""; - return functionName; + public String getFunctionName() + { + return ""; } final Object getPrototypeProperty() { @@ -532,8 +531,6 @@ public class BaseFunction extends IdScriptableObject implements Function // #/string_id_map# - protected String functionName; - private Object prototypeProperty; private boolean isPrototypePropertyImmune; } diff --git a/js/rhino/src/org/mozilla/javascript/FunctionObject.java b/js/rhino/src/org/mozilla/javascript/FunctionObject.java index 4f524071e1b..a8760dfa40c 100644 --- a/js/rhino/src/org/mozilla/javascript/FunctionObject.java +++ b/js/rhino/src/org/mozilla/javascript/FunctionObject.java @@ -259,6 +259,11 @@ public class FunctionObject extends BaseFunction return getArity(); } + public String getFunctionName() + { + return (functionName == null) ? "" : functionName; + } + /** * Get Java method or constructor this function represent. */ @@ -550,6 +555,7 @@ public class FunctionObject extends BaseFunction public static final int JAVA_OBJECT_TYPE = 6; MemberBox member; + private String functionName; private transient byte[] typeTags; private int parmsLength; private transient boolean hasVoidReturn; diff --git a/js/rhino/src/org/mozilla/javascript/IdFunctionObject.java b/js/rhino/src/org/mozilla/javascript/IdFunctionObject.java index a6d5730a02e..0bce806a2de 100644 --- a/js/rhino/src/org/mozilla/javascript/IdFunctionObject.java +++ b/js/rhino/src/org/mozilla/javascript/IdFunctionObject.java @@ -162,6 +162,11 @@ public class IdFunctionObject extends BaseFunction public int getLength() { return getArity(); } + public String getFunctionName() + { + return (functionName == null) ? "" : functionName; + } + public final RuntimeException unknown() { // It is program error to call id-like methods for unknown function @@ -174,4 +179,5 @@ public class IdFunctionObject extends BaseFunction private final int methodId; private int arity; private boolean useCallAsConstructor; + private String functionName; } diff --git a/js/rhino/src/org/mozilla/javascript/InterpretedFunction.java b/js/rhino/src/org/mozilla/javascript/InterpretedFunction.java index 0ab85bfe3e6..430da98f72e 100644 --- a/js/rhino/src/org/mozilla/javascript/InterpretedFunction.java +++ b/js/rhino/src/org/mozilla/javascript/InterpretedFunction.java @@ -84,7 +84,6 @@ final class InterpretedFunction extends NativeFunction implements Script { InterpretedFunction f; f = new InterpretedFunction(idata, staticSecurityDomain); - f.initScriptObject(); return f; } @@ -128,12 +127,17 @@ final class InterpretedFunction extends NativeFunction implements Script private void initInterpretedFunction(Context cx, Scriptable scope) { - initScriptFunction(cx, scope, idata.itsName); + initScriptFunction(cx, scope); if (idata.itsRegExpLiterals != null) { functionRegExps = createRegExpWraps(cx, scope); } } + public String getFunctionName() + { + return (idata.itsName == null) ? "" : idata.itsName; + } + public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { diff --git a/js/rhino/src/org/mozilla/javascript/NativeFunction.java b/js/rhino/src/org/mozilla/javascript/NativeFunction.java index 38b97143091..5957e48dc35 100644 --- a/js/rhino/src/org/mozilla/javascript/NativeFunction.java +++ b/js/rhino/src/org/mozilla/javascript/NativeFunction.java @@ -48,19 +48,11 @@ import org.mozilla.javascript.debug.DebuggableScript; public abstract class NativeFunction extends BaseFunction { - public final void initScriptFunction(Context cx, Scriptable scope, - String functionName) + public final void initScriptFunction(Context cx, Scriptable scope) { - this.functionName = functionName; - ScriptRuntime.setFunctionProtoAndParent(this, scope); } - public final void initScriptObject() - { - this.functionName = ""; - } - /** * @param indent How much to indent the decompiled result * diff --git a/js/rhino/src/org/mozilla/javascript/NativeJavaConstructor.java b/js/rhino/src/org/mozilla/javascript/NativeJavaConstructor.java index 61c334ee11a..b9367b38360 100644 --- a/js/rhino/src/org/mozilla/javascript/NativeJavaConstructor.java +++ b/js/rhino/src/org/mozilla/javascript/NativeJavaConstructor.java @@ -56,11 +56,11 @@ import java.io.*; public class NativeJavaConstructor extends BaseFunction { + MemberBox ctor; + public NativeJavaConstructor(MemberBox ctor) { this.ctor = ctor; - String sig = JavaMembers.liveConnectSignature(ctor.argTypes); - this.functionName = "".concat(sig); } public Object call(Context cx, Scriptable scope, Scriptable thisObj, @@ -69,11 +69,15 @@ public class NativeJavaConstructor extends BaseFunction return NativeJavaClass.constructSpecific(cx, scope, args, ctor); } + public String getFunctionName() + { + String sig = JavaMembers.liveConnectSignature(ctor.argTypes); + return "".concat(sig); + } + public String toString() { return "[JavaConstructor " + ctor.getName() + "]"; } - - MemberBox ctor; } diff --git a/js/rhino/src/org/mozilla/javascript/NativeJavaMethod.java b/js/rhino/src/org/mozilla/javascript/NativeJavaMethod.java index 59c9ea3ba6a..e40cf8db842 100644 --- a/js/rhino/src/org/mozilla/javascript/NativeJavaMethod.java +++ b/js/rhino/src/org/mozilla/javascript/NativeJavaMethod.java @@ -70,6 +70,11 @@ public class NativeJavaMethod extends BaseFunction this(new MemberBox(method, null), name); } + public String getFunctionName() + { + return functionName; + } + static String scriptSignature(Object[] values) { StringBuffer sig = new StringBuffer(); @@ -148,7 +153,7 @@ public class NativeJavaMethod extends BaseFunction int index = findFunction(cx, methods, args); if (index < 0) { Class c = methods[0].method().getDeclaringClass(); - String sig = c.getName() + '.' + functionName + '(' + + String sig = c.getName() + '.' + getFunctionName() + '(' + scriptSignature(args) + ')'; throw Context.reportRuntimeError1("msg.java.no_such_method", sig); } @@ -177,7 +182,7 @@ public class NativeJavaMethod extends BaseFunction for (;;) { if (o == null) { throw Context.reportRuntimeError3( - "msg.nonjava.method", functionName, + "msg.nonjava.method", getFunctionName(), ScriptRuntime.toString(thisObj), c.getName()); } if (o instanceof Wrapper) { @@ -467,5 +472,6 @@ public class NativeJavaMethod extends BaseFunction } MemberBox[] methods; + private String functionName; } diff --git a/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java b/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java index 32de94d6f5a..dde70f96ad3 100644 --- a/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java +++ b/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java @@ -3034,7 +3034,7 @@ public class ScriptRuntime { boolean fromEvalCode) { if (type == FunctionNode.FUNCTION_STATEMENT) { - String name = function.functionName; + String name = function.getFunctionName(); if (name != null && name.length() != 0) { if (!fromEvalCode) { // ECMA specifies that functions defined in global and @@ -3046,7 +3046,7 @@ public class ScriptRuntime { } } } else if (type == FunctionNode.FUNCTION_EXPRESSION_STATEMENT) { - String name = function.functionName; + String name = function.getFunctionName(); if (name != null && name.length() != 0) { // Always put function expression statements into initial // activation object ignoring the with statement to follow diff --git a/js/rhino/src/org/mozilla/javascript/optimizer/Codegen.java b/js/rhino/src/org/mozilla/javascript/optimizer/Codegen.java index ac2a6e9ea58..7e3c8529edc 100644 --- a/js/rhino/src/org/mozilla/javascript/optimizer/Codegen.java +++ b/js/rhino/src/org/mozilla/javascript/optimizer/Codegen.java @@ -553,13 +553,6 @@ public class Codegen extends Interpreter cfw.addPush(0); cfw.add(ByteCode.PUTFIELD, cfw.getClassName(), ID_FIELD_NAME, "I"); - // Call - // NativeFunction.initScriptObject(version, varNamesArray) - cfw.addLoadThis(); - cfw.addInvoke(ByteCode.INVOKEVIRTUAL, - "org/mozilla/javascript/NativeFunction", - "initScriptObject", "()V"); - cfw.add(ByteCode.RETURN); // 1 parameter = this cfw.stopMethod((short)1); @@ -635,13 +628,11 @@ public class Codegen extends Interpreter cfw.addLoadThis(); cfw.addALoad(CONTEXT_ARG); cfw.addALoad(SCOPE_ARG); - cfw.addPush(ofn.fnode.getFunctionName()); cfw.addInvoke(ByteCode.INVOKEVIRTUAL, "org/mozilla/javascript/NativeFunction", "initScriptFunction", "(Lorg/mozilla/javascript/Context;" +"Lorg/mozilla/javascript/Scriptable;" - +"Ljava/lang/String;" +")V"); // precompile all regexp literals @@ -676,11 +667,12 @@ public class Codegen extends Interpreter // The rest of NativeFunction overrides require specific code for each // script/function id - final int Do_getParamCount = 0; - final int Do_getParamAndVarCount = 1; - final int Do_getParamOrVarName = 2; - final int Do_getEncodedSource = 3; - final int SWITCH_COUNT = 4; + final int Do_getFunctionName = 0; + final int Do_getParamCount = 1; + final int Do_getParamAndVarCount = 2; + final int Do_getParamOrVarName = 3; + final int Do_getEncodedSource = 4; + final int SWITCH_COUNT = 5; for (int methodIndex = 0; methodIndex != SWITCH_COUNT; ++methodIndex) { if (methodIndex == Do_getEncodedSource && encodedSource == null) { @@ -694,6 +686,11 @@ public class Codegen extends Interpreter short metodLocals; switch (methodIndex) { + case Do_getFunctionName: + metodLocals = 1; // Only this + cfw.startMethod("getFunctionName", "()Ljava/lang/String;", + ClassFileWriter.ACC_PUBLIC); + break; case Do_getParamCount: metodLocals = 1; // Only this cfw.startMethod("getParamCount", "()I", @@ -748,6 +745,17 @@ public class Codegen extends Interpreter // Impelemnet method-specific switch code switch (methodIndex) { + case Do_getFunctionName: + // Push function name + if (n.getType() == Token.SCRIPT) { + cfw.addPush(""); + } else { + String name = ((FunctionNode)n).getFunctionName(); + cfw.addPush(name); + } + cfw.add(ByteCode.ARETURN); + break; + case Do_getParamCount: // Push number of defined parameters cfw.addPush(n.getParamCount()); diff --git a/js/rhino/src/org/mozilla/javascript/regexp/NativeRegExpCtor.java b/js/rhino/src/org/mozilla/javascript/regexp/NativeRegExpCtor.java index b77525b536b..4a3efd0c07c 100644 --- a/js/rhino/src/org/mozilla/javascript/regexp/NativeRegExpCtor.java +++ b/js/rhino/src/org/mozilla/javascript/regexp/NativeRegExpCtor.java @@ -57,7 +57,11 @@ class NativeRegExpCtor extends BaseFunction { NativeRegExpCtor() { - functionName = "RegExp"; + } + + public String getFunctionName() + { + return "RegExp"; } public Object call(Context cx, Scriptable scope, Scriptable thisObj,