kopia lustrzana https://github.com/TeamNewPipe/NewPipeExtractor
Fix compile problems in JavaScript class
rodzic
b376539062
commit
470a719861
|
@ -10,31 +10,25 @@ public final class JavaScript {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void compileOrThrow(final String function) {
|
public static void compileOrThrow(final String function) {
|
||||||
try {
|
try (Context context = Context.enter()) {
|
||||||
final Context context = Context.enter();
|
context.setInterpretedMode(true);
|
||||||
context.setOptimizationLevel(-1);
|
|
||||||
|
|
||||||
// If it doesn't compile it throws an exception here
|
// If it doesn't compile it throws an exception here
|
||||||
context.compileString(function, null, 1, null);
|
context.compileString(function, null, 1, null);
|
||||||
} finally {
|
|
||||||
Context.exit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String run(final String function,
|
public static String run(final String function,
|
||||||
final String functionName,
|
final String functionName,
|
||||||
final String... parameters) {
|
final String... parameters) {
|
||||||
try {
|
try (Context context = Context.enter()) {
|
||||||
final Context context = Context.enter();
|
context.setInterpretedMode(true);
|
||||||
context.setOptimizationLevel(-1);
|
|
||||||
final ScriptableObject scope = context.initSafeStandardObjects();
|
final ScriptableObject scope = context.initSafeStandardObjects();
|
||||||
|
|
||||||
context.evaluateString(scope, function, functionName, 1, null);
|
context.evaluateString(scope, function, functionName, 1, null);
|
||||||
final Function jsFunction = (Function) scope.get(functionName, scope);
|
final Function jsFunction = (Function) scope.get(functionName, scope);
|
||||||
final Object result = jsFunction.call(context, scope, scope, parameters);
|
final Object result = jsFunction.call(context, scope, scope, parameters);
|
||||||
return result.toString();
|
return result.toString();
|
||||||
} finally {
|
|
||||||
Context.exit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue