| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
package org.mozilla.javascript; |
| 8 |
|
| 9 |
import org.mozilla.javascript.debug.DebuggableScript; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
public abstract class NativeFunction extends BaseFunction |
| 17 |
{ |
| 18 |
|
| 19 |
static final long serialVersionUID = 8713897114082216401L; |
| 20 |
|
| 21 |
public final void initScriptFunction(Context cx, Scriptable scope) |
| 22 |
{ |
| 23 |
ScriptRuntime.setFunctionProtoAndParent(this, scope); |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
@Override |
| 32 |
final String decompile(int indent, int flags) |
| 33 |
{ |
| 34 |
String encodedSource = getEncodedSource(); |
| 35 |
if (encodedSource == null) { |
| 36 |
return super.decompile(indent, flags); |
| 37 |
} else { |
| 38 |
UintMap properties = new UintMap(1); |
| 39 |
properties.put(Decompiler.INITIAL_INDENT_PROP, indent); |
| 40 |
return Decompiler.decompile(encodedSource, flags, properties); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
@Override |
| 45 |
public int getLength() |
| 46 |
{ |
| 47 |
int paramCount = getParamCount(); |
| 48 |
if (getLanguageVersion() != Context.VERSION_1_2) { |
| 49 |
return paramCount; |
| 50 |
} |
| 51 |
Context cx = Context.getContext(); |
| 52 |
NativeCall activation = ScriptRuntime.findFunctionActivation(cx, this); |
| 53 |
if (activation == null) { |
| 54 |
return paramCount; |
| 55 |
} |
| 56 |
return activation.originalArgs.length; |
| 57 |
} |
| 58 |
|
| 59 |
@Override |
| 60 |
public int getArity() |
| 61 |
{ |
| 62 |
return getParamCount(); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
@Deprecated |
| 71 |
public String jsGet_name() |
| 72 |
{ |
| 73 |
return getFunctionName(); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public String getEncodedSource() |
| 80 |
{ |
| 81 |
return null; |
| 82 |
} |
| 83 |
|
| 84 |
public DebuggableScript getDebuggableView() |
| 85 |
{ |
| 86 |
return null; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
public Object resumeGenerator(Context cx, Scriptable scope, |
| 99 |
int operation, Object state, Object value) |
| 100 |
{ |
| 101 |
throw new EvaluatorException("resumeGenerator() not implemented"); |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
protected abstract int getLanguageVersion(); |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
protected abstract int getParamCount(); |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
protected abstract int getParamAndVarCount(); |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
protected abstract String getParamOrVarName(int index); |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
protected boolean getParamOrVarConst(int index) |
| 132 |
{ |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
return false; |
| 137 |
} |
| 138 |
} |
| 139 |
|