ScriptObject.java
3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.mozilla.javascript.Context
* org.mozilla.javascript.Script
* org.mozilla.javascript.Scriptable
* org.mozilla.javascript.ScriptableObject
* org.mozilla.javascript.debug.DebuggableScript
*/
package com.adobe.xfa.scripthandler.rhino;
import com.adobe.xfa.scripthandler.rhino.RhinoEngine;
import java.util.ArrayList;
import java.util.List;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Script;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.debug.DebuggableScript;
class ScriptObject {
private ScriptableObject moScriptableObj;
private final List<String> mMethods;
private final List<String> mVars;
public ScriptObject(Script oScript) {
assert (oScript != null);
Context context = RhinoEngine.getThreadLocalRuntimeContext();
DebuggableScript view = Context.getDebuggableView((Script)oScript);
this.mVars = new ArrayList<String>();
this.mMethods = new ArrayList<String>();
if (view != null) {
int nVars = view.getParamAndVarCount();
for (int i = 0; i < nVars; ++i) {
String name = view.getParamOrVarName(i);
this.mVars.add(name);
}
int nFuncs = view.getFunctionCount();
for (int i2 = 0; i2 < nFuncs; ++i2) {
DebuggableScript func = view.getFunction(i2);
String name = func.getFunctionName();
this.mMethods.add(name);
}
}
this.compile(context.decompileScript(oScript, 0));
}
private void compile(String sSource) {
boolean bSuccess;
Context context = RhinoEngine.getThreadLocalRuntimeContext();
Scriptable scope = RhinoEngine.getTopLevelScope();
this.moScriptableObj = (ScriptableObject)context.newObject(scope);
boolean bl = bSuccess = this.moScriptableObj != null;
if (!bSuccess) {
return;
}
StringBuilder sBuf = new StringBuilder(sSource);
sBuf.append('\n');
String sThisDot = "this.";
String sEquals = " = ";
String sSemiColon = ";\n";
for (String sName2 : this.mMethods) {
sBuf.append("this.");
sBuf.append(sName2);
sBuf.append(" = ");
sBuf.append(sName2);
sBuf.append(";\n");
}
for (String sName2 : this.mVars) {
sBuf.append("this.");
sBuf.append(sName2);
sBuf.append(" = ");
sBuf.append(sName2);
sBuf.append(";\n");
}
context.evaluateString((Scriptable)this.moScriptableObj, sBuf.toString(), null, 0, (Object)null);
}
public Object get(String name, Scriptable start) {
if (this.mVars.contains(name)) {
return ScriptableObject.getProperty((Scriptable)this.moScriptableObj, (String)name);
}
return Scriptable.NOT_FOUND;
}
public void put(String name, Scriptable start, Object value) {
if (this.mVars.contains(name)) {
ScriptableObject.putProperty((Scriptable)this.moScriptableObj, (String)name, (Object)value);
}
}
}