OLD | NEW |
| (Empty) |
1 # Copyright 2011 the V8 project authors. All rights reserved. | |
2 # Redistribution and use in source and binary forms, with or without | |
3 # modification, are permitted provided that the following conditions are | |
4 # met: | |
5 # | |
6 # * Redistributions of source code must retain the above copyright | |
7 # notice, this list of conditions and the following disclaimer. | |
8 # * Redistributions in binary form must reproduce the above | |
9 # copyright notice, this list of conditions and the following | |
10 # disclaimer in the documentation and/or other materials provided | |
11 # with the distribution. | |
12 # * Neither the name of Google Inc. nor the names of its | |
13 # contributors may be used to endorse or promote products derived | |
14 # from this software without specific prior written permission. | |
15 # | |
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | |
28 # Templatated tests with duplicate parameter names. | |
29 | |
30 # ---------------------------------------------------------------------- | |
31 # Constants and utility functions | |
32 | |
33 # A template that performs the same strict-mode test in different | |
34 # scopes (global scope, function scope, and nested function scope), | |
35 # and in non-strict mode too. | |
36 def DuplicateParameterTest(name, source): | |
37 expectation = "strict_param_dupe" | |
38 non_selfstrict = {"selfstrict":"", "id":"selfnormal"} | |
39 | |
40 Template(name, '"use strict";\n' + source)(non_selfstrict, expectation) | |
41 Template(name + '-infunc', | |
42 'function foo() {\n "use strict";\n' + source +'\n}\n')( | |
43 non_selfstrict, expectation) | |
44 Template(name + '-infunc2', | |
45 'function foo() {\n "use strict";\n function bar() {\n' + | |
46 source +'\n }\n}\n')(non_selfstrict, expectation) | |
47 | |
48 selfstrict = {"selfstrict": "\"use strict\";", "id": "selfstrict"} | |
49 nestedstrict = {"selfstrict": "function bar(){\"use strict\";}", | |
50 "id": "nestedstrict"} | |
51 selfstrictnestedclean = {"selfstrict": """ | |
52 "use strict"; | |
53 function bar(){} | |
54 """, "id": "selfstrictnestedclean"} | |
55 selftest = Template(name + '-$id', source) | |
56 selftest(selfstrict, expectation) | |
57 selftest(selfstrictnestedclean, expectation) | |
58 selftest(nestedstrict, None) | |
59 selftest(non_selfstrict, None) | |
60 | |
61 | |
62 # ---------------------------------------------------------------------- | |
63 # Test templates | |
64 | |
65 DuplicateParameterTest("dups", """ | |
66 function foo(a, a) { $selfstrict } | |
67 """); | |
68 | |
69 DuplicateParameterTest("dups-apart", """ | |
70 function foo(a, b, c, d, e, f, g, h, i, j, k, l, m, n, a) { $selfstrict } | |
71 """); | |
72 | |
73 DuplicateParameterTest("dups-escaped", """ | |
74 function foo(\u0061, b, c, d, e, f, g, h, i, j, k, l, m, n, a) { $selfstrict } | |
75 """); | |
76 | |
77 DuplicateParameterTest("triples", """ | |
78 function foo(a, b, c, d, e, f, g, h, a, i, j, k, l, m, n, a) { $selfstrict } | |
79 """); | |
80 | |
OLD | NEW |