Skip to content

Commit

Permalink
Making Decompiler.decompile public and changing NativeFunction.getSou…
Browse files Browse the repository at this point in the history
…rceFunction() to return Object so it is easy to implement alternative presentation of encoded source.
  • Loading branch information
ibukanov committed Aug 12, 2003
1 parent 3fa338b commit 66cf82e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 29 deletions.
8 changes: 5 additions & 3 deletions src/org/mozilla/javascript/Decompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,12 @@ private String sourceToString(int offset)
* @param indentGap the identation offset for case labels
*
*/
static String decompile(String source,
boolean justFunctionBody,
int indent, int indentGap, int caseGap)
public static String decompile(Object sourceObj,
boolean justFunctionBody,
int indent, int indentGap, int caseGap)
{
String source = (String)sourceObj;

int length = source.length();
if (length == 0) { return ""; }

Expand Down
2 changes: 1 addition & 1 deletion src/org/mozilla/javascript/InterpretedFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Object call(Context cx, Scriptable scope, Scriptable thisObj,
this, itsData);
}

public String getEncodedSource()
public Object getEncodedSource()
{
return Interpreter.getEncodedSource(itsData);
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/mozilla/javascript/InterpretedScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Object call(Context cx, Scriptable scope,
this, itsData);
}

public String getEncodedSource()
public Object getEncodedSource()
{
return Interpreter.getEncodedSource(itsData);
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/mozilla/javascript/Interpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,7 @@ static int[] getLineNumbers(InterpreterData data) {
return presentLines.getKeys();
}

static String getEncodedSource(InterpreterData idata)
static Object getEncodedSource(InterpreterData idata)
{
if (idata.encodedSource == null) {
return null;
Expand Down
19 changes: 3 additions & 16 deletions src/org/mozilla/javascript/NativeFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class NativeFunction extends BaseFunction
*/
public String decompile(Context cx, int indent, boolean justbody)
{
String encodedSource = getEncodedSource();
Object encodedSource = getEncodedSource();
if (encodedSource == null) {
return super.decompile(cx, indent, justbody);
} else {
Expand Down Expand Up @@ -97,22 +97,9 @@ public String jsGet_name()
/**
* Get encoded source string.
*/
public String getEncodedSource()
public Object getEncodedSource()
{
// The following is used only by optimizer, but is here to avoid
// introduction of 2 additional classes there
Class cl = getClass();
try {
Method m = cl.getDeclaredMethod("getEncodedSourceImpl",
new Class[0]);
return (String)m.invoke(null, ScriptRuntime.emptyArgs);
} catch (NoSuchMethodException ex) {
// No source implementation
return null;
} catch (Exception ex) {
// Wrap the rest of exceptions including possible SecurityException
throw ScriptRuntime.throwAsUncheckedException(ex);
}
return null;
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/org/mozilla/javascript/optimizer/Codegen.java
Original file line number Diff line number Diff line change
Expand Up @@ -729,27 +729,27 @@ private void generateInit(Context cx, String superClassName)
// Change Parser if changing ordering.

if (mainCodegen.encodedSource != null) {
// generate
// public static String getEncodedSourceImpl()
// Override NativeFunction.getEncodedSourceg() with
// public String getEncodedSource()
// {
// return main_class.getEncodedSourceImpl(START, END);
// }
short flags = ClassFileWriter.ACC_PUBLIC
| ClassFileWriter.ACC_STATIC;
String getSourceMethodStr = "getEncodedSourceImpl";
String mainImplSig = "(II)Ljava/lang/String;";
classFile.startMethod(getSourceMethodStr,
"()Ljava/lang/String;",
(short)flags);
classFile.startMethod("getEncodedSource",
"()Ljava/lang/Object;",
ClassFileWriter.ACC_PUBLIC);
push(scriptOrFn.getEncodedSourceStart());
push(scriptOrFn.getEncodedSourceEnd());
classFile.addInvoke(ByteCode.INVOKESTATIC,
mainCodegen.generatedClassName,
getSourceMethodStr,
mainImplSig);
addByteCode(ByteCode.ARETURN);
// 0: no this and no argument
classFile.stopMethod((short)0, null);
// 1: this and no argument or locals
classFile.stopMethod((short)1, null);
if (isMainCodegen) {
// generate
// public static String getEncodedSourceImpl(int start, int end)
Expand Down

0 comments on commit 66cf82e

Please sign in to comment.