Java引用javascript中的function时btoa函数报错
Java code:
String jsFileName = "D:\\parseSc.js";
log.debug(jsFileName);
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("javascript");
FileReader reader = new FileReader(jsFileName);
engine.eval(reader);
if(engine instanceof Invocable) {
Invocable invoke = (Invocable)engine;
// 调用weorjjigh方法,并传入参数
Object result = invoke.invokeFunction("weorjjigh", video_page_url);
try {
invoke.invokeFunction("noweorjjigh");
} catch (NoSuchMethodException e) {
// expected
}
}
reader.close();
js code:
var u = {};
u.cache = btoa(c - v + "");
a(n, t);
var d = function(e) {
var a = [], n = 0;
for (; n < 64; ) {
a[n] = 0 | Math.abs(Math.sin(++n)) * 4294967296
}
报错:Exception in thread "main" javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "btoa" is not defined. (<Unknown source>#38) in <Unknown source> at line number 38