Created
January 8, 2018 18:47
-
-
Save sainaen/df76b0e7e91b17ffdaa11c4f8eda3195 to your computer and use it in GitHub Desktop.
Source JS code from https://github.com/mozilla/rhino/issues/379 and it's compiled by Rhino version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Source code recreated from a .class file by IntelliJ IDEA | |
// (powered by Fernflower decompiler) | |
// | |
import org.mozilla.javascript.Callable; | |
import org.mozilla.javascript.Context; | |
import org.mozilla.javascript.NativeFunction; | |
import org.mozilla.javascript.Script; | |
import org.mozilla.javascript.ScriptRuntime; | |
import org.mozilla.javascript.Scriptable; | |
import org.mozilla.javascript.Undefined; | |
import org.mozilla.javascript.optimizer.OptRuntime; | |
public class SourceScript extends NativeFunction implements Script { | |
private static Integer _k0 = 10; | |
private static Integer _k1 = 8; | |
private int _id; | |
public SourceScript(Scriptable var1, Context var2, int var3) { | |
this._id = var3; | |
switch (var3) { | |
case 2: | |
this._i2(var2, var1); | |
return; | |
case 3: | |
this._i3(var2, var1); | |
return; | |
default: | |
this._i1(var2, var1); | |
} | |
} | |
public SourceScript() { | |
this._id = 0; | |
} | |
public final Object exec(Context var1, Scriptable var2) { | |
return this.call(var1, var2, var2, (Object[]) null); | |
} | |
public final Object call(Context var1, Scriptable var2, Scriptable var3, Object[] var4) { | |
if (!ScriptRuntime.hasTopCall(var1)) { | |
return ScriptRuntime.doTopCall(this, var1, var2, var3, var4, false); | |
} else { | |
switch (this._id) { | |
case 1: | |
return ip2long_1(this, var1, var2, var3, var4); | |
case 2: | |
return ip2long_2(this, var1, var2, var3, var4); | |
case 3: | |
return callback(this, var1, var2, var3, var4); | |
default: | |
return _c_script_0(this, var1, var2, var3, var4); | |
} | |
} | |
} | |
public int getLanguageVersion() { | |
return 200; | |
} | |
public String getFunctionName() { | |
switch (this._id) { | |
case 1: | |
return "ip2long_1"; | |
case 2: | |
return "ip2long_2"; | |
case 3: | |
return ""; | |
default: | |
return ""; | |
} | |
} | |
public int getParamCount() { | |
switch (this._id) { | |
case 1: | |
return 1; | |
case 2: | |
return 1; | |
case 3: | |
return 2; | |
default: | |
return 0; | |
} | |
} | |
public int getParamAndVarCount() { | |
switch (this._id) { | |
case 1: | |
return 4; | |
case 2: | |
return 1; | |
case 3: | |
return 2; | |
default: | |
return 2; | |
} | |
} | |
public String getParamOrVarName(int var1) { | |
switch (this._id) { | |
case 1: | |
switch (var1) { | |
case 1: | |
return "items"; | |
case 2: | |
return "result"; | |
case 3: | |
return "i"; | |
default: | |
return "ipstr"; | |
} | |
case 2: | |
return "ipstr"; | |
case 3: | |
switch (var1) { | |
case 1: | |
return "octet"; | |
default: | |
return "ipInt"; | |
} | |
default: | |
switch (var1) { | |
case 1: | |
return "ip2long_2"; | |
default: | |
return "ip2long_1"; | |
} | |
} | |
} | |
public String getEncodedSource() { | |
switch (this._id) { | |
case 1: | |
return "\u0089n\u0001'\tip2long_1X'\u0005ipstrYV\u0001{'\u0005items['\u0005ipstrm'\u0005splitX)\u0001.YS\u0001{'\u0006result[(S\u0000S\u0001xX{'\u0001i[(S\u0000S'\u0001i\u000e'\u0005itemsm'\u0006lengthS'\u0001ikYV\u0001'\u0006result[X'\u0006result\u0012(S\bY\u0015'\bparseIntX'\u0005itemsT'\u0001iUZ(S\nYS\u0001W\u0001\u0004'\u0006result\u0014(S\u0000S\u0001W§\u0001n\u0001'\tip2long_2X'\u0005ipstrYV\u0001\u0004'\u0005ipstrm'\u0005splitX)\u0001.Ym'\u0006reduceXn\u0002X'\u0005ipIntZ'\u0005octetYV\u0001\u0004X'\u0005ipInt\u0012(S\bY\u0015'\bparseIntX'\u0005octetZ(S\nYS\u0001W§Z(S\u0000Y\u0014(S\u0000S\u0001W§\u0001'\u0005printX'\tip2long_1X)\t127.0.0.1YYS\u0001'\u0005printX'\tip2long_2X)\t127.0.0.1YYS\u0001".substring(1, 182); | |
case 2: | |
return "\u0089n\u0001'\tip2long_1X'\u0005ipstrYV\u0001{'\u0005items['\u0005ipstrm'\u0005splitX)\u0001.YS\u0001{'\u0006result[(S\u0000S\u0001xX{'\u0001i[(S\u0000S'\u0001i\u000e'\u0005itemsm'\u0006lengthS'\u0001ikYV\u0001'\u0006result[X'\u0006result\u0012(S\bY\u0015'\bparseIntX'\u0005itemsT'\u0001iUZ(S\nYS\u0001W\u0001\u0004'\u0006result\u0014(S\u0000S\u0001W§\u0001n\u0001'\tip2long_2X'\u0005ipstrYV\u0001\u0004'\u0005ipstrm'\u0005splitX)\u0001.Ym'\u0006reduceXn\u0002X'\u0005ipIntZ'\u0005octetYV\u0001\u0004X'\u0005ipInt\u0012(S\bY\u0015'\bparseIntX'\u0005octetZ(S\nYS\u0001W§Z(S\u0000Y\u0014(S\u0000S\u0001W§\u0001'\u0005printX'\tip2long_1X)\t127.0.0.1YYS\u0001'\u0005printX'\tip2long_2X)\t127.0.0.1YYS\u0001".substring(184, 314); | |
case 3: | |
return "\u0089n\u0001'\tip2long_1X'\u0005ipstrYV\u0001{'\u0005items['\u0005ipstrm'\u0005splitX)\u0001.YS\u0001{'\u0006result[(S\u0000S\u0001xX{'\u0001i[(S\u0000S'\u0001i\u000e'\u0005itemsm'\u0006lengthS'\u0001ikYV\u0001'\u0006result[X'\u0006result\u0012(S\bY\u0015'\bparseIntX'\u0005itemsT'\u0001iUZ(S\nYS\u0001W\u0001\u0004'\u0006result\u0014(S\u0000S\u0001W§\u0001n\u0001'\tip2long_2X'\u0005ipstrYV\u0001\u0004'\u0005ipstrm'\u0005splitX)\u0001.Ym'\u0006reduceXn\u0002X'\u0005ipIntZ'\u0005octetYV\u0001\u0004X'\u0005ipInt\u0012(S\bY\u0015'\bparseIntX'\u0005octetZ(S\nYS\u0001W§Z(S\u0000Y\u0014(S\u0000S\u0001W§\u0001'\u0005printX'\tip2long_1X)\t127.0.0.1YYS\u0001'\u0005printX'\tip2long_2X)\t127.0.0.1YYS\u0001".substring(239, 301); | |
default: | |
return "\u0089n\u0001'\tip2long_1X'\u0005ipstrYV\u0001{'\u0005items['\u0005ipstrm'\u0005splitX)\u0001.YS\u0001{'\u0006result[(S\u0000S\u0001xX{'\u0001i[(S\u0000S'\u0001i\u000e'\u0005itemsm'\u0006lengthS'\u0001ikYV\u0001'\u0006result[X'\u0006result\u0012(S\bY\u0015'\bparseIntX'\u0005itemsT'\u0001iUZ(S\nYS\u0001W\u0001\u0004'\u0006result\u0014(S\u0000S\u0001W§\u0001n\u0001'\tip2long_2X'\u0005ipstrYV\u0001\u0004'\u0005ipstrm'\u0005splitX)\u0001.Ym'\u0006reduceXn\u0002X'\u0005ipIntZ'\u0005octetYV\u0001\u0004X'\u0005ipInt\u0012(S\bY\u0015'\bparseIntX'\u0005octetZ(S\nYS\u0001W§Z(S\u0000Y\u0014(S\u0000S\u0001W§\u0001'\u0005printX'\tip2long_1X)\t127.0.0.1YYS\u0001'\u0005printX'\tip2long_2X)\t127.0.0.1YYS\u0001".substring(0, 386); | |
} | |
} | |
public boolean getParamOrVarConst(int var1) { | |
switch (this._id) { | |
case 1: | |
switch (var1) { | |
case 1: | |
return false; | |
case 2: | |
return false; | |
case 3: | |
return false; | |
default: | |
return false; | |
} | |
case 2: | |
return false; | |
case 3: | |
switch (var1) { | |
case 1: | |
return false; | |
default: | |
return false; | |
} | |
default: | |
switch (var1) { | |
case 1: | |
return false; | |
default: | |
return false; | |
} | |
} | |
} | |
private final void _i1(Context var1, Scriptable var2) { | |
this.initScriptFunction(var1, var2); | |
} | |
private final void _i2(Context var1, Scriptable var2) { | |
this.initScriptFunction(var1, var2); | |
} | |
private final void _i3(Context var1, Scriptable var2) { | |
this.initScriptFunction(var1, var2); | |
} | |
public static void main(String[] var0) { | |
OptRuntime.main(new SourceScript(), var0); | |
} | |
private static Object _c_script_0(SourceScript var0, Context var1, Scriptable global, Scriptable var3, Object[] var4) { | |
ScriptRuntime.initScript(var0, var3, var1, global, false); | |
OptRuntime.initFunction(new SourceScript(global, var1, 1), 1, global, var1); | |
OptRuntime.initFunction(new SourceScript(global, var1, 2), 1, global, var1); | |
Object var5 = Undefined.instance; | |
OptRuntime.callName(new Object[]{OptRuntime.callName(new Object[]{"127.0.0.1"}, "ip2long_1", var1, global)}, "print", var1, global); | |
var5 = OptRuntime.callName(new Object[]{OptRuntime.callName(new Object[]{"127.0.0.1"}, "ip2long_2", var1, global)}, "print", var1, global); | |
return var5; | |
} | |
private static Object ip2long_1(SourceScript script, Context cx, Scriptable scope, Scriptable var3, Object[] args) { | |
scope = script.getParentScope(); | |
if (args.length < 1) { | |
args = ScriptRuntime.padArguments(args, 1); | |
} | |
Object ipstr = args[0]; | |
Callable split = ScriptRuntime.getPropFunctionAndThis(ipstr, "split", cx, scope); | |
// `items = ipstr.split('.')` | |
Object items = OptRuntime.call1(split, ScriptRuntime.lastStoredScriptable(cx), ".", cx, scope); | |
Object result = OptRuntime.zeroObj; | |
double i = 0.0; | |
for (i = 0.0D; i < ScriptRuntime.toNumber(ScriptRuntime.getObjectProp(items, "length", cx, scope)); ++i) { | |
// `result << 8` | |
double prev = (ScriptRuntime.toInt32(ScriptRuntime.toNumber(result)) << ScriptRuntime.toInt32(8.0D)); | |
// `items[i]` | |
Object itemsElem = ScriptRuntime.getObjectIndex(items, i, cx); | |
// `parseInt(items[i], 10)` | |
Object next = OptRuntime.callName(new Object[]{itemsElem, _k0}, "parseInt", cx, scope); | |
// add and store in `result` | |
result = OptRuntime.add(prev, next); | |
} | |
// final `>>> 0` | |
return OptRuntime.wrapDouble((double) (ScriptRuntime.toUint32(result) >>> (ScriptRuntime.toInt32(OptRuntime.zeroObj) & 31))); | |
} | |
private static Object ip2long_2(SourceScript script, Context cx, Scriptable activation, Scriptable var3, Object[] args) { | |
activation = script.getParentScope(); | |
activation = ScriptRuntime.createFunctionActivation(script, activation, args, false); | |
ScriptRuntime.enterActivationFunction(cx, activation); | |
Double var10000; | |
try { | |
// find the `ipstr` in the scope | |
Object ipstr = ScriptRuntime.name(cx, activation, "ipstr"); | |
Callable split = ScriptRuntime.getPropFunctionAndThis(ipstr, "split", cx, activation); | |
Scriptable thisObj_ipstr = ScriptRuntime.lastStoredScriptable(cx); | |
// result of calling `ipstr.split('.')` | |
Object items = OptRuntime.call1(split, thisObj_ipstr, ".", cx, activation); | |
Callable reduce = ScriptRuntime.getPropFunctionAndThis(items, "reduce", cx, activation); | |
Scriptable thisObj_items = ScriptRuntime.lastStoredScriptable(cx); | |
Object result = OptRuntime.call2( | |
reduce, // fn to call | |
thisObj_items, // this | |
new SourceScript(activation, cx, 3), // arg #1: a callback | |
OptRuntime.zeroObj, // arg #2: `0` | |
cx, // context | |
activation // scope | |
); | |
// final `>>> 0` | |
var10000 = OptRuntime.wrapDouble((double) (ScriptRuntime.toUint32(result) >>> (ScriptRuntime.toInt32(OptRuntime.zeroObj) & 31))); | |
} finally { | |
ScriptRuntime.exitActivationFunction(cx); | |
} | |
return var10000; | |
} | |
private static Object callback(SourceScript script, Context cx, Scriptable scope, Scriptable var3, Object[] args) { | |
scope = script.getParentScope(); | |
if (args.length < 2) { | |
args = ScriptRuntime.padArguments(args, 2); | |
} | |
Object ipInt = args[0]; | |
Object octet = args[1]; | |
// `ipInt << 8` | |
Double result = OptRuntime.wrapDouble((double) (ScriptRuntime.toInt32(ipInt) << ScriptRuntime.toInt32(_k1))); | |
// `parseInt(octet, 10)` | |
Object parseInt_result = OptRuntime.callName(new Object[]{octet, _k0}, "parseInt", cx, scope); | |
// add and return | |
return ScriptRuntime.add(result, parseInt_result, cx); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ip2long_1(ipstr) { | |
var items = ipstr.split('.') | |
var result = 0 | |
for (var i = 0; i < items.length; i ++) { | |
result = (result << 8) + parseInt(items[i], 10) | |
} | |
return result >>> 0 | |
} | |
function ip2long_2(ipstr) { | |
return ipstr.split('.').reduce(function(ipInt, octet) { return (ipInt<<8) + parseInt(octet, 10)}, 0) >>> 0; | |
} | |
print(ip2long_2('127.0.0.1')); | |
print(ip2long_1('127.0.0.1')); | |
// to generate Java bytecode | |
// $ java -classpath rhino-1.7.8-SNAPSHOT.jar org.mozilla.javascript.tools.jsc.Main -version 200 -opt 9 -debug SourceScript.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment