From 22fdd1cdbbce96ba5d72fcdc4c77170d214fecf4 Mon Sep 17 00:00:00 2001 From: "mikhail.naganov@gmail.com" Date: Fri, 29 Apr 2011 20:59:29 +0000 Subject: [PATCH] Add some more (failing) tests for function names inference. After the "Naming Anonymous JavaScript Functions" paper by S. M. Ecole, J. J. Barton, C. Petitpierre. TBR=yurys@chromium.org BUG=1354 TEST=test-func-name-inference/* Review URL: http://codereview.chromium.org/6893135 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7733 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- test/cctest/cctest.status | 11 +++-- test/cctest/test-func-name-inference.cc | 71 +++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/test/cctest/cctest.status b/test/cctest/cctest.status index bf62520..d4050c2 100644 --- a/test/cctest/cctest.status +++ b/test/cctest/cctest.status @@ -42,6 +42,14 @@ test-serialize/TestThatAlwaysFails: FAIL test-serialize/DependentTestThatAlwaysFails: FAIL ############################################################################## +# BUG(1354): Bad function name inference +test-func-name-inference/FactoryHashmapConditional: FAIL +test-func-name-inference/FactoryHashmapVariable: FAIL +test-func-name-inference/FactoryHashmap: FAIL +test-func-name-inference/MultipleAssignments: FAIL +test-func-name-inference/PassedAsConstructorParameter: FAIL + +############################################################################## [ $arch == arm ] # We cannot assume that we can throw OutOfMemory exceptions in all situations. @@ -95,6 +103,3 @@ test-sockets: SKIP test-strings: SKIP test-threads: SKIP test-thread-termination: SKIP - -############################################################################## -# Tests that time out with Isolates diff --git a/test/cctest/test-func-name-inference.cc b/test/cctest/test-func-name-inference.cc index dea5c47..80f9bd1 100644 --- a/test/cctest/test-func-name-inference.cc +++ b/test/cctest/test-func-name-inference.cc @@ -281,3 +281,74 @@ TEST(Issue380) { "}"); CheckFunctionName(script, "return p", ""); } + + +TEST(MultipleAssignments) { + InitializeVM(); + v8::HandleScope scope; + + v8::Handle script = Compile( + "var fun1 = fun2 = function () { return 1; }"); + CheckFunctionName(script, "return 1", "fun2"); +} + + +TEST(PassedAsConstructorParameter) { + InitializeVM(); + v8::HandleScope scope; + + v8::Handle script = Compile( + "function Foo() {}\n" + "var foo = new Foo(function() { return 1; })"); + CheckFunctionName(script, "return 1", ""); +} + + +TEST(FactoryHashmap) { + InitializeVM(); + v8::HandleScope scope; + + v8::Handle script = Compile( + "function createMyObj() {\n" + " var obj = {};\n" + " obj[\"method1\"] = function() { return 1; }\n" + " obj[\"method2\"] = function() { return 2; }\n" + " return obj;\n" + "}"); + CheckFunctionName(script, "return 1", "obj.method1"); + CheckFunctionName(script, "return 2", "obj.method2"); +} + + +TEST(FactoryHashmapVariable) { + InitializeVM(); + v8::HandleScope scope; + + v8::Handle script = Compile( + "function createMyObj() {\n" + " var obj = {};\n" + " var methodName = \"method1\";\n" + " obj[methodName] = function() { return 1; }\n" + " methodName = \"method2\";\n" + " obj[methodName] = function() { return 2; }\n" + " return obj;\n" + "}"); + // Can't infer function names statically. + CheckFunctionName(script, "return 1", "obj.(anonymous function)"); + CheckFunctionName(script, "return 2", "obj.(anonymous function)"); +} + + +TEST(FactoryHashmapConditional) { + InitializeVM(); + v8::HandleScope scope; + + v8::Handle script = Compile( + "function createMyObj() {\n" + " var obj = {};\n" + " obj[0 ? \"method1\" : \"method2\"] = function() { return 1; }\n" + " return obj;\n" + "}"); + // Can't infer the function name statically. + CheckFunctionName(script, "return 1", "obj.(anonymous function)"); +} -- 2.7.4