OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 2045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2056 | 2056 |
2057 const char* statement_data[] = { | 2057 const char* statement_data[] = { |
2058 "%someintrinsic(arg)", | 2058 "%someintrinsic(arg)", |
2059 NULL | 2059 NULL |
2060 }; | 2060 }; |
2061 | 2061 |
2062 // Parsing will fail or succeed depending on whether we allow natives syntax | 2062 // Parsing will fail or succeed depending on whether we allow natives syntax |
2063 // or not. | 2063 // or not. |
2064 RunParserSyncTest(context_data, statement_data, kSuccessOrError); | 2064 RunParserSyncTest(context_data, statement_data, kSuccessOrError); |
2065 } | 2065 } |
| 2066 |
| 2067 |
| 2068 TEST(NoErrorsNewExpression) { |
| 2069 const char* context_data[][2] = { |
| 2070 {"", ""}, |
| 2071 {"var f =", ""}, |
| 2072 { NULL, NULL } |
| 2073 }; |
| 2074 |
| 2075 const char* statement_data[] = { |
| 2076 "new foo", |
| 2077 "new foo();", |
| 2078 "new foo(1);", |
| 2079 "new foo(1, 2);", |
| 2080 // The first () will be processed as a part of the NewExpression and the |
| 2081 // second () will be processed as part of LeftHandSideExpression. |
| 2082 "new foo()();", |
| 2083 // The first () will be processed as a part of the inner NewExpression and |
| 2084 // the second () will be processed as a part of the outer NewExpression. |
| 2085 "new new foo()();", |
| 2086 "new foo.bar;", |
| 2087 "new foo.bar();", |
| 2088 "new foo.bar.baz;", |
| 2089 "new foo.bar().baz;", |
| 2090 "new foo[bar];", |
| 2091 "new foo[bar]();", |
| 2092 "new foo[bar][baz];", |
| 2093 "new foo[bar]()[baz];", |
| 2094 "new foo[bar].baz(baz)()[bar].baz;", |
| 2095 "new \"foo\"", // Runtime error |
| 2096 "new 1", // Runtime error |
| 2097 "new foo++", |
| 2098 // This even runs: |
| 2099 "(new new Function(\"this.x = 1\")).x;", |
| 2100 NULL |
| 2101 }; |
| 2102 |
| 2103 RunParserSyncTest(context_data, statement_data, kSuccess); |
| 2104 } |
| 2105 |
| 2106 |
| 2107 TEST(ErrorsNewExpression) { |
| 2108 const char* context_data[][2] = { |
| 2109 {"", ""}, |
| 2110 {"var f =", ""}, |
| 2111 { NULL, NULL } |
| 2112 }; |
| 2113 |
| 2114 const char* statement_data[] = { |
| 2115 "new foo bar", |
| 2116 "new ) foo", |
| 2117 "new ++foo", |
| 2118 NULL |
| 2119 }; |
| 2120 |
| 2121 RunParserSyncTest(context_data, statement_data, kError); |
| 2122 } |
OLD | NEW |