Java 类org.mozilla.javascript.optimizer.OptFunctionNode 实例源码
项目:rhino-android
文件:Bug782363Test.java
/**
* Checks every variable {@code v} in {@code source} is marked as a
* number-variable iff {@code numbers} contains {@code v}
*/
protected void assertNumberVars(CharSequence source, String... numbers) {
// wrap source in function
ScriptNode tree = compile("function f(){" + source + "}");
FunctionNode fnode = tree.getFunctionNode(0);
assertNotNull(fnode);
OptFunctionNode opt = OptFunctionNode.get(fnode);
assertNotNull(opt);
assertSame(fnode, opt.fnode);
for (int i = 0, c = fnode.getParamCount(); i < c; ++i) {
assertTrue(opt.isParameter(i));
assertFalse(opt.isNumberVar(i));
}
Set<String> set = new HashSet<String>(asList(numbers));
for (int i = fnode.getParamCount(), c = fnode.getParamAndVarCount(); i < c; ++i) {
assertFalse(opt.isParameter(i));
String name = fnode.getParamOrVarName(i);
String msg = format("{%s -> number? = %b}", name, opt.isNumberVar(i));
assertEquals(msg, set.contains(name), opt.isNumberVar(i));
}
}
项目:rhino-android
文件:Bug708801Test.java
/**
* Checks every variable {@code v} in {@code source} is marked as a
* number-variable iff {@code numbers} contains {@code v}
*/
protected void assertNumberVars(CharSequence source, String... numbers) {
// wrap source in function
ScriptNode tree = compile("function f(o, fn){" + source + "}");
FunctionNode fnode = tree.getFunctionNode(0);
assertNotNull(fnode);
OptFunctionNode opt = OptFunctionNode.get(fnode);
assertNotNull(opt);
assertSame(fnode, opt.fnode);
for (int i = 0, c = fnode.getParamCount(); i < c; ++i) {
assertTrue(opt.isParameter(i));
assertFalse(opt.isNumberVar(i));
}
Set<String> set = new HashSet<String>(asList(numbers));
for (int i = fnode.getParamCount(), c = fnode.getParamAndVarCount(); i < c; ++i) {
assertFalse(opt.isParameter(i));
String name = fnode.getParamOrVarName(i);
String msg = format("{%s -> number? = %b}", name, opt.isNumberVar(i));
assertEquals(msg, set.contains(name), opt.isNumberVar(i));
}
}
项目:code404
文件:Bug708801Test.java
/**
* Checks every variable {@code v} in {@code source} is marked as a
* number-variable iff {@code numbers} contains {@code v}
*/
protected void assertNumberVars(CharSequence source, String... numbers) {
// wrap source in function
ScriptNode tree = compile("function f(o, fn){" + source + "}");
FunctionNode fnode = tree.getFunctionNode(0);
assertNotNull(fnode);
OptFunctionNode opt = OptFunctionNode.get(fnode);
assertNotNull(opt);
assertSame(fnode, opt.fnode);
for (int i = 0, c = fnode.getParamCount(); i < c; ++i) {
assertTrue(opt.isParameter(i));
assertFalse(opt.isNumberVar(i));
}
Set<String> set = new HashSet<String>(asList(numbers));
for (int i = fnode.getParamCount(), c = fnode.getParamAndVarCount(); i < c; ++i) {
assertFalse(opt.isParameter(i));
String name = fnode.getParamOrVarName(i);
String msg = format("{%s -> number? = %b}", name, opt.isNumberVar(i));
assertEquals(msg, set.contains(name), opt.isNumberVar(i));
}
}
项目:rhino-jscover
文件:Bug708801Test.java
/**
* Checks every variable {@code v} in {@code source} is marked as a
* number-variable iff {@code numbers} contains {@code v}
*/
protected void assertNumberVars(CharSequence source, String... numbers) {
// wrap source in function
ScriptNode tree = compile("function f(o, fn){" + source + "}");
FunctionNode fnode = tree.getFunctionNode(0);
assertNotNull(fnode);
OptFunctionNode opt = OptFunctionNode.get(fnode);
assertNotNull(opt);
assertSame(fnode, opt.fnode);
for (int i = 0, c = fnode.getParamCount(); i < c; ++i) {
assertTrue(opt.isParameter(i));
assertFalse(opt.isNumberVar(i));
}
Set<String> set = new HashSet<String>(asList(numbers));
for (int i = fnode.getParamCount(), c = fnode.getParamAndVarCount(); i < c; ++i) {
assertFalse(opt.isParameter(i));
String name = fnode.getParamOrVarName(i);
String msg = format("{%s -> number? = %b}", name, opt.isNumberVar(i));
assertEquals(msg, set.contains(name), opt.isNumberVar(i));
}
}
项目:Rhino-Prov-Mod
文件:Bug708801Test.java
/**
* Checks every variable {@code v} in {@code source} is marked as a
* number-variable iff {@code numbers} contains {@code v}
*/
protected void assertNumberVars(CharSequence source, String... numbers) {
// wrap source in function
ScriptNode tree = compile("function f(o, fn){" + source + "}");
FunctionNode fnode = tree.getFunctionNode(0);
assertNotNull(fnode);
OptFunctionNode opt = OptFunctionNode.get(fnode);
assertNotNull(opt);
assertSame(fnode, opt.fnode);
for (int i = 0, c = fnode.getParamCount(); i < c; ++i) {
assertTrue(opt.isParameter(i));
assertFalse(opt.isNumberVar(i));
}
Set<String> set = new HashSet<String>(asList(numbers));
for (int i = fnode.getParamCount(), c = fnode.getParamAndVarCount(); i < c; ++i) {
assertFalse(opt.isParameter(i));
String name = fnode.getParamOrVarName(i);
String msg = format("{%s -> number? = %b}", name, opt.isNumberVar(i));
assertEquals(msg, set.contains(name), opt.isNumberVar(i));
}
}