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

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

Issue 160073006: Implement handling of arrow functions in the parser (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Removed ParamListFinder Created 6 years, 5 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
« src/preparser.cc ('K') | « src/token.h ('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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 148 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
149 for (int i = 0; tests[i]; i++) { 149 for (int i = 0; tests[i]; i++) {
150 const i::byte* source = 150 const i::byte* source =
151 reinterpret_cast<const i::byte*>(tests[i]); 151 reinterpret_cast<const i::byte*>(tests[i]);
152 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i])); 152 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i]));
153 i::CompleteParserRecorder log; 153 i::CompleteParserRecorder log;
154 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 154 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
155 scanner.Initialize(&stream); 155 scanner.Initialize(&stream);
156 i::PreParser preparser(&scanner, &log, stack_limit); 156 i::PreParser preparser(&scanner, &log, stack_limit);
157 preparser.set_allow_lazy(true); 157 preparser.set_allow_lazy(true);
158 preparser.set_allow_arrow_functions(true);
158 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 159 i::PreParser::PreParseResult result = preparser.PreParseProgram();
159 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 160 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
160 i::ScriptData data(log.ExtractData()); 161 i::ScriptData data(log.ExtractData());
161 CHECK(!data.has_error()); 162 CHECK(!data.has_error());
162 } 163 }
163 164
164 for (int i = 0; fail_tests[i]; i++) { 165 for (int i = 0; fail_tests[i]; i++) {
165 const i::byte* source = 166 const i::byte* source =
166 reinterpret_cast<const i::byte*>(fail_tests[i]); 167 reinterpret_cast<const i::byte*>(fail_tests[i]);
167 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i])); 168 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i]));
168 i::CompleteParserRecorder log; 169 i::CompleteParserRecorder log;
169 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 170 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
170 scanner.Initialize(&stream); 171 scanner.Initialize(&stream);
171 i::PreParser preparser(&scanner, &log, stack_limit); 172 i::PreParser preparser(&scanner, &log, stack_limit);
172 preparser.set_allow_lazy(true); 173 preparser.set_allow_lazy(true);
174 preparser.set_allow_arrow_functions(true);
173 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 175 i::PreParser::PreParseResult result = preparser.PreParseProgram();
174 // Even in the case of a syntax error, kPreParseSuccess is returned. 176 // Even in the case of a syntax error, kPreParseSuccess is returned.
175 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 177 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
176 i::ScriptData data(log.ExtractData()); 178 i::ScriptData data(log.ExtractData());
177 CHECK(data.has_error()); 179 CHECK(data.has_error());
178 } 180 }
179 } 181 }
180 182
181 183
182 class ScriptResource : public v8::String::ExternalAsciiStringResource { 184 class ScriptResource : public v8::String::ExternalAsciiStringResource {
183 public: 185 public:
184 ScriptResource(const char* data, size_t length) 186 ScriptResource(const char* data, size_t length)
185 : data_(data), length_(length) { } 187 : data_(data), length_(length) { }
186 188
187 const char* data() const { return data_; } 189 const char* data() const { return data_; }
188 size_t length() const { return length_; } 190 size_t length() const { return length_; }
189 191
190 private: 192 private:
191 const char* data_; 193 const char* data_;
192 size_t length_; 194 size_t length_;
193 }; 195 };
194 196
195 197
196 TEST(UsingCachedData) { 198 TEST(UsingCachedData) {
199 i::FLAG_harmony_arrow_functions = true;
marja 2014/06/26 14:38:14 I don't think you need to add this to existing tes
197 v8::Isolate* isolate = CcTest::isolate(); 200 v8::Isolate* isolate = CcTest::isolate();
198 v8::HandleScope handles(isolate); 201 v8::HandleScope handles(isolate);
199 v8::Local<v8::Context> context = v8::Context::New(isolate); 202 v8::Local<v8::Context> context = v8::Context::New(isolate);
200 v8::Context::Scope context_scope(context); 203 v8::Context::Scope context_scope(context);
201 int marker; 204 int marker;
202 CcTest::i_isolate()->stack_guard()->SetStackLimit( 205 CcTest::i_isolate()->stack_guard()->SetStackLimit(
203 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 206 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
204 207
205 // Source containing functions that might be lazily compiled and all types 208 // Source containing functions that might be lazily compiled and all types
206 // of symbols (string, propertyName, regexp). 209 // of symbols (string, propertyName, regexp).
(...skipping 27 matching lines...) Expand all
234 i::FLAG_lazy = lazy_flag; 237 i::FLAG_lazy = lazy_flag;
235 } 238 }
236 239
237 240
238 TEST(PreparseFunctionDataIsUsed) { 241 TEST(PreparseFunctionDataIsUsed) {
239 // This tests that we actually do use the function data generated by the 242 // This tests that we actually do use the function data generated by the
240 // preparser. 243 // preparser.
241 244
242 // Make preparsing work for short scripts. 245 // Make preparsing work for short scripts.
243 i::FLAG_min_preparse_length = 0; 246 i::FLAG_min_preparse_length = 0;
247 i::FLAG_harmony_arrow_functions = true;
244 248
245 v8::Isolate* isolate = CcTest::isolate(); 249 v8::Isolate* isolate = CcTest::isolate();
246 v8::HandleScope handles(isolate); 250 v8::HandleScope handles(isolate);
247 v8::Local<v8::Context> context = v8::Context::New(isolate); 251 v8::Local<v8::Context> context = v8::Context::New(isolate);
248 v8::Context::Scope context_scope(context); 252 v8::Context::Scope context_scope(context);
249 int marker; 253 int marker;
250 CcTest::i_isolate()->stack_guard()->SetStackLimit( 254 CcTest::i_isolate()->stack_guard()->SetStackLimit(
251 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 255 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
252 256
253 const char* good_code = 257 const char* good_code[] = {
marja 2014/06/26 14:38:14 I whined about this change before, I'm still whini
254 "function this_is_lazy() { var a; } function foo() { return 25; } foo();"; 258 "function this_is_lazy() { var a; } function foo() { return 25; } foo();",
259 NULL
260 };
255 261
256 // Insert a syntax error inside the lazy function. 262 // Insert a syntax error inside the lazy function.
257 const char* bad_code = 263 const char* bad_code[] = {
258 "function this_is_lazy() { if ( } function foo() { return 25; } foo();"; 264 "function this_is_lazy() { if ( } function foo() { return 25; } foo();",
265 NULL
266 };
259 267
260 v8::ScriptCompiler::Source good_source(v8_str(good_code)); 268 for (int i = 0; good_code[i]; i++) {
261 v8::ScriptCompiler::Compile(isolate, &good_source, 269 v8::ScriptCompiler::Source good_source(v8_str(good_code[i]));
262 v8::ScriptCompiler::kProduceDataToCache); 270 v8::ScriptCompiler::Compile(isolate, &good_source,
271 v8::ScriptCompiler::kProduceDataToCache);
263 272
264 const v8::ScriptCompiler::CachedData* cached_data = 273 const v8::ScriptCompiler::CachedData* cached_data =
265 good_source.GetCachedData(); 274 good_source.GetCachedData();
266 CHECK(cached_data->data != NULL); 275 CHECK(cached_data->data != NULL);
267 CHECK_GT(cached_data->length, 0); 276 CHECK_GT(cached_data->length, 0);
268 277
269 // Now compile the erroneous code with the good preparse data. If the preparse 278 // Now compile the erroneous code with the good preparse data. If the
270 // data is used, the lazy function is skipped and it should compile fine. 279 // preparse data is used, the lazy function is skipped and it should
271 v8::ScriptCompiler::Source bad_source( 280 // compile fine.
272 v8_str(bad_code), new v8::ScriptCompiler::CachedData( 281 v8::ScriptCompiler::Source bad_source(
273 cached_data->data, cached_data->length)); 282 v8_str(bad_code[i]), new v8::ScriptCompiler::CachedData(
274 v8::Local<v8::Value> result = 283 cached_data->data, cached_data->length));
275 v8::ScriptCompiler::Compile(isolate, &bad_source)->Run(); 284 v8::Local<v8::Value> result =
276 CHECK(result->IsInt32()); 285 v8::ScriptCompiler::Compile(isolate, &bad_source)->Run();
277 CHECK_EQ(25, result->Int32Value()); 286 CHECK(result->IsInt32());
287 CHECK_EQ(25, result->Int32Value());
288 }
278 } 289 }
279 290
280 291
281 TEST(StandAlonePreParser) { 292 TEST(StandAlonePreParser) {
282 v8::V8::Initialize(); 293 v8::V8::Initialize();
283 294
284 int marker; 295 int marker;
285 CcTest::i_isolate()->stack_guard()->SetStackLimit( 296 CcTest::i_isolate()->stack_guard()->SetStackLimit(
286 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 297 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
287 298
288 const char* programs[] = { 299 const char* programs[] = {
289 "{label: 42}", 300 "{label: 42}",
290 "var x = 42;", 301 "var x = 42;",
291 "function foo(x, y) { return x + y; }", 302 "function foo(x, y) { return x + y; }",
292 "%ArgleBargle(glop);", 303 "%ArgleBargle(glop);",
293 "var x = new new Function('this.x = 42');", 304 "var x = new new Function('this.x = 42');",
305 "var f = (x, y) => x + y;",
294 NULL 306 NULL
295 }; 307 };
296 308
297 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 309 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
298 for (int i = 0; programs[i]; i++) { 310 for (int i = 0; programs[i]; i++) {
299 const char* program = programs[i]; 311 const char* program = programs[i];
300 i::Utf8ToUtf16CharacterStream stream( 312 i::Utf8ToUtf16CharacterStream stream(
301 reinterpret_cast<const i::byte*>(program), 313 reinterpret_cast<const i::byte*>(program),
302 static_cast<unsigned>(strlen(program))); 314 static_cast<unsigned>(strlen(program)));
303 i::CompleteParserRecorder log; 315 i::CompleteParserRecorder log;
304 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 316 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
305 scanner.Initialize(&stream); 317 scanner.Initialize(&stream);
306 318
307 i::PreParser preparser(&scanner, &log, stack_limit); 319 i::PreParser preparser(&scanner, &log, stack_limit);
308 preparser.set_allow_lazy(true); 320 preparser.set_allow_lazy(true);
309 preparser.set_allow_natives_syntax(true); 321 preparser.set_allow_natives_syntax(true);
322 preparser.set_allow_arrow_functions(true);
310 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 323 i::PreParser::PreParseResult result = preparser.PreParseProgram();
311 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 324 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
312 i::ScriptData data(log.ExtractData()); 325 i::ScriptData data(log.ExtractData());
313 CHECK(!data.has_error()); 326 CHECK(!data.has_error());
314 } 327 }
315 } 328 }
316 329
317 330
318 TEST(StandAlonePreParserNoNatives) { 331 TEST(StandAlonePreParserNoNatives) {
319 v8::V8::Initialize(); 332 v8::V8::Initialize();
(...skipping 14 matching lines...) Expand all
334 i::Utf8ToUtf16CharacterStream stream( 347 i::Utf8ToUtf16CharacterStream stream(
335 reinterpret_cast<const i::byte*>(program), 348 reinterpret_cast<const i::byte*>(program),
336 static_cast<unsigned>(strlen(program))); 349 static_cast<unsigned>(strlen(program)));
337 i::CompleteParserRecorder log; 350 i::CompleteParserRecorder log;
338 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 351 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
339 scanner.Initialize(&stream); 352 scanner.Initialize(&stream);
340 353
341 // Preparser defaults to disallowing natives syntax. 354 // Preparser defaults to disallowing natives syntax.
342 i::PreParser preparser(&scanner, &log, stack_limit); 355 i::PreParser preparser(&scanner, &log, stack_limit);
343 preparser.set_allow_lazy(true); 356 preparser.set_allow_lazy(true);
357 preparser.set_allow_arrow_functions(true);
marja 2014/06/26 14:38:14 And these shouldn't be needed either. For these te
344 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 358 i::PreParser::PreParseResult result = preparser.PreParseProgram();
345 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 359 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
346 i::ScriptData data(log.ExtractData()); 360 i::ScriptData data(log.ExtractData());
347 // Data contains syntax error. 361 // Data contains syntax error.
348 CHECK(data.has_error()); 362 CHECK(data.has_error());
349 } 363 }
350 } 364 }
351 365
352 366
353 TEST(PreparsingObjectLiterals) { 367 TEST(PreparsingObjectLiterals) {
354 // Regression test for a bug where the symbol stream produced by PreParser 368 // Regression test for a bug where the symbol stream produced by PreParser
355 // didn't match what Parser wanted to consume. 369 // didn't match what Parser wanted to consume.
370 i::FLAG_harmony_arrow_functions = true;
356 v8::Isolate* isolate = CcTest::isolate(); 371 v8::Isolate* isolate = CcTest::isolate();
357 v8::HandleScope handles(isolate); 372 v8::HandleScope handles(isolate);
358 v8::Local<v8::Context> context = v8::Context::New(isolate); 373 v8::Local<v8::Context> context = v8::Context::New(isolate);
359 v8::Context::Scope context_scope(context); 374 v8::Context::Scope context_scope(context);
360 int marker; 375 int marker;
361 CcTest::i_isolate()->stack_guard()->SetStackLimit( 376 CcTest::i_isolate()->stack_guard()->SetStackLimit(
362 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 377 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
363 378
364 { 379 {
365 const char* source = "var myo = {if: \"foo\"}; myo.if;"; 380 const char* source = "var myo = {if: \"foo\"}; myo.if;";
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 419
405 i::Utf8ToUtf16CharacterStream stream( 420 i::Utf8ToUtf16CharacterStream stream(
406 reinterpret_cast<const i::byte*>(program), 421 reinterpret_cast<const i::byte*>(program),
407 static_cast<unsigned>(strlen(program))); 422 static_cast<unsigned>(strlen(program)));
408 i::CompleteParserRecorder log; 423 i::CompleteParserRecorder log;
409 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 424 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
410 scanner.Initialize(&stream); 425 scanner.Initialize(&stream);
411 i::PreParser preparser(&scanner, &log, 426 i::PreParser preparser(&scanner, &log,
412 CcTest::i_isolate()->stack_guard()->real_climit()); 427 CcTest::i_isolate()->stack_guard()->real_climit());
413 preparser.set_allow_lazy(true); 428 preparser.set_allow_lazy(true);
429 preparser.set_allow_arrow_functions(true);
414 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 430 i::PreParser::PreParseResult result = preparser.PreParseProgram();
415 // Even in the case of a syntax error, kPreParseSuccess is returned. 431 // Even in the case of a syntax error, kPreParseSuccess is returned.
416 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 432 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
417 i::ScriptData data(log.ExtractData()); 433 i::ScriptData data(log.ExtractData());
418 CHECK(data.has_error()); 434 CHECK(data.has_error());
419 } 435 }
420 436
421 437
422 TEST(Regress928) { 438 TEST(Regress928) {
423 v8::V8::Initialize(); 439 v8::V8::Initialize();
(...skipping 14 matching lines...) Expand all
438 454
439 v8::HandleScope handles(CcTest::isolate()); 455 v8::HandleScope handles(CcTest::isolate());
440 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program); 456 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program);
441 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 457 i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
442 i::CompleteParserRecorder log; 458 i::CompleteParserRecorder log;
443 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 459 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
444 scanner.Initialize(&stream); 460 scanner.Initialize(&stream);
445 i::PreParser preparser(&scanner, &log, 461 i::PreParser preparser(&scanner, &log,
446 CcTest::i_isolate()->stack_guard()->real_climit()); 462 CcTest::i_isolate()->stack_guard()->real_climit());
447 preparser.set_allow_lazy(true); 463 preparser.set_allow_lazy(true);
464 preparser.set_allow_arrow_functions(true);
448 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 465 i::PreParser::PreParseResult result = preparser.PreParseProgram();
449 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 466 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
450 i::ScriptData data(log.ExtractData()); 467 i::ScriptData data(log.ExtractData());
451 CHECK(!data.has_error()); 468 CHECK(!data.has_error());
452 data.Initialize(); 469 data.Initialize();
453 470
454 int first_function = 471 int first_function =
455 static_cast<int>(strstr(program, "function") - program); 472 static_cast<int>(strstr(program, "function") - program);
456 int first_lbrace = first_function + i::StrLength("function () "); 473 int first_lbrace = first_function + i::StrLength("function () ");
457 CHECK_EQ('{', program[first_lbrace]); 474 CHECK_EQ('{', program[first_lbrace]);
(...skipping 27 matching lines...) Expand all
485 502
486 i::Utf8ToUtf16CharacterStream stream( 503 i::Utf8ToUtf16CharacterStream stream(
487 reinterpret_cast<const i::byte*>(program.get()), 504 reinterpret_cast<const i::byte*>(program.get()),
488 static_cast<unsigned>(kProgramSize)); 505 static_cast<unsigned>(kProgramSize));
489 i::CompleteParserRecorder log; 506 i::CompleteParserRecorder log;
490 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 507 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
491 scanner.Initialize(&stream); 508 scanner.Initialize(&stream);
492 509
493 i::PreParser preparser(&scanner, &log, stack_limit); 510 i::PreParser preparser(&scanner, &log, stack_limit);
494 preparser.set_allow_lazy(true); 511 preparser.set_allow_lazy(true);
512 preparser.set_allow_arrow_functions(true);
495 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 513 i::PreParser::PreParseResult result = preparser.PreParseProgram();
496 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); 514 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result);
497 } 515 }
498 516
499 517
500 class TestExternalResource: public v8::String::ExternalStringResource { 518 class TestExternalResource: public v8::String::ExternalStringResource {
501 public: 519 public:
502 explicit TestExternalResource(uint16_t* data, int length) 520 explicit TestExternalResource(uint16_t* data, int length)
503 : data_(data), length_(static_cast<size_t>(length)) { } 521 : data_(data), length_(static_cast<size_t>(length)) { }
504 522
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 i += input_offset; 924 i += input_offset;
907 character_length -= output_adjust; 925 character_length -= output_adjust;
908 } 926 }
909 } 927 }
910 } 928 }
911 return character_length; 929 return character_length;
912 } 930 }
913 931
914 932
915 TEST(ScopePositions) { 933 TEST(ScopePositions) {
916 v8::internal::FLAG_harmony_scoping = true;
marja 2014/06/26 14:38:14 Why this change?
917
918 // Test the parser for correctly setting the start and end positions 934 // Test the parser for correctly setting the start and end positions
919 // of a scope. We check the scope positions of exactly one scope 935 // of a scope. We check the scope positions of exactly one scope
920 // nested in the global scope of a program. 'inner source' is the 936 // nested in the global scope of a program. 'inner source' is the
921 // source code that determines the part of the source belonging 937 // source code that determines the part of the source belonging
922 // to the nested scope. 'outer_prefix' and 'outer_suffix' are 938 // to the nested scope. 'outer_prefix' and 'outer_suffix' are
923 // parts of the source that belong to the global scope. 939 // parts of the source that belong to the global scope.
924 struct SourceData { 940 struct SourceData {
925 const char* outer_prefix; 941 const char* outer_prefix;
926 const char* inner_source; 942 const char* inner_source;
927 const char* outer_suffix; 943 const char* outer_suffix;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 " }", "\n" 978 " }", "\n"
963 " more;", i::BLOCK_SCOPE, i::STRICT }, 979 " more;", i::BLOCK_SCOPE, i::STRICT },
964 { " start;\n" 980 { " start;\n"
965 " function fun", "(a,b) { infunction; }", " more;", 981 " function fun", "(a,b) { infunction; }", " more;",
966 i::FUNCTION_SCOPE, i::SLOPPY }, 982 i::FUNCTION_SCOPE, i::SLOPPY },
967 { " start;\n" 983 { " start;\n"
968 " function fun", "(a,b) {\n" 984 " function fun", "(a,b) {\n"
969 " infunction;\n" 985 " infunction;\n"
970 " }", "\n" 986 " }", "\n"
971 " more;", i::FUNCTION_SCOPE, i::SLOPPY }, 987 " more;", i::FUNCTION_SCOPE, i::SLOPPY },
972 { " (function fun", "(a,b) { infunction; }", ")();", 988 { " start;\n"
989 " (function fun", "(a,b) { infunction; }", ")();",
973 i::FUNCTION_SCOPE, i::SLOPPY }, 990 i::FUNCTION_SCOPE, i::SLOPPY },
974 { " for ", "(let x = 1 ; x < 10; ++ x) { block; }", " more;", 991 { " for ", "(let x = 1 ; x < 10; ++ x) { block; }", " more;",
975 i::BLOCK_SCOPE, i::STRICT }, 992 i::BLOCK_SCOPE, i::STRICT },
976 { " for ", "(let x = 1 ; x < 10; ++ x) { block; }", "; more;", 993 { " for ", "(let x = 1 ; x < 10; ++ x) { block; }", "; more;",
977 i::BLOCK_SCOPE, i::STRICT }, 994 i::BLOCK_SCOPE, i::STRICT },
978 { " for ", "(let x = 1 ; x < 10; ++ x) {\n" 995 { " for ", "(let x = 1 ; x < 10; ++ x) {\n"
979 " block;\n" 996 " block;\n"
980 " }", "\n" 997 " }", "\n"
981 " more;", i::BLOCK_SCOPE, i::STRICT }, 998 " more;", i::BLOCK_SCOPE, i::STRICT },
982 { " for ", "(let x = 1 ; x < 10; ++ x) statement;", " more;", 999 { " for ", "(let x = 1 ; x < 10; ++ x) statement;", " more;",
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 1134
1118 // Parse program source. 1135 // Parse program source.
1119 i::Handle<i::String> source = factory->NewStringFromUtf8( 1136 i::Handle<i::String> source = factory->NewStringFromUtf8(
1120 i::CStrVector(program.start())).ToHandleChecked(); 1137 i::CStrVector(program.start())).ToHandleChecked();
1121 CHECK_EQ(source->length(), kProgramSize); 1138 CHECK_EQ(source->length(), kProgramSize);
1122 i::Handle<i::Script> script = factory->NewScript(source); 1139 i::Handle<i::Script> script = factory->NewScript(source);
1123 i::CompilationInfoWithZone info(script); 1140 i::CompilationInfoWithZone info(script);
1124 i::Parser parser(&info); 1141 i::Parser parser(&info);
1125 parser.set_allow_lazy(true); 1142 parser.set_allow_lazy(true);
1126 parser.set_allow_harmony_scoping(true); 1143 parser.set_allow_harmony_scoping(true);
1144 parser.set_allow_arrow_functions(true);
1127 info.MarkAsGlobal(); 1145 info.MarkAsGlobal();
1128 info.SetStrictMode(source_data[i].strict_mode); 1146 info.SetStrictMode(source_data[i].strict_mode);
1129 parser.Parse(); 1147 parser.Parse();
1130 CHECK(info.function() != NULL); 1148 CHECK(info.function() != NULL);
1131 1149
1132 // Check scope types and positions. 1150 // Check scope types and positions.
1133 i::Scope* scope = info.function()->scope(); 1151 i::Scope* scope = info.function()->scope();
1134 CHECK(scope->is_global_scope()); 1152 CHECK(scope->is_global_scope());
1135 CHECK_EQ(scope->start_position(), 0); 1153 CHECK_EQ(scope->start_position(), 0);
1136 CHECK_EQ(scope->end_position(), kProgramSize); 1154 CHECK_EQ(scope->end_position(), kProgramSize);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 } 1191 }
1174 1192
1175 1193
1176 enum ParserFlag { 1194 enum ParserFlag {
1177 kAllowLazy, 1195 kAllowLazy,
1178 kAllowNativesSyntax, 1196 kAllowNativesSyntax,
1179 kAllowHarmonyScoping, 1197 kAllowHarmonyScoping,
1180 kAllowModules, 1198 kAllowModules,
1181 kAllowGenerators, 1199 kAllowGenerators,
1182 kAllowForOf, 1200 kAllowForOf,
1183 kAllowHarmonyNumericLiterals 1201 kAllowHarmonyNumericLiterals,
1202 kAllowArrowFunctions
1184 }; 1203 };
1185 1204
1186 1205
1187 enum ParserSyncTestResult { 1206 enum ParserSyncTestResult {
1188 kSuccessOrError, 1207 kSuccessOrError,
1189 kSuccess, 1208 kSuccess,
1190 kError 1209 kError
1191 }; 1210 };
1192 1211
1193 template <typename Traits> 1212 template <typename Traits>
1194 void SetParserFlags(i::ParserBase<Traits>* parser, 1213 void SetParserFlags(i::ParserBase<Traits>* parser,
1195 i::EnumSet<ParserFlag> flags) { 1214 i::EnumSet<ParserFlag> flags) {
1196 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1215 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1197 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); 1216 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax));
1198 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); 1217 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping));
1199 parser->set_allow_modules(flags.Contains(kAllowModules)); 1218 parser->set_allow_modules(flags.Contains(kAllowModules));
1200 parser->set_allow_generators(flags.Contains(kAllowGenerators)); 1219 parser->set_allow_generators(flags.Contains(kAllowGenerators));
1201 parser->set_allow_for_of(flags.Contains(kAllowForOf)); 1220 parser->set_allow_for_of(flags.Contains(kAllowForOf));
1202 parser->set_allow_harmony_numeric_literals( 1221 parser->set_allow_harmony_numeric_literals(
1203 flags.Contains(kAllowHarmonyNumericLiterals)); 1222 flags.Contains(kAllowHarmonyNumericLiterals));
1223 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions));
1204 } 1224 }
1205 1225
1206 1226
1207 void TestParserSyncWithFlags(i::Handle<i::String> source, 1227 void TestParserSyncWithFlags(i::Handle<i::String> source,
1208 i::EnumSet<ParserFlag> flags, 1228 i::EnumSet<ParserFlag> flags,
1209 ParserSyncTestResult result) { 1229 ParserSyncTestResult result) {
1210 i::Isolate* isolate = CcTest::i_isolate(); 1230 i::Isolate* isolate = CcTest::i_isolate();
1211 i::Factory* factory = isolate->factory(); 1231 i::Factory* factory = isolate->factory();
1212 1232
1213 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); 1233 uintptr_t stack_limit = isolate->stack_guard()->real_climit();
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 }; 1416 };
1397 1417
1398 v8::HandleScope handles(CcTest::isolate()); 1418 v8::HandleScope handles(CcTest::isolate());
1399 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1419 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1400 v8::Context::Scope context_scope(context); 1420 v8::Context::Scope context_scope(context);
1401 1421
1402 int marker; 1422 int marker;
1403 CcTest::i_isolate()->stack_guard()->SetStackLimit( 1423 CcTest::i_isolate()->stack_guard()->SetStackLimit(
1404 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 1424 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
1405 1425
1426 static const ParserFlag always_flags[] = { kAllowArrowFunctions };
marja 2014/06/26 14:38:14 Instead of this, you should add the flag to flags1
1406 static const ParserFlag flags1[] = { 1427 static const ParserFlag flags1[] = {
1407 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators, 1428 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators,
1408 kAllowForOf 1429 kAllowForOf
1409 }; 1430 };
1410 for (int i = 0; context_data[i][0] != NULL; ++i) { 1431 for (int i = 0; context_data[i][0] != NULL; ++i) {
1411 for (int j = 0; statement_data[j] != NULL; ++j) { 1432 for (int j = 0; statement_data[j] != NULL; ++j) {
1412 for (int k = 0; termination_data[k] != NULL; ++k) { 1433 for (int k = 0; termination_data[k] != NULL; ++k) {
1413 int kPrefixLen = i::StrLength(context_data[i][0]); 1434 int kPrefixLen = i::StrLength(context_data[i][0]);
1414 int kStatementLen = i::StrLength(statement_data[j]); 1435 int kStatementLen = i::StrLength(statement_data[j]);
1415 int kTerminationLen = i::StrLength(termination_data[k]); 1436 int kTerminationLen = i::StrLength(termination_data[k]);
1416 int kSuffixLen = i::StrLength(context_data[i][1]); 1437 int kSuffixLen = i::StrLength(context_data[i][1]);
1417 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen 1438 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen
1418 + kSuffixLen + i::StrLength("label: for (;;) { }"); 1439 + kSuffixLen + i::StrLength("label: for (;;) { }");
1419 1440
1420 // Plug the source code pieces together. 1441 // Plug the source code pieces together.
1421 i::ScopedVector<char> program(kProgramSize + 1); 1442 i::ScopedVector<char> program(kProgramSize + 1);
1422 int length = i::SNPrintF(program, 1443 int length = i::SNPrintF(program,
1423 "label: for (;;) { %s%s%s%s }", 1444 "label: for (;;) { %s%s%s%s }",
1424 context_data[i][0], 1445 context_data[i][0],
1425 statement_data[j], 1446 statement_data[j],
1426 termination_data[k], 1447 termination_data[k],
1427 context_data[i][1]); 1448 context_data[i][1]);
1428 CHECK(length == kProgramSize); 1449 CHECK(length == kProgramSize);
1429 TestParserSync(program.start(), flags1, ARRAY_SIZE(flags1)); 1450 TestParserSync(program.start(), flags1, ARRAY_SIZE(flags1),
1451 kSuccessOrError, always_flags, ARRAY_SIZE(always_flags));
1430 } 1452 }
1431 } 1453 }
1432 } 1454 }
1433 1455
1434 // Neither Harmony numeric literals nor our natives syntax have any 1456 // Neither Harmony numeric literals nor our natives syntax have any
1435 // interaction with the flags above, so test these separately to reduce 1457 // interaction with the flags above, so test these separately to reduce
1436 // the combinatorial explosion. 1458 // the combinatorial explosion.
1437 static const ParserFlag flags2[] = { kAllowHarmonyNumericLiterals }; 1459 static const ParserFlag flags2[] = { kAllowHarmonyNumericLiterals };
1438 TestParserSync("0o1234", flags2, ARRAY_SIZE(flags2)); 1460 TestParserSync("0o1234", flags2, ARRAY_SIZE(flags2),
1439 TestParserSync("0b1011", flags2, ARRAY_SIZE(flags2)); 1461 kSuccessOrError, always_flags, ARRAY_SIZE(always_flags));
1462 TestParserSync("0b1011", flags2, ARRAY_SIZE(flags2),
1463 kSuccessOrError, always_flags, ARRAY_SIZE(always_flags));
1440 1464
1441 static const ParserFlag flags3[] = { kAllowNativesSyntax }; 1465 static const ParserFlag flags3[] = { kAllowNativesSyntax };
1442 TestParserSync("%DebugPrint(123)", flags3, ARRAY_SIZE(flags3)); 1466 TestParserSync("%DebugPrint(123)", flags3, ARRAY_SIZE(flags3),
1467 kSuccessOrError, always_flags, ARRAY_SIZE(always_flags));
1443 } 1468 }
1444 1469
1445 1470
1446 TEST(StrictOctal) { 1471 TEST(StrictOctal) {
1447 // Test that syntax error caused by octal literal is reported correctly as 1472 // Test that syntax error caused by octal literal is reported correctly as
1448 // such (issue 2220). 1473 // such (issue 2220).
1449 v8::V8::Initialize(); 1474 v8::V8::Initialize();
1475 i::FLAG_harmony_arrow_functions = true;
1476
1450 v8::HandleScope scope(CcTest::isolate()); 1477 v8::HandleScope scope(CcTest::isolate());
1451 v8::Context::Scope context_scope( 1478 v8::Context::Scope context_scope(
1452 v8::Context::New(CcTest::isolate())); 1479 v8::Context::New(CcTest::isolate()));
1453 v8::TryCatch try_catch; 1480 v8::TryCatch try_catch;
1454 const char* script = 1481 const char* script =
1455 "\"use strict\"; \n" 1482 "\"use strict\"; \n"
1456 "a = function() { \n" 1483 "a = function() { \n"
1457 " b = function() { \n" 1484 " b = function() { \n"
1458 " 01; \n" 1485 " 01; \n"
1459 " }; \n" 1486 " }; \n"
(...skipping 16 matching lines...) Expand all
1476 v8::HandleScope handles(CcTest::isolate()); 1503 v8::HandleScope handles(CcTest::isolate());
1477 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1504 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1478 v8::Context::Scope context_scope(context); 1505 v8::Context::Scope context_scope(context);
1479 1506
1480 int marker; 1507 int marker;
1481 CcTest::i_isolate()->stack_guard()->SetStackLimit( 1508 CcTest::i_isolate()->stack_guard()->SetStackLimit(
1482 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 1509 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
1483 1510
1484 static const ParserFlag default_flags[] = { 1511 static const ParserFlag default_flags[] = {
1485 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators, 1512 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators,
1486 kAllowForOf, kAllowNativesSyntax 1513 kAllowForOf, kAllowNativesSyntax, kAllowArrowFunctions
1487 }; 1514 };
1488 ParserFlag* generated_flags = NULL; 1515 ParserFlag* generated_flags = NULL;
1489 if (flags == NULL) { 1516 if (flags == NULL) {
1490 flags = default_flags; 1517 flags = default_flags;
1491 flags_len = ARRAY_SIZE(default_flags); 1518 flags_len = ARRAY_SIZE(default_flags);
1492 if (always_true_flags != NULL) { 1519 if (always_true_flags != NULL) {
1493 // Remove always_true_flags from default_flags. 1520 // Remove always_true_flags from default_flags.
1494 CHECK(always_true_flags_len < flags_len); 1521 CHECK(always_true_flags_len < flags_len);
1495 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; 1522 generated_flags = new ParserFlag[flags_len - always_true_flags_len];
1496 int flag_index = 0; 1523 int flag_index = 0;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 "var foo, eval;", 1580 "var foo, eval;",
1554 "var foo, arguments;", 1581 "var foo, arguments;",
1555 "try { } catch (eval) { }", 1582 "try { } catch (eval) { }",
1556 "try { } catch (arguments) { }", 1583 "try { } catch (arguments) { }",
1557 "function eval() { }", 1584 "function eval() { }",
1558 "function arguments() { }", 1585 "function arguments() { }",
1559 "function foo(eval) { }", 1586 "function foo(eval) { }",
1560 "function foo(arguments) { }", 1587 "function foo(arguments) { }",
1561 "function foo(bar, eval) { }", 1588 "function foo(bar, eval) { }",
1562 "function foo(bar, arguments) { }", 1589 "function foo(bar, arguments) { }",
1590 "(eval) => { }",
1591 "(arguments) => { }",
1592 "(foo, eval) => { }",
1593 "(foo, arguments) => { }",
1563 "eval = 1;", 1594 "eval = 1;",
1564 "arguments = 1;", 1595 "arguments = 1;",
1565 "var foo = eval = 1;", 1596 "var foo = eval = 1;",
1566 "var foo = arguments = 1;", 1597 "var foo = arguments = 1;",
1567 "++eval;", 1598 "++eval;",
1568 "++arguments;", 1599 "++arguments;",
1569 "eval++;", 1600 "eval++;",
1570 "arguments++;", 1601 "arguments++;",
1571 NULL 1602 NULL
1572 }; 1603 };
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1609 }; 1640 };
1610 1641
1611 RunParserSyncTest(context_data, statement_data, kSuccess); 1642 RunParserSyncTest(context_data, statement_data, kSuccess);
1612 } 1643 }
1613 1644
1614 1645
1615 TEST(NoErrorsEvalAndArgumentsStrict) { 1646 TEST(NoErrorsEvalAndArgumentsStrict) {
1616 const char* context_data[][2] = { 1647 const char* context_data[][2] = {
1617 { "\"use strict\";", "" }, 1648 { "\"use strict\";", "" },
1618 { "function test_func() { \"use strict\";", "}" }, 1649 { "function test_func() { \"use strict\";", "}" },
1650 { "() => { \"use strict\"; ", "}" },
1619 { NULL, NULL } 1651 { NULL, NULL }
1620 }; 1652 };
1621 1653
1622 const char* statement_data[] = { 1654 const char* statement_data[] = {
1623 "eval;", 1655 "eval;",
1624 "arguments;", 1656 "arguments;",
1625 "var foo = eval;", 1657 "var foo = eval;",
1626 "var foo = arguments;", 1658 "var foo = arguments;",
1627 "var foo = { eval: 1 };", 1659 "var foo = { eval: 1 };",
1628 "var foo = { arguments: 1 };", 1660 "var foo = { arguments: 1 };",
1629 "var foo = { }; foo.eval = {};", 1661 "var foo = { }; foo.eval = {};",
1630 "var foo = { }; foo.arguments = {};", 1662 "var foo = { }; foo.arguments = {};",
1631 NULL 1663 NULL
1632 }; 1664 };
1633 1665
1634 RunParserSyncTest(context_data, statement_data, kSuccess); 1666 static const ParserFlag always_flags[] = { kAllowArrowFunctions };
1667 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1668 always_flags, ARRAY_SIZE(always_flags));
1635 } 1669 }
1636 1670
1637 1671
1638 TEST(ErrorsFutureStrictReservedWords) { 1672 TEST(ErrorsFutureStrictReservedWords) {
1639 // Tests that both preparsing and parsing produce the right kind of errors for 1673 // Tests that both preparsing and parsing produce the right kind of errors for
1640 // using future strict reserved words as identifiers. Without the strict mode, 1674 // using future strict reserved words as identifiers. Without the strict mode,
1641 // it's ok to use future strict reserved words as identifiers. With the strict 1675 // it's ok to use future strict reserved words as identifiers. With the strict
1642 // mode, it isn't. 1676 // mode, it isn't.
1643 const char* context_data[][2] = { 1677 const char* context_data[][2] = {
1644 { "\"use strict\";", "" }, 1678 { "\"use strict\";", "" },
1645 { "function test_func() {\"use strict\"; ", "}"}, 1679 { "function test_func() {\"use strict\"; ", "}"},
1680 { "() => { \"use strict\"; ", "}" },
1646 { NULL, NULL } 1681 { NULL, NULL }
1647 }; 1682 };
1648 1683
1649 const char* statement_data[] = { 1684 const char* statement_data[] = {
1650 "var interface;", 1685 "var interface;",
1651 "var foo, interface;", 1686 "var foo, interface;",
1652 "try { } catch (interface) { }", 1687 "try { } catch (interface) { }",
1653 "function interface() { }", 1688 "function interface() { }",
1654 "function foo(interface) { }", 1689 "function foo(interface) { }",
1655 "function foo(bar, interface) { }", 1690 "function foo(bar, interface) { }",
1691 "(interface) => { }",
1692 "(bar, interface) => { }",
1656 "interface = 1;", 1693 "interface = 1;",
1657 "var foo = interface = 1;", 1694 "var foo = interface = 1;",
1658 "++interface;", 1695 "++interface;",
1659 "interface++;", 1696 "interface++;",
1660 NULL 1697 NULL
1661 }; 1698 };
1662 1699
1700 i::FLAG_harmony_arrow_functions = true;
marja 2014/06/26 14:38:13 Instead of this, you should use always_true_flags.
1663 RunParserSyncTest(context_data, statement_data, kError); 1701 RunParserSyncTest(context_data, statement_data, kError);
1664 } 1702 }
1665 1703
1666 1704
1667 TEST(NoErrorsFutureStrictReservedWords) { 1705 TEST(NoErrorsFutureStrictReservedWords) {
1668 const char* context_data[][2] = { 1706 const char* context_data[][2] = {
1669 { "", "" }, 1707 { "", "" },
1670 { "function test_func() {", "}"}, 1708 { "function test_func() {", "}"},
1709 { "() => {", "}" },
1671 { NULL, NULL } 1710 { NULL, NULL }
1672 }; 1711 };
1673 1712
1674 const char* statement_data[] = { 1713 const char* statement_data[] = {
1675 "var interface;", 1714 "var interface;",
1676 "var foo, interface;", 1715 "var foo, interface;",
1677 "try { } catch (interface) { }", 1716 "try { } catch (interface) { }",
1678 "function interface() { }", 1717 "function interface() { }",
1679 "function foo(interface) { }", 1718 "function foo(interface) { }",
1680 "function foo(bar, interface) { }", 1719 "function foo(bar, interface) { }",
1681 "interface = 1;", 1720 "interface = 1;",
1682 "var foo = interface = 1;", 1721 "var foo = interface = 1;",
1683 "++interface;", 1722 "++interface;",
1684 "interface++;", 1723 "interface++;",
1685 NULL 1724 NULL
1686 }; 1725 };
1687 1726
1688 RunParserSyncTest(context_data, statement_data, kSuccess); 1727 static const ParserFlag always_flags[] = { kAllowArrowFunctions };
1728 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1729 always_flags, ARRAY_SIZE(always_flags));
1730
1689 } 1731 }
1690 1732
1691 1733
1692 TEST(ErrorsReservedWords) { 1734 TEST(ErrorsReservedWords) {
1693 // Tests that both preparsing and parsing produce the right kind of errors for 1735 // Tests that both preparsing and parsing produce the right kind of errors for
1694 // using future reserved words as identifiers. These tests don't depend on the 1736 // using future reserved words as identifiers. These tests don't depend on the
1695 // strict mode. 1737 // strict mode.
1696 const char* context_data[][2] = { 1738 const char* context_data[][2] = {
1697 { "", "" }, 1739 { "", "" },
1698 { "\"use strict\";", "" }, 1740 { "\"use strict\";", "" },
1699 { "var eval; function test_func() {", "}"}, 1741 { "var eval; function test_func() {", "}"},
1700 { "var eval; function test_func() {\"use strict\"; ", "}"}, 1742 { "var eval; function test_func() {\"use strict\"; ", "}"},
1743 { "var eval; () => {", "}" },
1744 { "var eval; () => {\"use strict\"; ", "}" },
1701 { NULL, NULL } 1745 { NULL, NULL }
1702 }; 1746 };
1703 1747
1704 const char* statement_data[] = { 1748 const char* statement_data[] = {
1705 "var super;", 1749 "var super;",
1706 "var foo, super;", 1750 "var foo, super;",
1707 "try { } catch (super) { }", 1751 "try { } catch (super) { }",
1708 "function super() { }", 1752 "function super() { }",
1709 "function foo(super) { }", 1753 "function foo(super) { }",
1710 "function foo(bar, super) { }", 1754 "function foo(bar, super) { }",
1755 "(super) => { }",
1756 "(bar, super) => { }",
1711 "super = 1;", 1757 "super = 1;",
1712 "var foo = super = 1;", 1758 "var foo = super = 1;",
1713 "++super;", 1759 "++super;",
1714 "super++;", 1760 "super++;",
1715 "function foo super", 1761 "function foo super",
1716 NULL 1762 NULL
1717 }; 1763 };
1718 1764
1765 i::FLAG_harmony_arrow_functions = true;
marja 2014/06/26 14:38:14 Here too... in all places, where you need the flag
1719 RunParserSyncTest(context_data, statement_data, kError); 1766 RunParserSyncTest(context_data, statement_data, kError);
1720 } 1767 }
1721 1768
1722 1769
1723 TEST(NoErrorsYieldSloppy) { 1770 TEST(NoErrorsYieldSloppy) {
1724 // In sloppy mode, it's okay to use "yield" as identifier, *except* inside a 1771 // In sloppy mode, it's okay to use "yield" as identifier, *except* inside a
1725 // generator (see next test). 1772 // generator (see next test).
1726 const char* context_data[][2] = { 1773 const char* context_data[][2] = {
1727 { "", "" }, 1774 { "", "" },
1728 { "function is_not_gen() {", "}" }, 1775 { "function is_not_gen() {", "}" },
1776 { "() => {", "}" },
1729 { NULL, NULL } 1777 { NULL, NULL }
1730 }; 1778 };
1731 1779
1732 const char* statement_data[] = { 1780 const char* statement_data[] = {
1733 "var yield;", 1781 "var yield;",
1734 "var foo, yield;", 1782 "var foo, yield;",
1735 "try { } catch (yield) { }", 1783 "try { } catch (yield) { }",
1736 "function yield() { }", 1784 "function yield() { }",
1737 "function foo(yield) { }", 1785 "function foo(yield) { }",
1738 "function foo(bar, yield) { }", 1786 "function foo(bar, yield) { }",
1739 "yield = 1;", 1787 "yield = 1;",
1740 "var foo = yield = 1;", 1788 "var foo = yield = 1;",
1741 "++yield;", 1789 "++yield;",
1742 "yield++;", 1790 "yield++;",
1743 NULL 1791 NULL
1744 }; 1792 };
1745 1793
1746 RunParserSyncTest(context_data, statement_data, kSuccess); 1794 static const ParserFlag always_flags[] = { kAllowArrowFunctions };
1795 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1796 always_flags, ARRAY_SIZE(always_flags));
1747 } 1797 }
1748 1798
1749 1799
1750 TEST(ErrorsYieldSloppyGenerator) { 1800 TEST(ErrorsYieldSloppyGenerator) {
1751 const char* context_data[][2] = { 1801 const char* context_data[][2] = {
1752 { "function * is_gen() {", "}" }, 1802 { "function * is_gen() {", "}" },
1753 { NULL, NULL } 1803 { NULL, NULL }
1754 }; 1804 };
1755 1805
1756 const char* statement_data[] = { 1806 const char* statement_data[] = {
1757 "var yield;", 1807 "var yield;",
1758 "var foo, yield;", 1808 "var foo, yield;",
1759 "try { } catch (yield) { }", 1809 "try { } catch (yield) { }",
1760 "function yield() { }", 1810 "function yield() { }",
1761 // BUG: These should not be allowed, but they are (if kAllowGenerators is 1811 // BUG: These should not be allowed, but they are (if kAllowGenerators is
1762 // set) 1812 // set)
1763 // "function foo(yield) { }", 1813 // "function foo(yield) { }",
1764 // "function foo(bar, yield) { }", 1814 // "function foo(bar, yield) { }",
1765 "yield = 1;", 1815 "yield = 1;",
1766 "var foo = yield = 1;", 1816 "var foo = yield = 1;",
1767 "++yield;", 1817 "++yield;",
1768 "yield++;", 1818 "yield++;",
1769 NULL 1819 NULL
1770 }; 1820 };
1771 1821
1772 // If generators are not allowed, the error will be produced at the '*' token, 1822 // If generators are not allowed, the error will be produced at the '*' token,
1773 // so this test works both with and without the kAllowGenerators flag. 1823 // so this test works both with and without the kAllowGenerators flag.
1824 i::FLAG_harmony_arrow_functions = true;
marja 2014/06/26 14:38:14 And this is completely unnecessary; the test shoul
1774 RunParserSyncTest(context_data, statement_data, kError); 1825 RunParserSyncTest(context_data, statement_data, kError);
1775 } 1826 }
1776 1827
1777 1828
1778 TEST(ErrorsYieldStrict) { 1829 TEST(ErrorsYieldStrict) {
1779 const char* context_data[][2] = { 1830 const char* context_data[][2] = {
1780 { "\"use strict\";", "" }, 1831 { "\"use strict\";", "" },
1781 { "\"use strict\"; function is_not_gen() {", "}" }, 1832 { "\"use strict\"; function is_not_gen() {", "}" },
1782 { "function test_func() {\"use strict\"; ", "}"}, 1833 { "function test_func() {\"use strict\"; ", "}"},
1834 { "() => {\"use strict\"; ", "}" },
1783 { NULL, NULL } 1835 { NULL, NULL }
1784 }; 1836 };
1785 1837
1786 const char* statement_data[] = { 1838 const char* statement_data[] = {
1787 "var yield;", 1839 "var yield;",
1788 "var foo, yield;", 1840 "var foo, yield;",
1789 "try { } catch (yield) { }", 1841 "try { } catch (yield) { }",
1790 "function yield() { }", 1842 "function yield() { }",
1791 "function foo(yield) { }", 1843 "function foo(yield) { }",
1792 "function foo(bar, yield) { }", 1844 "function foo(bar, yield) { }",
1845 "(yield) => { }",
1846 "(bar, yield) => { }",
1793 "yield = 1;", 1847 "yield = 1;",
1794 "var foo = yield = 1;", 1848 "var foo = yield = 1;",
1795 "++yield;", 1849 "++yield;",
1796 "yield++;", 1850 "yield++;",
1797 NULL 1851 NULL
1798 }; 1852 };
1799 1853
1854 i::FLAG_harmony_arrow_functions = true;
1800 RunParserSyncTest(context_data, statement_data, kError); 1855 RunParserSyncTest(context_data, statement_data, kError);
1801 } 1856 }
1802 1857
1803 1858
1804 TEST(NoErrorsYield) { 1859 TEST(NoErrorsYield) {
1805 const char* context_data[][2] = { 1860 const char* context_data[][2] = {
1806 { "function * is_gen() {", "}" }, 1861 { "function * is_gen() {", "}" },
1807 { NULL, NULL } 1862 { NULL, NULL }
1808 }; 1863 };
1809 1864
1810 const char* statement_data[] = { 1865 const char* statement_data[] = {
1811 "yield 2;", // this is legal inside generator 1866 "yield 2;", // this is legal inside generator
1812 "yield * 2;", // this is legal inside generator 1867 "yield * 2;", // this is legal inside generator
1813 NULL 1868 NULL
1814 }; 1869 };
1815 1870
1816 // This test requires kAllowGenerators to succeed. 1871 // This test requires kAllowGenerators to succeed.
1817 static const ParserFlag always_true_flags[] = { 1872 static const ParserFlag always_true_flags[] = {
1818 kAllowGenerators 1873 kAllowGenerators
1819 }; 1874 };
1875 i::FLAG_harmony_arrow_functions = true;
1820 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 1876 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1821 always_true_flags, 1); 1877 always_true_flags, 1);
1822 } 1878 }
1823 1879
1824 1880
1825 TEST(ErrorsNameOfStrictFunction) { 1881 TEST(ErrorsNameOfStrictFunction) {
1826 // Tests that illegal tokens as names of a strict function produce the correct 1882 // Tests that illegal tokens as names of a strict function produce the correct
1827 // errors. 1883 // errors.
1828 const char* context_data[][2] = { 1884 const char* context_data[][2] = {
1829 { "", ""}, 1885 { "", ""},
1830 { "\"use strict\";", ""}, 1886 { "\"use strict\";", ""},
1831 { NULL, NULL } 1887 { NULL, NULL }
1832 }; 1888 };
1833 1889
1834 const char* statement_data[] = { 1890 const char* statement_data[] = {
1835 "function eval() {\"use strict\";}", 1891 "function eval() {\"use strict\";}",
1836 "function arguments() {\"use strict\";}", 1892 "function arguments() {\"use strict\";}",
1837 "function interface() {\"use strict\";}", 1893 "function interface() {\"use strict\";}",
1838 "function yield() {\"use strict\";}", 1894 "function yield() {\"use strict\";}",
1839 // Future reserved words are always illegal 1895 // Future reserved words are always illegal
1840 "function super() { }", 1896 "function super() { }",
1841 "function super() {\"use strict\";}", 1897 "function super() {\"use strict\";}",
1842 NULL 1898 NULL
1843 }; 1899 };
1844 1900
1901 i::FLAG_harmony_arrow_functions = true;
1845 RunParserSyncTest(context_data, statement_data, kError); 1902 RunParserSyncTest(context_data, statement_data, kError);
1846 } 1903 }
1847 1904
1848 1905
1849 TEST(NoErrorsNameOfStrictFunction) { 1906 TEST(NoErrorsNameOfStrictFunction) {
1850 const char* context_data[][2] = { 1907 const char* context_data[][2] = {
1851 { "", ""}, 1908 { "", ""},
1852 { NULL, NULL } 1909 { NULL, NULL }
1853 }; 1910 };
1854 1911
1855 const char* statement_data[] = { 1912 const char* statement_data[] = {
1856 "function eval() { }", 1913 "function eval() { }",
1857 "function arguments() { }", 1914 "function arguments() { }",
1858 "function interface() { }", 1915 "function interface() { }",
1859 "function yield() { }", 1916 "function yield() { }",
1860 NULL 1917 NULL
1861 }; 1918 };
1862 1919
1920 i::FLAG_harmony_arrow_functions = true;
1863 RunParserSyncTest(context_data, statement_data, kSuccess); 1921 RunParserSyncTest(context_data, statement_data, kSuccess);
1864 } 1922 }
1865 1923
1866 1924
1867 1925
1868 TEST(ErrorsIllegalWordsAsLabelsSloppy) { 1926 TEST(ErrorsIllegalWordsAsLabelsSloppy) {
1869 // Using future reserved words as labels is always an error. 1927 // Using future reserved words as labels is always an error.
1870 const char* context_data[][2] = { 1928 const char* context_data[][2] = {
1871 { "", ""}, 1929 { "", ""},
1872 { "function test_func() {", "}" }, 1930 { "function test_func() {", "}" },
1931 { "() => {", "}" },
1873 { NULL, NULL } 1932 { NULL, NULL }
1874 }; 1933 };
1875 1934
1876 const char* statement_data[] = { 1935 const char* statement_data[] = {
1877 "super: while(true) { break super; }", 1936 "super: while(true) { break super; }",
1878 NULL 1937 NULL
1879 }; 1938 };
1880 1939
1881 RunParserSyncTest(context_data, statement_data, kError); 1940 RunParserSyncTest(context_data, statement_data, kError);
1882 } 1941 }
1883 1942
1884 1943
1885 TEST(ErrorsIllegalWordsAsLabelsStrict) { 1944 TEST(ErrorsIllegalWordsAsLabelsStrict) {
1886 // Tests that illegal tokens as labels produce the correct errors. 1945 // Tests that illegal tokens as labels produce the correct errors.
1887 const char* context_data[][2] = { 1946 const char* context_data[][2] = {
1888 { "\"use strict\";", "" }, 1947 { "\"use strict\";", "" },
1889 { "function test_func() {\"use strict\"; ", "}"}, 1948 { "function test_func() {\"use strict\"; ", "}"},
1949 { "() => {\"use strict\"; ", "}" },
1890 { NULL, NULL } 1950 { NULL, NULL }
1891 }; 1951 };
1892 1952
1893 const char* statement_data[] = { 1953 const char* statement_data[] = {
1894 "super: while(true) { break super; }", 1954 "super: while(true) { break super; }",
1895 "interface: while(true) { break interface; }", 1955 "interface: while(true) { break interface; }",
1896 "yield: while(true) { break yield; }", 1956 "yield: while(true) { break yield; }",
1897 NULL 1957 NULL
1898 }; 1958 };
1899 1959
1900 RunParserSyncTest(context_data, statement_data, kError); 1960 RunParserSyncTest(context_data, statement_data, kError);
1901 } 1961 }
1902 1962
1903 1963
1904 TEST(NoErrorsIllegalWordsAsLabels) { 1964 TEST(NoErrorsIllegalWordsAsLabels) {
1905 // Using eval and arguments as labels is legal even in strict mode. 1965 // Using eval and arguments as labels is legal even in strict mode.
1906 const char* context_data[][2] = { 1966 const char* context_data[][2] = {
1907 { "", ""}, 1967 { "", ""},
1908 { "function test_func() {", "}" }, 1968 { "function test_func() {", "}" },
1969 { "() => {", "}" },
1909 { "\"use strict\";", "" }, 1970 { "\"use strict\";", "" },
1910 { "\"use strict\"; function test_func() {", "}" }, 1971 { "\"use strict\"; function test_func() {", "}" },
1972 { "\"use strict\"; () => {", "}" },
1911 { NULL, NULL } 1973 { NULL, NULL }
1912 }; 1974 };
1913 1975
1914 const char* statement_data[] = { 1976 const char* statement_data[] = {
1915 "mylabel: while(true) { break mylabel; }", 1977 "mylabel: while(true) { break mylabel; }",
1916 "eval: while(true) { break eval; }", 1978 "eval: while(true) { break eval; }",
1917 "arguments: while(true) { break arguments; }", 1979 "arguments: while(true) { break arguments; }",
1918 NULL 1980 NULL
1919 }; 1981 };
1920 1982
1921 RunParserSyncTest(context_data, statement_data, kSuccess); 1983 static const ParserFlag always_flags[] = { kAllowArrowFunctions };
1984 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
1985 always_flags, ARRAY_SIZE(always_flags));
1922 } 1986 }
1923 1987
1924 1988
1925 TEST(ErrorsParenthesizedLabels) { 1989 TEST(ErrorsParenthesizedLabels) {
1926 // Parenthesized identifiers shouldn't be recognized as labels. 1990 // Parenthesized identifiers shouldn't be recognized as labels.
1927 const char* context_data[][2] = { 1991 const char* context_data[][2] = {
1928 { "", ""}, 1992 { "", ""},
1929 { "function test_func() {", "}" }, 1993 { "function test_func() {", "}" },
1994 { "() => {", "}" },
1930 { NULL, NULL } 1995 { NULL, NULL }
1931 }; 1996 };
1932 1997
1933 const char* statement_data[] = { 1998 const char* statement_data[] = {
1934 "(mylabel): while(true) { break mylabel; }", 1999 "(mylabel): while(true) { break mylabel; }",
1935 NULL 2000 NULL
1936 }; 2001 };
1937 2002
1938 RunParserSyncTest(context_data, statement_data, kError); 2003 RunParserSyncTest(context_data, statement_data, kError);
1939 } 2004 }
1940 2005
1941 2006
1942 TEST(NoErrorsParenthesizedDirectivePrologue) { 2007 TEST(NoErrorsParenthesizedDirectivePrologue) {
1943 // Parenthesized directive prologue shouldn't be recognized. 2008 // Parenthesized directive prologue shouldn't be recognized.
1944 const char* context_data[][2] = { 2009 const char* context_data[][2] = {
1945 { "", ""}, 2010 { "", ""},
1946 { NULL, NULL } 2011 { NULL, NULL }
1947 }; 2012 };
1948 2013
1949 const char* statement_data[] = { 2014 const char* statement_data[] = {
1950 "(\"use strict\"); var eval;", 2015 "(\"use strict\"); var eval;",
1951 NULL 2016 NULL
1952 }; 2017 };
1953 2018
2019 i::FLAG_harmony_arrow_functions = true;
1954 RunParserSyncTest(context_data, statement_data, kSuccess); 2020 RunParserSyncTest(context_data, statement_data, kSuccess);
1955 } 2021 }
1956 2022
1957 2023
1958 TEST(ErrorsNotAnIdentifierName) { 2024 TEST(ErrorsNotAnIdentifierName) {
1959 const char* context_data[][2] = { 2025 const char* context_data[][2] = {
1960 { "", ""}, 2026 { "", ""},
1961 { "\"use strict\";", ""}, 2027 { "\"use strict\";", ""},
1962 { NULL, NULL } 2028 { NULL, NULL }
1963 }; 2029 };
1964 2030
1965 const char* statement_data[] = { 2031 const char* statement_data[] = {
1966 "var foo = {}; foo.{;", 2032 "var foo = {}; foo.{;",
1967 "var foo = {}; foo.};", 2033 "var foo = {}; foo.};",
1968 "var foo = {}; foo.=;", 2034 "var foo = {}; foo.=;",
1969 "var foo = {}; foo.888;", 2035 "var foo = {}; foo.888;",
1970 "var foo = {}; foo.-;", 2036 "var foo = {}; foo.-;",
1971 "var foo = {}; foo.--;", 2037 "var foo = {}; foo.--;",
1972 NULL 2038 NULL
1973 }; 2039 };
1974 2040
2041 i::FLAG_harmony_arrow_functions = true;
1975 RunParserSyncTest(context_data, statement_data, kError); 2042 RunParserSyncTest(context_data, statement_data, kError);
1976 } 2043 }
1977 2044
1978 2045
1979 TEST(NoErrorsIdentifierNames) { 2046 TEST(NoErrorsIdentifierNames) {
1980 // Keywords etc. are valid as property names. 2047 // Keywords etc. are valid as property names.
1981 const char* context_data[][2] = { 2048 const char* context_data[][2] = {
1982 { "", ""}, 2049 { "", ""},
1983 { "\"use strict\";", ""}, 2050 { "\"use strict\";", ""},
1984 { NULL, NULL } 2051 { NULL, NULL }
1985 }; 2052 };
1986 2053
1987 const char* statement_data[] = { 2054 const char* statement_data[] = {
1988 "var foo = {}; foo.if;", 2055 "var foo = {}; foo.if;",
1989 "var foo = {}; foo.yield;", 2056 "var foo = {}; foo.yield;",
1990 "var foo = {}; foo.super;", 2057 "var foo = {}; foo.super;",
1991 "var foo = {}; foo.interface;", 2058 "var foo = {}; foo.interface;",
1992 "var foo = {}; foo.eval;", 2059 "var foo = {}; foo.eval;",
1993 "var foo = {}; foo.arguments;", 2060 "var foo = {}; foo.arguments;",
1994 NULL 2061 NULL
1995 }; 2062 };
1996 2063
2064 i::FLAG_harmony_arrow_functions = true;
1997 RunParserSyncTest(context_data, statement_data, kSuccess); 2065 RunParserSyncTest(context_data, statement_data, kSuccess);
1998 } 2066 }
1999 2067
2000 2068
2001 TEST(DontRegressPreParserDataSizes) { 2069 TEST(DontRegressPreParserDataSizes) {
2002 // These tests make sure that Parser doesn't start producing less "preparse 2070 // These tests make sure that Parser doesn't start producing less "preparse
2003 // data" (data which the embedder can cache). 2071 // data" (data which the embedder can cache).
2004 v8::V8::Initialize(); 2072 v8::V8::Initialize();
2073 i::FLAG_harmony_arrow_functions = true;
2005 v8::Isolate* isolate = CcTest::isolate(); 2074 v8::Isolate* isolate = CcTest::isolate();
2006 v8::HandleScope handles(isolate); 2075 v8::HandleScope handles(isolate);
2007 2076
2008 int marker; 2077 int marker;
2009 CcTest::i_isolate()->stack_guard()->SetStackLimit( 2078 CcTest::i_isolate()->stack_guard()->SetStackLimit(
2010 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 2079 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
2011 2080
2012 struct TestCase { 2081 struct TestCase {
2013 const char* program; 2082 const char* program;
2014 int functions; 2083 int functions;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 const char* strict_statement_data[] = { 2147 const char* strict_statement_data[] = {
2079 "\"use strict\";", 2148 "\"use strict\";",
2080 NULL 2149 NULL
2081 }; 2150 };
2082 2151
2083 const char* non_strict_statement_data[] = { 2152 const char* non_strict_statement_data[] = {
2084 ";", 2153 ";",
2085 NULL 2154 NULL
2086 }; 2155 };
2087 2156
2157 i::FLAG_harmony_arrow_functions = true;
2088 RunParserSyncTest(context_data, strict_statement_data, kError); 2158 RunParserSyncTest(context_data, strict_statement_data, kError);
2089 RunParserSyncTest(context_data, non_strict_statement_data, kSuccess); 2159 RunParserSyncTest(context_data, non_strict_statement_data, kSuccess);
2090 } 2160 }
2091 2161
2092 2162
2093 TEST(ErrorsTryWithoutCatchOrFinally) { 2163 TEST(ErrorsTryWithoutCatchOrFinally) {
2094 const char* context_data[][2] = { 2164 const char* context_data[][2] = {
2095 {"", ""}, 2165 {"", ""},
2096 { NULL, NULL } 2166 { NULL, NULL }
2097 }; 2167 };
2098 2168
2099 const char* statement_data[] = { 2169 const char* statement_data[] = {
2100 "try { }", 2170 "try { }",
2101 "try { } foo();", 2171 "try { } foo();",
2102 "try { } catch (e) foo();", 2172 "try { } catch (e) foo();",
2103 "try { } catch { }", 2173 "try { } catch { }",
2104 "try { } finally foo();", 2174 "try { } finally foo();",
2105 NULL 2175 NULL
2106 }; 2176 };
2107 2177
2178 i::FLAG_harmony_arrow_functions = true;
2108 RunParserSyncTest(context_data, statement_data, kError); 2179 RunParserSyncTest(context_data, statement_data, kError);
2109 } 2180 }
2110 2181
2111 2182
2112 TEST(NoErrorsTryCatchFinally) { 2183 TEST(NoErrorsTryCatchFinally) {
2113 const char* context_data[][2] = { 2184 const char* context_data[][2] = {
2114 {"", ""}, 2185 {"", ""},
2115 { NULL, NULL } 2186 { NULL, NULL }
2116 }; 2187 };
2117 2188
2118 const char* statement_data[] = { 2189 const char* statement_data[] = {
2119 "try { } catch (e) { }", 2190 "try { } catch (e) { }",
2120 "try { } catch (e) { } finally { }", 2191 "try { } catch (e) { } finally { }",
2121 "try { } finally { }", 2192 "try { } finally { }",
2122 NULL 2193 NULL
2123 }; 2194 };
2124 2195
2196 i::FLAG_harmony_arrow_functions = true;
2125 RunParserSyncTest(context_data, statement_data, kSuccess); 2197 RunParserSyncTest(context_data, statement_data, kSuccess);
2126 } 2198 }
2127 2199
2128 2200
2129 TEST(ErrorsRegexpLiteral) { 2201 TEST(ErrorsRegexpLiteral) {
2130 const char* context_data[][2] = { 2202 const char* context_data[][2] = {
2131 {"var r = ", ""}, 2203 {"var r = ", ""},
2132 { NULL, NULL } 2204 { NULL, NULL }
2133 }; 2205 };
2134 2206
2135 const char* statement_data[] = { 2207 const char* statement_data[] = {
2136 "/unterminated", 2208 "/unterminated",
2137 NULL 2209 NULL
2138 }; 2210 };
2139 2211
2212 i::FLAG_harmony_arrow_functions = true;
2140 RunParserSyncTest(context_data, statement_data, kError); 2213 RunParserSyncTest(context_data, statement_data, kError);
2141 } 2214 }
2142 2215
2143 2216
2144 TEST(NoErrorsRegexpLiteral) { 2217 TEST(NoErrorsRegexpLiteral) {
2145 const char* context_data[][2] = { 2218 const char* context_data[][2] = {
2146 {"var r = ", ""}, 2219 {"var r = ", ""},
2147 { NULL, NULL } 2220 { NULL, NULL }
2148 }; 2221 };
2149 2222
2150 const char* statement_data[] = { 2223 const char* statement_data[] = {
2151 "/foo/", 2224 "/foo/",
2152 "/foo/g", 2225 "/foo/g",
2153 "/foo/whatever", // This is an error but not detected by the parser. 2226 "/foo/whatever", // This is an error but not detected by the parser.
2154 NULL 2227 NULL
2155 }; 2228 };
2156 2229
2230 i::FLAG_harmony_arrow_functions = true;
2157 RunParserSyncTest(context_data, statement_data, kSuccess); 2231 RunParserSyncTest(context_data, statement_data, kSuccess);
2158 } 2232 }
2159 2233
2160 2234
2161 TEST(Intrinsics) { 2235 TEST(Intrinsics) {
2162 const char* context_data[][2] = { 2236 const char* context_data[][2] = {
2163 {"", ""}, 2237 {"", ""},
2164 { NULL, NULL } 2238 { NULL, NULL }
2165 }; 2239 };
2166 2240
2167 const char* statement_data[] = { 2241 const char* statement_data[] = {
2168 "%someintrinsic(arg)", 2242 "%someintrinsic(arg)",
2169 NULL 2243 NULL
2170 }; 2244 };
2171 2245
2172 // This test requires kAllowNativesSyntax to succeed. 2246 // This test requires kAllowNativesSyntax to succeed.
2173 static const ParserFlag always_true_flags[] = { 2247 static const ParserFlag always_true_flags[] = {
2174 kAllowNativesSyntax 2248 kAllowNativesSyntax
2175 }; 2249 };
2176 2250
2251 i::FLAG_harmony_arrow_functions = true;
2177 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 2252 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2178 always_true_flags, 1); 2253 always_true_flags, 1);
2254 RunParserSyncTest(context_data, statement_data, kSuccessOrError);
2179 } 2255 }
2180 2256
2181 2257
2182 TEST(NoErrorsNewExpression) { 2258 TEST(NoErrorsNewExpression) {
2183 const char* context_data[][2] = { 2259 const char* context_data[][2] = {
2184 {"", ""}, 2260 {"", ""},
2185 {"var f =", ""}, 2261 {"var f =", ""},
2186 { NULL, NULL } 2262 { NULL, NULL }
2187 }; 2263 };
2188 2264
(...skipping 18 matching lines...) Expand all
2207 "new foo[bar]()[baz];", 2283 "new foo[bar]()[baz];",
2208 "new foo[bar].baz(baz)()[bar].baz;", 2284 "new foo[bar].baz(baz)()[bar].baz;",
2209 "new \"foo\"", // Runtime error 2285 "new \"foo\"", // Runtime error
2210 "new 1", // Runtime error 2286 "new 1", // Runtime error
2211 // This even runs: 2287 // This even runs:
2212 "(new new Function(\"this.x = 1\")).x;", 2288 "(new new Function(\"this.x = 1\")).x;",
2213 "new new Test_Two(String, 2).v(0123).length;", 2289 "new new Test_Two(String, 2).v(0123).length;",
2214 NULL 2290 NULL
2215 }; 2291 };
2216 2292
2293 i::FLAG_harmony_arrow_functions = true;
2217 RunParserSyncTest(context_data, statement_data, kSuccess); 2294 RunParserSyncTest(context_data, statement_data, kSuccess);
2218 } 2295 }
2219 2296
2220 2297
2221 TEST(ErrorsNewExpression) { 2298 TEST(ErrorsNewExpression) {
2222 const char* context_data[][2] = { 2299 const char* context_data[][2] = {
2223 {"", ""}, 2300 {"", ""},
2224 {"var f =", ""}, 2301 {"var f =", ""},
2225 { NULL, NULL } 2302 { NULL, NULL }
2226 }; 2303 };
2227 2304
2228 const char* statement_data[] = { 2305 const char* statement_data[] = {
2229 "new foo bar", 2306 "new foo bar",
2230 "new ) foo", 2307 "new ) foo",
2231 "new ++foo", 2308 "new ++foo",
2232 "new foo ++", 2309 "new foo ++",
2233 NULL 2310 NULL
2234 }; 2311 };
2235 2312
2313 i::FLAG_harmony_arrow_functions = true;
2236 RunParserSyncTest(context_data, statement_data, kError); 2314 RunParserSyncTest(context_data, statement_data, kError);
2237 } 2315 }
2238 2316
2239 2317
2240 TEST(StrictObjectLiteralChecking) { 2318 TEST(StrictObjectLiteralChecking) {
2241 const char* strict_context_data[][2] = { 2319 const char* strict_context_data[][2] = {
2242 {"\"use strict\"; var myobject = {", "};"}, 2320 {"\"use strict\"; var myobject = {", "};"},
2243 {"\"use strict\"; var myobject = {", ",};"}, 2321 {"\"use strict\"; var myobject = {", ",};"},
2244 { NULL, NULL } 2322 { NULL, NULL }
2245 }; 2323 };
2246 const char* non_strict_context_data[][2] = { 2324 const char* non_strict_context_data[][2] = {
2247 {"var myobject = {", "};"}, 2325 {"var myobject = {", "};"},
2248 {"var myobject = {", ",};"}, 2326 {"var myobject = {", ",};"},
2249 { NULL, NULL } 2327 { NULL, NULL }
2250 }; 2328 };
2251 2329
2252 // These are only errors in strict mode. 2330 // These are only errors in strict mode.
2253 const char* statement_data[] = { 2331 const char* statement_data[] = {
2254 "foo: 1, foo: 2", 2332 "foo: 1, foo: 2",
2255 "\"foo\": 1, \"foo\": 2", 2333 "\"foo\": 1, \"foo\": 2",
2256 "foo: 1, \"foo\": 2", 2334 "foo: 1, \"foo\": 2",
2257 "1: 1, 1: 2", 2335 "1: 1, 1: 2",
2258 "1: 1, \"1\": 2", 2336 "1: 1, \"1\": 2",
2259 "get: 1, get: 2", // Not a getter for real, just a property called get. 2337 "get: 1, get: 2", // Not a getter for real, just a property called get.
2260 "set: 1, set: 2", // Not a setter for real, just a property called set. 2338 "set: 1, set: 2", // Not a setter for real, just a property called set.
2261 NULL 2339 NULL
2262 }; 2340 };
2263 2341
2342 i::FLAG_harmony_arrow_functions = true;
2264 RunParserSyncTest(non_strict_context_data, statement_data, kSuccess); 2343 RunParserSyncTest(non_strict_context_data, statement_data, kSuccess);
2265 RunParserSyncTest(strict_context_data, statement_data, kError); 2344 RunParserSyncTest(strict_context_data, statement_data, kError);
2266 } 2345 }
2267 2346
2268 2347
2269 TEST(ErrorsObjectLiteralChecking) { 2348 TEST(ErrorsObjectLiteralChecking) {
2270 const char* context_data[][2] = { 2349 const char* context_data[][2] = {
2271 {"\"use strict\"; var myobject = {", "};"}, 2350 {"\"use strict\"; var myobject = {", "};"},
2272 {"var myobject = {", "};"}, 2351 {"var myobject = {", "};"},
2273 { NULL, NULL } 2352 { NULL, NULL }
(...skipping 22 matching lines...) Expand all
2296 "get bar(x) {}", 2375 "get bar(x) {}",
2297 "get bar(x, y) {}", 2376 "get bar(x, y) {}",
2298 "set bar() {}", 2377 "set bar() {}",
2299 "set bar(x, y) {}", 2378 "set bar(x, y) {}",
2300 // Parsing FunctionLiteral for getter or setter fails 2379 // Parsing FunctionLiteral for getter or setter fails
2301 "get foo( +", 2380 "get foo( +",
2302 "get foo() \"error\"", 2381 "get foo() \"error\"",
2303 NULL 2382 NULL
2304 }; 2383 };
2305 2384
2385 i::FLAG_harmony_arrow_functions = true;
2306 RunParserSyncTest(context_data, statement_data, kError); 2386 RunParserSyncTest(context_data, statement_data, kError);
2307 } 2387 }
2308 2388
2309 2389
2310 TEST(NoErrorsObjectLiteralChecking) { 2390 TEST(NoErrorsObjectLiteralChecking) {
2311 const char* context_data[][2] = { 2391 const char* context_data[][2] = {
2312 {"var myobject = {", "};"}, 2392 {"var myobject = {", "};"},
2313 {"var myobject = {", ",};"}, 2393 {"var myobject = {", ",};"},
2314 {"\"use strict\"; var myobject = {", "};"}, 2394 {"\"use strict\"; var myobject = {", "};"},
2315 {"\"use strict\"; var myobject = {", ",};"}, 2395 {"\"use strict\"; var myobject = {", ",};"},
(...skipping 25 matching lines...) Expand all
2341 // Keywords, future reserved and strict future reserved are also allowed as 2421 // Keywords, future reserved and strict future reserved are also allowed as
2342 // property names. 2422 // property names.
2343 "if: 4", 2423 "if: 4",
2344 "interface: 5", 2424 "interface: 5",
2345 "super: 6", 2425 "super: 6",
2346 "eval: 7", 2426 "eval: 7",
2347 "arguments: 8", 2427 "arguments: 8",
2348 NULL 2428 NULL
2349 }; 2429 };
2350 2430
2431 i::FLAG_harmony_arrow_functions = true;
2351 RunParserSyncTest(context_data, statement_data, kSuccess); 2432 RunParserSyncTest(context_data, statement_data, kSuccess);
2352 } 2433 }
2353 2434
2354 2435
2355 TEST(TooManyArguments) { 2436 TEST(TooManyArguments) {
2356 const char* context_data[][2] = { 2437 const char* context_data[][2] = {
2357 {"foo(", "0)"}, 2438 {"foo(", "0)"},
2358 { NULL, NULL } 2439 { NULL, NULL }
2359 }; 2440 };
2360 2441
2361 using v8::internal::Code; 2442 using v8::internal::Code;
2362 char statement[Code::kMaxArguments * 2 + 1]; 2443 char statement[Code::kMaxArguments * 2 + 1];
2363 for (int i = 0; i < Code::kMaxArguments; ++i) { 2444 for (int i = 0; i < Code::kMaxArguments; ++i) {
2364 statement[2 * i] = '0'; 2445 statement[2 * i] = '0';
2365 statement[2 * i + 1] = ','; 2446 statement[2 * i + 1] = ',';
2366 } 2447 }
2367 statement[Code::kMaxArguments * 2] = 0; 2448 statement[Code::kMaxArguments * 2] = 0;
2368 2449
2369 const char* statement_data[] = { 2450 const char* statement_data[] = {
2370 statement, 2451 statement,
2371 NULL 2452 NULL
2372 }; 2453 };
2373 2454
2374 // The test is quite slow, so run it with a reduced set of flags. 2455 // The test is quite slow, so run it with a reduced set of flags.
2456 i::FLAG_harmony_arrow_functions = true;
2375 static const ParserFlag empty_flags[] = {kAllowLazy}; 2457 static const ParserFlag empty_flags[] = {kAllowLazy};
2376 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1); 2458 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1);
2377 } 2459 }
2378 2460
2379 2461
2380 TEST(StrictDelete) { 2462 TEST(StrictDelete) {
2381 // "delete <Identifier>" is not allowed in strict mode. 2463 // "delete <Identifier>" is not allowed in strict mode.
2382 const char* strict_context_data[][2] = { 2464 const char* strict_context_data[][2] = {
2383 {"\"use strict\"; ", ""}, 2465 {"\"use strict\"; ", ""},
2384 { NULL, NULL } 2466 { NULL, NULL }
(...skipping 28 matching lines...) Expand all
2413 "delete new foo(bar);", 2495 "delete new foo(bar);",
2414 NULL 2496 NULL
2415 }; 2497 };
2416 2498
2417 // These are always errors 2499 // These are always errors
2418 const char* bad_statement_data[] = { 2500 const char* bad_statement_data[] = {
2419 "delete if;", 2501 "delete if;",
2420 NULL 2502 NULL
2421 }; 2503 };
2422 2504
2505 i::FLAG_harmony_arrow_functions = true;
2506
2423 RunParserSyncTest(strict_context_data, sloppy_statement_data, kError); 2507 RunParserSyncTest(strict_context_data, sloppy_statement_data, kError);
2424 RunParserSyncTest(sloppy_context_data, sloppy_statement_data, kSuccess); 2508 RunParserSyncTest(sloppy_context_data, sloppy_statement_data, kSuccess);
2425 2509
2426 RunParserSyncTest(strict_context_data, good_statement_data, kSuccess); 2510 RunParserSyncTest(strict_context_data, good_statement_data, kSuccess);
2427 RunParserSyncTest(sloppy_context_data, good_statement_data, kSuccess); 2511 RunParserSyncTest(sloppy_context_data, good_statement_data, kSuccess);
2428 2512
2429 RunParserSyncTest(strict_context_data, bad_statement_data, kError); 2513 RunParserSyncTest(strict_context_data, bad_statement_data, kError);
2430 RunParserSyncTest(sloppy_context_data, bad_statement_data, kError); 2514 RunParserSyncTest(sloppy_context_data, bad_statement_data, kError);
2431 } 2515 }
2432 2516
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2489 }; 2573 };
2490 2574
2491 // These are not okay for assignment, but okay for prefix / postix. 2575 // These are not okay for assignment, but okay for prefix / postix.
2492 const char* bad_statement_data_for_assignment[] = { 2576 const char* bad_statement_data_for_assignment[] = {
2493 "++foo", 2577 "++foo",
2494 "foo++", 2578 "foo++",
2495 "foo + bar", 2579 "foo + bar",
2496 NULL 2580 NULL
2497 }; 2581 };
2498 2582
2583 i::FLAG_harmony_arrow_functions = true;
2584
2499 RunParserSyncTest(assignment_context_data, good_statement_data, kSuccess); 2585 RunParserSyncTest(assignment_context_data, good_statement_data, kSuccess);
2500 RunParserSyncTest(assignment_context_data, bad_statement_data_common, kError); 2586 RunParserSyncTest(assignment_context_data, bad_statement_data_common, kError);
2501 RunParserSyncTest(assignment_context_data, bad_statement_data_for_assignment, 2587 RunParserSyncTest(assignment_context_data, bad_statement_data_for_assignment,
2502 kError); 2588 kError);
2503 2589
2504 RunParserSyncTest(prefix_context_data, good_statement_data, kSuccess); 2590 RunParserSyncTest(prefix_context_data, good_statement_data, kSuccess);
2505 RunParserSyncTest(prefix_context_data, bad_statement_data_common, kError); 2591 RunParserSyncTest(prefix_context_data, bad_statement_data_common, kError);
2506 2592
2507 RunParserSyncTest(postfix_context_data, good_statement_data, kSuccess); 2593 RunParserSyncTest(postfix_context_data, good_statement_data, kSuccess);
2508 RunParserSyncTest(postfix_context_data, bad_statement_data_common, kError); 2594 RunParserSyncTest(postfix_context_data, bad_statement_data_common, kError);
2509 } 2595 }
2510 2596
2511 2597
2512 TEST(FuncNameInferrerBasic) { 2598 TEST(FuncNameInferrerBasic) {
2513 // Tests that function names are inferred properly. 2599 // Tests that function names are inferred properly.
2514 i::FLAG_allow_natives_syntax = true; 2600 i::FLAG_allow_natives_syntax = true;
2601 i::FLAG_harmony_arrow_functions = true;
2515 v8::Isolate* isolate = CcTest::isolate(); 2602 v8::Isolate* isolate = CcTest::isolate();
2516 v8::HandleScope scope(isolate); 2603 v8::HandleScope scope(isolate);
2517 LocalContext env; 2604 LocalContext env;
2518 CompileRun("var foo1 = function() {}; " 2605 CompileRun("var foo1 = function() {}; "
2519 "var foo2 = function foo3() {}; " 2606 "var foo2 = function foo3() {}; "
2520 "function not_ctor() { " 2607 "function not_ctor() { "
2521 " var foo4 = function() {}; " 2608 " var foo4 = function() {}; "
2522 " return %FunctionGetInferredName(foo4); " 2609 " return %FunctionGetInferredName(foo4); "
2523 "} " 2610 "} "
2524 "function Ctor() { " 2611 "function Ctor() { "
(...skipping 21 matching lines...) Expand all
2546 ExpectString("%FunctionGetInferredName(obj4[1])", ""); 2633 ExpectString("%FunctionGetInferredName(obj4[1])", "");
2547 ExpectString("%FunctionGetInferredName(obj5['foo9'])", "obj5.foo9"); 2634 ExpectString("%FunctionGetInferredName(obj5['foo9'])", "obj5.foo9");
2548 ExpectString("%FunctionGetInferredName(obj6.obj7.foo10)", "obj6.obj7.foo10"); 2635 ExpectString("%FunctionGetInferredName(obj6.obj7.foo10)", "obj6.obj7.foo10");
2549 } 2636 }
2550 2637
2551 2638
2552 TEST(FuncNameInferrerTwoByte) { 2639 TEST(FuncNameInferrerTwoByte) {
2553 // Tests function name inferring in cases where some parts of the inferred 2640 // Tests function name inferring in cases where some parts of the inferred
2554 // function name are two-byte strings. 2641 // function name are two-byte strings.
2555 i::FLAG_allow_natives_syntax = true; 2642 i::FLAG_allow_natives_syntax = true;
2643 i::FLAG_harmony_arrow_functions = true;
2556 v8::Isolate* isolate = CcTest::isolate(); 2644 v8::Isolate* isolate = CcTest::isolate();
2557 v8::HandleScope scope(isolate); 2645 v8::HandleScope scope(isolate);
2558 LocalContext env; 2646 LocalContext env;
2559 uint16_t* two_byte_source = AsciiToTwoByteString( 2647 uint16_t* two_byte_source = AsciiToTwoByteString(
2560 "var obj1 = { oXj2 : { foo1: function() {} } }; " 2648 "var obj1 = { oXj2 : { foo1: function() {} } }; "
2561 "%FunctionGetInferredName(obj1.oXj2.foo1)"); 2649 "%FunctionGetInferredName(obj1.oXj2.foo1)");
2562 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1"); 2650 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1");
2563 // Make it really non-ASCII (replace the Xs with a non-ASCII character). 2651 // Make it really non-ASCII (replace the Xs with a non-ASCII character).
2564 two_byte_source[14] = two_byte_source[78] = two_byte_name[6] = 0x010d; 2652 two_byte_source[14] = two_byte_source[78] = two_byte_name[6] = 0x010d;
2565 v8::Local<v8::String> source = 2653 v8::Local<v8::String> source =
2566 v8::String::NewFromTwoByte(isolate, two_byte_source); 2654 v8::String::NewFromTwoByte(isolate, two_byte_source);
2567 v8::Local<v8::Value> result = CompileRun(source); 2655 v8::Local<v8::Value> result = CompileRun(source);
2568 CHECK(result->IsString()); 2656 CHECK(result->IsString());
2569 v8::Local<v8::String> expected_name = 2657 v8::Local<v8::String> expected_name =
2570 v8::String::NewFromTwoByte(isolate, two_byte_name); 2658 v8::String::NewFromTwoByte(isolate, two_byte_name);
2571 CHECK(result->Equals(expected_name)); 2659 CHECK(result->Equals(expected_name));
2572 i::DeleteArray(two_byte_source); 2660 i::DeleteArray(two_byte_source);
2573 i::DeleteArray(two_byte_name); 2661 i::DeleteArray(two_byte_name);
2574 } 2662 }
2575 2663
2576 2664
2577 TEST(FuncNameInferrerEscaped) { 2665 TEST(FuncNameInferrerEscaped) {
2578 // The same as FuncNameInferrerTwoByte, except that we express the two-byte 2666 // The same as FuncNameInferrerTwoByte, except that we express the two-byte
2579 // character as a unicode escape. 2667 // character as a unicode escape.
2580 i::FLAG_allow_natives_syntax = true; 2668 i::FLAG_allow_natives_syntax = true;
2669 i::FLAG_harmony_arrow_functions = true;
2581 v8::Isolate* isolate = CcTest::isolate(); 2670 v8::Isolate* isolate = CcTest::isolate();
2582 v8::HandleScope scope(isolate); 2671 v8::HandleScope scope(isolate);
2583 LocalContext env; 2672 LocalContext env;
2584 uint16_t* two_byte_source = AsciiToTwoByteString( 2673 uint16_t* two_byte_source = AsciiToTwoByteString(
2585 "var obj1 = { o\\u010dj2 : { foo1: function() {} } }; " 2674 "var obj1 = { o\\u010dj2 : { foo1: function() {} } }; "
2586 "%FunctionGetInferredName(obj1.o\\u010dj2.foo1)"); 2675 "%FunctionGetInferredName(obj1.o\\u010dj2.foo1)");
2587 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1"); 2676 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1");
2588 // Fix to correspond to the non-ASCII name in two_byte_source. 2677 // Fix to correspond to the non-ASCII name in two_byte_source.
2589 two_byte_name[6] = 0x010d; 2678 two_byte_name[6] = 0x010d;
2590 v8::Local<v8::String> source = 2679 v8::Local<v8::String> source =
(...skipping 16 matching lines...) Expand all
2607 v8::Isolate* isolate = CcTest::isolate(); 2696 v8::Isolate* isolate = CcTest::isolate();
2608 v8::HandleScope scope(isolate); 2697 v8::HandleScope scope(isolate);
2609 LocalContext env; 2698 LocalContext env;
2610 i::FLAG_lazy = true; 2699 i::FLAG_lazy = true;
2611 i::FLAG_min_preparse_length = 0; 2700 i::FLAG_min_preparse_length = 0;
2612 CompileRun("function this_is_lazy() {\n" 2701 CompileRun("function this_is_lazy() {\n"
2613 " break p;\n" 2702 " break p;\n"
2614 "}\n" 2703 "}\n"
2615 "this_is_lazy();\n"); 2704 "this_is_lazy();\n");
2616 } 2705 }
2706
2707
2708 TEST(ErrorsArrowFunctions) {
2709 // Tests that parser and preparser generate the same kind of errors
2710 // on invalid arrow function syntax.
2711 const char* context_data[][2] = {
2712 {"", ";"},
2713 {"v = ", ";"},
2714 {"bar ? (", ") : baz;"},
2715 {"bar ? baz : (", ");"},
2716 {"bar[", "];"},
2717 {"bar, ", ";"},
2718 {"", ", bar;"},
2719 { NULL, NULL }
2720 };
2721
2722 const char* statement_data[] = {
2723 "=> 0",
2724 "=>",
2725 "() =>",
2726 "=> {}",
2727 ") => {}",
2728 ", => {}",
2729 "(,) => {}",
2730 "return => {}",
2731 "() => {'value': 42}",
2732
2733 // Check that the early return introduced in ParsePrimaryExpression
2734 // does not accept stray closing parentheses.
2735 ")",
2736 ") => 0",
2737 "foo[()]",
2738 "()",
2739
2740 // Parameter lists with extra parens should be recognized as errors.
2741 "(()) => 0",
2742 "((x)) => 0",
2743 "((x, y)) => 0",
2744 "(x, (y)) => 0",
2745 "((x, y, z)) => 0",
2746 "(x, (y, z)) => 0",
2747 "((x, y), z) => 0",
2748
2749 // Parameter lists are always validated as strict, so those are errors.
2750 "eval => {}",
2751 "arguments => {}",
2752 "yield => {}",
2753 "interface => {}",
2754 "(eval) => {}",
2755 "(arguments) => {}",
2756 "(yield) => {}",
2757 "(interface) => {}",
2758 "(eval, bar) => {}",
2759 "(bar, eval) => {}",
2760 "(bar, arguments) => {}",
2761 "(bar, yield) => {}",
2762 "(bar, interface) => {}",
2763 // TODO(aperez): Detecting duplicates does not work in PreParser.
2764 //"(bar, bar) => {}",
2765
2766 // The parameter list is parsed as an expression, but only
2767 // a comma-separated list of identifier is valid.
2768 "32 => {}",
2769 "(32) => {}",
2770 "(a, 32) => {}",
2771 "if => {}",
2772 "(if) => {}",
2773 "(a, if) => {}",
2774 "a + b => {}",
2775 "(a + b) => {}",
2776 "(a + b, c) => {}",
2777 "(a, b - c) => {}",
2778 "\"a\" => {}",
2779 "(\"a\") => {}",
2780 "(\"a\", b) => {}",
2781 "(a, \"b\") => {}",
2782 "-a => {}",
2783 "(-a) => {}",
2784 "(-a, b) => {}",
2785 "(a, -b) => {}",
2786 "{} => {}",
2787 "({}) => {}",
2788 "(a, {}) => {}",
2789 "({}, a) => {}",
2790 "a++ => {}",
2791 "(a++) => {}",
2792 "(a++, b) => {}",
2793 "(a, b++) => {}",
2794 "[] => {}",
2795 "([]) => {}",
2796 "(a, []) => {}",
2797 "([], a) => {}",
2798 "(a = b) => {}",
2799 "(a = b, c) => {}",
2800 "(a, b = c) => {}",
2801 "(foo ? bar : baz) => {}",
2802 "(a, foo ? bar : baz) => {}",
2803 "(foo ? bar : baz, a) => {}",
2804
2805 NULL
2806 };
2807
2808 RunParserSyncTest(context_data, statement_data, kError);
2809 }
2810
2811
2812 TEST(NoErrorsArrowFunctions) {
2813 // Tests that parser and preparser accept valid arrow functions syntax.
2814 const char* context_data[][2] = {
2815 {"", ";"},
2816 // TODO(aperez): Uncomment this when ParseArrowFunctionLiteral()
2817 // generates code and returns a non-NULL expression. Currently it
2818 // crashes when expression->set_is_parenthesized(true) is called.
2819 //{"bar ? (", ") : baz;"},
2820 //{"bar ? baz : (", ");"},
2821 {"bar, ", ";"},
2822 {"", ", bar;"},
2823 { NULL, NULL }
2824 };
2825
2826 const char* statement_data[] = {
2827 "() => {}",
2828 "() => { return 42 }",
2829 "x => { return x; }",
2830 "(x) => { return x; }",
2831 "(x, y) => { return x + y; }",
2832 "(x, y, z) => { return x + y + z; }",
2833 "(x, y) => { x.a = y; }",
2834 "() => 42",
2835 "x => x",
2836 "x => x * x",
2837 "(x) => x",
2838 "(x) => x * x",
2839 "(x, y) => x + y",
2840 "(x, y, z) => x, y, z",
2841 "(x, y) => x.a = y",
2842 "() => ({'value': 42})",
2843 "x => y => x + y",
2844 "(x, y) => (u, v) => x*u + y*v",
2845 "(x, y) => z => z * (x + y)",
2846 "x => (y, z) => z * (x + y)",
2847
2848 // Those are comma-separated expressions, with arrow functions as items.
2849 // They stress the code for validating arrow function parameter lists.
2850 "a, b => 0",
2851 "a, b, (c, d) => 0",
2852 "(a, b, (c, d) => 0)",
2853 "(a, b) => 0, (c, d) => 1",
2854 "(a, b => {}, a => a + 1)",
2855 // TODO(aperez): Uncomment this when ParseArrowFunctionLiteral()
2856 // generates code and returns a non-NULL expression. Currently it
2857 // crashes when expression->set_is_parenthesized(true) is called.
2858 //"((a, b) => {}, (a => a + 1))",
2859 //"(a, (a, (b, c) => 0))",
2860
2861 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {})
2862 "foo ? bar : baz => {}",
2863
2864 NULL
2865 };
2866
2867 static const ParserFlag always_flags[] = { kAllowArrowFunctions };
2868 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2869 always_flags, ARRAY_SIZE(always_flags));
2870 }
OLDNEW
« src/preparser.cc ('K') | « src/token.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698