Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: test/cctest/test-parsing.cc

Issue 173273006: Unify (Pre)Parser::ParseObjectLiteral and add tests. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/preparser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1900 matching lines...) Expand 10 before | Expand all | Expand 10 after
1911 }; 1911 };
1912 1912
1913 RunParserSyncTest(context_data, statement_data, kSuccess); 1913 RunParserSyncTest(context_data, statement_data, kSuccess);
1914 } 1914 }
1915 1915
1916 1916
1917 TEST(DontRegressPreParserDataSizes) { 1917 TEST(DontRegressPreParserDataSizes) {
1918 // These tests make sure that PreParser doesn't start producing less data. 1918 // These tests make sure that PreParser doesn't start producing less data.
1919 1919
1920 v8::V8::Initialize(); 1920 v8::V8::Initialize();
1921
1922 int marker; 1921 int marker;
1923 CcTest::i_isolate()->stack_guard()->SetStackLimit( 1922 CcTest::i_isolate()->stack_guard()->SetStackLimit(
1924 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 1923 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
1925 1924
1926 struct TestCase { 1925 struct TestCase {
1927 const char* program; 1926 const char* program;
1928 int symbols; 1927 int symbols;
1929 int functions; 1928 int functions;
1930 } test_cases[] = { 1929 } test_cases[] = {
1931 // Labels, variables and functions are recorded as symbols. 1930 // Labels and variables are recorded as symbols.
1932 {"{label: 42}", 1, 0}, {"{label: 42; label2: 43}", 2, 0}, 1931 {"{label: 42}", 1, 0}, {"{label: 42; label2: 43}", 2, 0},
1933 {"var x = 42;", 1, 0}, {"var x = 42, y = 43;", 2, 0}, 1932 {"var x = 42;", 1, 0}, {"var x = 42, y = 43;", 2, 0},
1933 {"var x = {y: 1};", 2, 0},
1934 {"var x = {}; x.y = 1", 2, 0},
1935 // "get" is recorded as a symbol too.
1936 {"var x = {get foo(){} };", 3, 1},
1937 // When keywords are used as identifiers, they're logged as symbols, too:
1938 {"var x = {if: 1};", 2, 0},
1939 {"var x = {}; x.if = 1", 2, 0},
1940 {"var x = {get if(){} };", 3, 1},
1941 // Functions
1934 {"function foo() {}", 1, 1}, {"function foo() {} function bar() {}", 2, 2}, 1942 {"function foo() {}", 1, 1}, {"function foo() {} function bar() {}", 2, 2},
1935 // Labels, variables and functions insize lazy functions are not recorded. 1943 // Labels, variables and functions insize lazy functions are not recorded.
1936 {"function lazy() { var a, b, c; }", 1, 1}, 1944 {"function lazy() { var a, b, c; }", 1, 1},
1937 {"function lazy() { a: 1; b: 2; c: 3; }", 1, 1}, 1945 {"function lazy() { a: 1; b: 2; c: 3; }", 1, 1},
1938 {"function lazy() { function a() {} function b() {} function c() {} }", 1, 1946 {"function lazy() { function a() {} function b() {} function c() {} }", 1,
1939 1}, 1947 1},
1940 {NULL, 0, 0} 1948 {NULL, 0, 0}
1941 }; 1949 };
1942 // Each function adds 5 elements to the preparse function data. 1950 // Each function adds 5 elements to the preparse function data.
1943 const int kDataPerFunction = 5; 1951 const int kDataPerFunction = 5;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
2151 2159
2152 const char* statement_data[] = { 2160 const char* statement_data[] = {
2153 "new foo bar", 2161 "new foo bar",
2154 "new ) foo", 2162 "new ) foo",
2155 "new ++foo", 2163 "new ++foo",
2156 NULL 2164 NULL
2157 }; 2165 };
2158 2166
2159 RunParserSyncTest(context_data, statement_data, kError); 2167 RunParserSyncTest(context_data, statement_data, kError);
2160 } 2168 }
2169
2170
2171 TEST(StrictObjectLiteralChecking) {
2172 const char* strict_context_data[][2] = {
2173 {"\"use strict\"; var myobject = {", "};"},
2174 { NULL, NULL }
2175 };
2176 const char* non_strict_context_data[][2] = {
2177 {"var myobject = {", "};"},
2178 { NULL, NULL }
2179 };
2180
2181 // These are only errors in strict mode.
2182 const char* statement_data[] = {
2183 "foo: 1, foo: 2",
2184 "\"foo\": 1, \"foo\": 2",
2185 "foo: 1, \"foo\": 2",
2186 "1: 1, 1: 2",
2187 "1: 1, \"1\": 2",
2188 "get: 1, get: 2", // Not a getter for real, just a property called get.
2189 "set: 1, set: 2", // Not a setter for real, just a property called set.
2190 NULL
2191 };
2192
2193 RunParserSyncTest(non_strict_context_data, statement_data, kSuccess);
2194 RunParserSyncTest(strict_context_data, statement_data, kError);
2195 }
2196
2197
2198 TEST(ErrorsObjectLiteralChecking) {
2199 const char* context_data[][2] = {
2200 {"\"use strict\"; var myobject = {", "};"},
2201 {"var myobject = {", "};"},
2202 { NULL, NULL }
2203 };
2204
2205 const char* statement_data[] = {
2206 "foo: 1, get foo() {}",
2207 "foo: 1, set foo() {}",
2208 "\"foo\": 1, get \"foo\"() {}",
2209 "\"foo\": 1, set \"foo\"() {}",
2210 "1: 1, get 1() {}",
2211 "1: 1, set 1() {}",
2212 // It's counter-intuitive, but these collide too (even in classic
2213 // mode). Note that we can have "foo" and foo as properties in classic mode,
2214 // but we cannot have "foo" and get foo, or foo and get "foo".
2215 "foo: 1, get \"foo\"() {}",
2216 "foo: 1, set \"foo\"() {}",
2217 "\"foo\": 1, get foo() {}",
2218 "\"foo\": 1, set foo() {}",
2219 "1: 1, get \"1\"() {}",
2220 "1: 1, set \"1\"() {}",
2221 "\"1\": 1, get 1() {}"
2222 "\"1\": 1, set 1() {}"
2223 // Parsing FunctionLiteral for getter or setter fails
2224 "get foo( +",
2225 "get foo() \"error\"",
2226 NULL
2227 };
2228
2229 RunParserSyncTest(context_data, statement_data, kError);
2230 }
2231
2232
2233 TEST(NoErrorsObjectLiteralChecking) {
2234 const char* context_data[][2] = {
2235 {"var myobject = {", "};"},
2236 {"\"use strict\"; var myobject = {", "};"},
2237 { NULL, NULL }
2238 };
2239
2240 const char* statement_data[] = {
2241 "foo: 1, bar: 2",
2242 "\"foo\": 1, \"bar\": 2",
2243 "1: 1, 2: 2",
2244 // Syntax: IdentifierName ':' AssignmentExpression
2245 "foo: bar = 5 + baz",
2246 // Syntax: 'get' (IdentifierName | String | Number) FunctionLiteral
2247 "get foo() {}",
2248 "get \"foo\"() {}",
2249 "get 1() {}",
2250 // Syntax: 'set' (IdentifierName | String | Number) FunctionLiteral
2251 "set foo() {}",
2252 "set \"foo\"() {}",
2253 "set 1() {}",
2254 // Non-colliding getters and setters -> no errors
2255 "foo: 1, get bar() {}",
2256 "foo: 1, set bar(b) {}",
2257 "\"foo\": 1, get \"bar\"() {}",
2258 "\"foo\": 1, set \"bar\"() {}",
2259 "1: 1, get 2() {}",
2260 "1: 1, set 2() {}",
2261 // Weird number of parameters -> no errors
2262 "get bar() {}, set bar() {}",
2263 "get bar(x) {}, set bar(x) {}",
2264 "get bar(x, y) {}, set bar(x, y) {}",
2265 // Keywords, future reserved and strict future reserved are also allowed as
2266 // property names.
2267 "if: 4",
2268 "interface: 5",
2269 "super: 6",
2270 "eval: 7",
2271 "arguments: 8",
2272 NULL
2273 };
2274
2275 RunParserSyncTest(context_data, statement_data, kSuccess);
2276 }
OLDNEW
« no previous file with comments | « src/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698