From 610c7e252e0a9fca4beebc9101cc118a240b7bb8 Mon Sep 17 00:00:00 2001 From: msridhar1 Date: Fri, 6 Jan 2012 21:27:21 +0000 Subject: [PATCH] add a test for Function.apply() with the arguments array git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4336 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../examples-src/tests/function_apply.js | 4 +++- .../examples-src/tests/function_apply2.js | 9 +++++++++ .../wala/cast/js/test/TestSimpleCallGraphShape.java | 10 ++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 com.ibm.wala.cast.js.test/examples-src/tests/function_apply2.js diff --git a/com.ibm.wala.cast.js.test/examples-src/tests/function_apply.js b/com.ibm.wala.cast.js.test/examples-src/tests/function_apply.js index 2c654bc7a..c72ab32e3 100644 --- a/com.ibm.wala.cast.js.test/examples-src/tests/function_apply.js +++ b/com.ibm.wala.cast.js.test/examples-src/tests/function_apply.js @@ -3,7 +3,7 @@ function biz() { return this; } var q = biz; var o = { m: function theOne() {} } var r = q.apply(o); -o.m() +r.m() function id(y) { return y; } @@ -14,3 +14,5 @@ s(); // test invoking with non-array argsList p.apply(null, o); + + diff --git a/com.ibm.wala.cast.js.test/examples-src/tests/function_apply2.js b/com.ibm.wala.cast.js.test/examples-src/tests/function_apply2.js new file mode 100644 index 000000000..3247ae443 --- /dev/null +++ b/com.ibm.wala.cast.js.test/examples-src/tests/function_apply2.js @@ -0,0 +1,9 @@ +// test use of arguments array +function useArgs() { + return arguments[2]; +} +var o = {} +function theThree() {} +var a = useArgs; +var b = a.apply(o, [o,o,theThree]); +b(); \ No newline at end of file diff --git a/com.ibm.wala.cast.js.test/harness-src/com/ibm/wala/cast/js/test/TestSimpleCallGraphShape.java b/com.ibm.wala.cast.js.test/harness-src/com/ibm/wala/cast/js/test/TestSimpleCallGraphShape.java index 54b881c19..b4c9c9174 100644 --- a/com.ibm.wala.cast.js.test/harness-src/com/ibm/wala/cast/js/test/TestSimpleCallGraphShape.java +++ b/com.ibm.wala.cast.js.test/harness-src/com/ibm/wala/cast/js/test/TestSimpleCallGraphShape.java @@ -328,6 +328,16 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape { verifyGraphAssertions(CG, assertionsForFunctionApply); } + private static final Object[][] assertionsForFunctionApply2 = new Object[][] { + new Object[] { ROOT, new String[] { "tests/function_apply2.js" } }, + new Object[] { "suffix:function_apply2.js", new String[] { "suffix:theThree" } } }; + + @Test + public void testFunctionDotApply2() throws IOException, IllegalArgumentException, CancelException { + CallGraph CG = Util.makeScriptCG("tests", "function_apply2.js"); + verifyGraphAssertions(CG, assertionsForFunctionApply2); + } + private static final Object[][] assertionsForComplexCall = new Object[][] { new Object[] { ROOT, new String[] { "tests/complex_call.js" } }, new Object[] { "suffix:call.js", new String[] { "suffix:f3" } } };