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

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: Made tests more comprehensive Created 6 years, 6 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/scanner.h ('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;
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[] = {
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);
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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 " }", "\n" 978 " }", "\n"
961 " more;", i::BLOCK_SCOPE, i::STRICT }, 979 " more;", i::BLOCK_SCOPE, i::STRICT },
962 { " start;\n" 980 { " start;\n"
963 " function fun", "(a,b) { infunction; }", " more;", 981 " function fun", "(a,b) { infunction; }", " more;",
964 i::FUNCTION_SCOPE, i::SLOPPY }, 982 i::FUNCTION_SCOPE, i::SLOPPY },
965 { " start;\n" 983 { " start;\n"
966 " function fun", "(a,b) {\n" 984 " function fun", "(a,b) {\n"
967 " infunction;\n" 985 " infunction;\n"
968 " }", "\n" 986 " }", "\n"
969 " more;", i::FUNCTION_SCOPE, i::SLOPPY }, 987 " more;", i::FUNCTION_SCOPE, i::SLOPPY },
970 { " (function fun", "(a,b) { infunction; }", ")();", 988 // TODO(aperez): Change to use i::ARROW_SCOPE when implemented
989 { " start;\n", "(a,b) => a + b", "; more;",
990 i::FUNCTION_SCOPE, i::SLOPPY },
991 { " start;\n", "(a,b) => { return a+b; }", "\nmore;",
992 i::FUNCTION_SCOPE, i::SLOPPY },
993 { " start;\n"
994 " (function fun", "(a,b) { infunction; }", ")();",
971 i::FUNCTION_SCOPE, i::SLOPPY }, 995 i::FUNCTION_SCOPE, i::SLOPPY },
972 { " for ", "(let x = 1 ; x < 10; ++ x) { block; }", " more;", 996 { " for ", "(let x = 1 ; x < 10; ++ x) { block; }", " more;",
973 i::BLOCK_SCOPE, i::STRICT }, 997 i::BLOCK_SCOPE, i::STRICT },
974 { " for ", "(let x = 1 ; x < 10; ++ x) { block; }", "; more;", 998 { " for ", "(let x = 1 ; x < 10; ++ x) { block; }", "; more;",
975 i::BLOCK_SCOPE, i::STRICT }, 999 i::BLOCK_SCOPE, i::STRICT },
976 { " for ", "(let x = 1 ; x < 10; ++ x) {\n" 1000 { " for ", "(let x = 1 ; x < 10; ++ x) {\n"
977 " block;\n" 1001 " block;\n"
978 " }", "\n" 1002 " }", "\n"
979 " more;", i::BLOCK_SCOPE, i::STRICT }, 1003 " more;", i::BLOCK_SCOPE, i::STRICT },
980 { " for ", "(let x = 1 ; x < 10; ++ x) statement;", " more;", 1004 { " for ", "(let x = 1 ; x < 10; ++ x) statement;", " more;",
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 1139
1116 // Parse program source. 1140 // Parse program source.
1117 i::Handle<i::String> source = factory->NewStringFromUtf8( 1141 i::Handle<i::String> source = factory->NewStringFromUtf8(
1118 i::CStrVector(program.start())).ToHandleChecked(); 1142 i::CStrVector(program.start())).ToHandleChecked();
1119 CHECK_EQ(source->length(), kProgramSize); 1143 CHECK_EQ(source->length(), kProgramSize);
1120 i::Handle<i::Script> script = factory->NewScript(source); 1144 i::Handle<i::Script> script = factory->NewScript(source);
1121 i::CompilationInfoWithZone info(script); 1145 i::CompilationInfoWithZone info(script);
1122 i::Parser parser(&info); 1146 i::Parser parser(&info);
1123 parser.set_allow_lazy(true); 1147 parser.set_allow_lazy(true);
1124 parser.set_allow_harmony_scoping(true); 1148 parser.set_allow_harmony_scoping(true);
1149 parser.set_allow_arrow_functions(true);
1125 info.MarkAsGlobal(); 1150 info.MarkAsGlobal();
1126 info.SetStrictMode(source_data[i].strict_mode); 1151 info.SetStrictMode(source_data[i].strict_mode);
1127 parser.Parse(); 1152 parser.Parse();
1128 CHECK(info.function() != NULL); 1153 CHECK(info.function() != NULL);
1129 1154
1130 // Check scope types and positions. 1155 // Check scope types and positions.
1131 i::Scope* scope = info.function()->scope(); 1156 i::Scope* scope = info.function()->scope();
1132 CHECK(scope->is_global_scope()); 1157 CHECK(scope->is_global_scope());
1133 CHECK_EQ(scope->start_position(), 0); 1158 CHECK_EQ(scope->start_position(), 0);
1134 CHECK_EQ(scope->end_position(), kProgramSize); 1159 CHECK_EQ(scope->end_position(), kProgramSize);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 void SetParserFlags(i::ParserBase<Traits>* parser, 1217 void SetParserFlags(i::ParserBase<Traits>* parser,
1193 i::EnumSet<ParserFlag> flags) { 1218 i::EnumSet<ParserFlag> flags) {
1194 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1219 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1195 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); 1220 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax));
1196 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); 1221 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping));
1197 parser->set_allow_modules(flags.Contains(kAllowModules)); 1222 parser->set_allow_modules(flags.Contains(kAllowModules));
1198 parser->set_allow_generators(flags.Contains(kAllowGenerators)); 1223 parser->set_allow_generators(flags.Contains(kAllowGenerators));
1199 parser->set_allow_for_of(flags.Contains(kAllowForOf)); 1224 parser->set_allow_for_of(flags.Contains(kAllowForOf));
1200 parser->set_allow_harmony_numeric_literals( 1225 parser->set_allow_harmony_numeric_literals(
1201 flags.Contains(kAllowHarmonyNumericLiterals)); 1226 flags.Contains(kAllowHarmonyNumericLiterals));
1227 parser->set_allow_arrow_functions(i::FLAG_harmony_arrow_functions);
1202 } 1228 }
1203 1229
1204 1230
1205 void TestParserSyncWithFlags(i::Handle<i::String> source, 1231 void TestParserSyncWithFlags(i::Handle<i::String> source,
1206 i::EnumSet<ParserFlag> flags, 1232 i::EnumSet<ParserFlag> flags,
1207 ParserSyncTestResult result) { 1233 ParserSyncTestResult result) {
1208 i::Isolate* isolate = CcTest::i_isolate(); 1234 i::Isolate* isolate = CcTest::i_isolate();
1209 i::Factory* factory = isolate->factory(); 1235 i::Factory* factory = isolate->factory();
1210 1236
1211 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); 1237 uintptr_t stack_limit = isolate->stack_guard()->real_climit();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 i::EnumSet<ParserFlag> flags; 1336 i::EnumSet<ParserFlag> flags;
1311 for (size_t flag_index = 0; flag_index < flag_list_length; flag_index++) { 1337 for (size_t flag_index = 0; flag_index < flag_list_length; flag_index++) {
1312 if ((bits & (1 << flag_index)) != 0) flags.Add(flag_list[flag_index]); 1338 if ((bits & (1 << flag_index)) != 0) flags.Add(flag_list[flag_index]);
1313 } 1339 }
1314 TestParserSyncWithFlags(str, flags, result); 1340 TestParserSyncWithFlags(str, flags, result);
1315 } 1341 }
1316 } 1342 }
1317 1343
1318 1344
1319 TEST(ParserSync) { 1345 TEST(ParserSync) {
1346 i::FLAG_harmony_arrow_functions = true;
1347
1320 const char* context_data[][2] = { 1348 const char* context_data[][2] = {
1321 { "", "" }, 1349 { "", "" },
1322 { "{", "}" }, 1350 { "{", "}" },
1323 { "if (true) ", " else {}" }, 1351 { "if (true) ", " else {}" },
1324 { "if (true) {} else ", "" }, 1352 { "if (true) {} else ", "" },
1325 { "if (true) ", "" }, 1353 { "if (true) ", "" },
1326 { "do ", " while (false)" }, 1354 { "do ", " while (false)" },
1327 { "while (false) ", "" }, 1355 { "while (false) ", "" },
1328 { "for (;;) ", "" }, 1356 { "for (;;) ", "" },
1329 { "with ({})", "" }, 1357 { "with ({})", "" },
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 1459
1432 static const ParserFlag flags3[] = { kAllowNativesSyntax }; 1460 static const ParserFlag flags3[] = { kAllowNativesSyntax };
1433 TestParserSync("%DebugPrint(123)", flags3, ARRAY_SIZE(flags3)); 1461 TestParserSync("%DebugPrint(123)", flags3, ARRAY_SIZE(flags3));
1434 } 1462 }
1435 1463
1436 1464
1437 TEST(StrictOctal) { 1465 TEST(StrictOctal) {
1438 // Test that syntax error caused by octal literal is reported correctly as 1466 // Test that syntax error caused by octal literal is reported correctly as
1439 // such (issue 2220). 1467 // such (issue 2220).
1440 v8::V8::Initialize(); 1468 v8::V8::Initialize();
1469 i::FLAG_harmony_arrow_functions = true;
1470
1441 v8::HandleScope scope(CcTest::isolate()); 1471 v8::HandleScope scope(CcTest::isolate());
1442 v8::Context::Scope context_scope( 1472 v8::Context::Scope context_scope(
1443 v8::Context::New(CcTest::isolate())); 1473 v8::Context::New(CcTest::isolate()));
1444 v8::TryCatch try_catch; 1474 v8::TryCatch try_catch;
1445 const char* script = 1475 const char* script =
1446 "\"use strict\"; \n" 1476 "\"use strict\"; \n"
1447 "a = function() { \n" 1477 "a = function() { \n"
1448 " b = function() { \n" 1478 " b = function() { \n"
1449 " 01; \n" 1479 " 01; \n"
1450 " }; \n" 1480 " }; \n"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 "var foo, eval;", 1549 "var foo, eval;",
1520 "var foo, arguments;", 1550 "var foo, arguments;",
1521 "try { } catch (eval) { }", 1551 "try { } catch (eval) { }",
1522 "try { } catch (arguments) { }", 1552 "try { } catch (arguments) { }",
1523 "function eval() { }", 1553 "function eval() { }",
1524 "function arguments() { }", 1554 "function arguments() { }",
1525 "function foo(eval) { }", 1555 "function foo(eval) { }",
1526 "function foo(arguments) { }", 1556 "function foo(arguments) { }",
1527 "function foo(bar, eval) { }", 1557 "function foo(bar, eval) { }",
1528 "function foo(bar, arguments) { }", 1558 "function foo(bar, arguments) { }",
1559 "(eval) => { }",
1560 "(arguments) => { }",
1561 "(foo, eval) => { }",
1562 "(foo, arguments) => { }",
1529 "eval = 1;", 1563 "eval = 1;",
1530 "arguments = 1;", 1564 "arguments = 1;",
1531 "var foo = eval = 1;", 1565 "var foo = eval = 1;",
1532 "var foo = arguments = 1;", 1566 "var foo = arguments = 1;",
1533 "++eval;", 1567 "++eval;",
1534 "++arguments;", 1568 "++arguments;",
1535 "eval++;", 1569 "eval++;",
1536 "arguments++;", 1570 "arguments++;",
1537 NULL 1571 NULL
1538 }; 1572 };
1539 1573
1574 i::FLAG_harmony_arrow_functions = true;
1540 RunParserSyncTest(context_data, statement_data, kError); 1575 RunParserSyncTest(context_data, statement_data, kError);
1541 } 1576 }
1542 1577
1543 1578
1544 TEST(NoErrorsEvalAndArgumentsSloppy) { 1579 TEST(NoErrorsEvalAndArgumentsSloppy) {
1545 // Tests that both preparsing and parsing accept "eval" and "arguments" as 1580 // Tests that both preparsing and parsing accept "eval" and "arguments" as
1546 // identifiers when needed. 1581 // identifiers when needed.
1547 const char* context_data[][2] = { 1582 const char* context_data[][2] = {
1548 { "", "" }, 1583 { "", "" },
1549 { "function test_func() {", "}"}, 1584 { "function test_func() {", "}"},
1550 { NULL, NULL } 1585 { NULL, NULL }
1551 }; 1586 };
1552 1587
1553 const char* statement_data[] = { 1588 const char* statement_data[] = {
1554 "var eval;", 1589 "var eval;",
1555 "var arguments", 1590 "var arguments",
1556 "var foo, eval;", 1591 "var foo, eval;",
1557 "var foo, arguments;", 1592 "var foo, arguments;",
1558 "try { } catch (eval) { }", 1593 "try { } catch (eval) { }",
1559 "try { } catch (arguments) { }", 1594 "try { } catch (arguments) { }",
1560 "function eval() { }", 1595 "function eval() { }",
1561 "function arguments() { }", 1596 "function arguments() { }",
1562 "function foo(eval) { }", 1597 "function foo(eval) { }",
1563 "function foo(arguments) { }", 1598 "function foo(arguments) { }",
1564 "function foo(bar, eval) { }", 1599 "function foo(bar, eval) { }",
1565 "function foo(bar, arguments) { }", 1600 "function foo(bar, arguments) { }",
1601 "(eval) => { }",
1602 "(arguments) => { }",
1603 "(bar, eval) => { }",
1604 "(bar, arguments) => { }",
1566 "eval = 1;", 1605 "eval = 1;",
1567 "arguments = 1;", 1606 "arguments = 1;",
1568 "var foo = eval = 1;", 1607 "var foo = eval = 1;",
1569 "var foo = arguments = 1;", 1608 "var foo = arguments = 1;",
1570 "++eval;", 1609 "++eval;",
1571 "++arguments;", 1610 "++arguments;",
1572 "eval++;", 1611 "eval++;",
1573 "arguments++;", 1612 "arguments++;",
1574 NULL 1613 NULL
1575 }; 1614 };
1576 1615
1616 i::FLAG_harmony_arrow_functions = true;
1577 RunParserSyncTest(context_data, statement_data, kSuccess); 1617 RunParserSyncTest(context_data, statement_data, kSuccess);
1578 } 1618 }
1579 1619
1580 1620
1581 TEST(NoErrorsEvalAndArgumentsStrict) { 1621 TEST(NoErrorsEvalAndArgumentsStrict) {
1582 const char* context_data[][2] = { 1622 const char* context_data[][2] = {
1583 { "\"use strict\";", "" }, 1623 { "\"use strict\";", "" },
1584 { "function test_func() { \"use strict\";", "}" }, 1624 { "function test_func() { \"use strict\";", "}" },
1625 { "() => { \"use strict\"; ", "}" },
1585 { NULL, NULL } 1626 { NULL, NULL }
1586 }; 1627 };
1587 1628
1588 const char* statement_data[] = { 1629 const char* statement_data[] = {
1589 "eval;", 1630 "eval;",
1590 "arguments;", 1631 "arguments;",
1591 "var foo = eval;", 1632 "var foo = eval;",
1592 "var foo = arguments;", 1633 "var foo = arguments;",
1593 "var foo = { eval: 1 };", 1634 "var foo = { eval: 1 };",
1594 "var foo = { arguments: 1 };", 1635 "var foo = { arguments: 1 };",
1595 "var foo = { }; foo.eval = {};", 1636 "var foo = { }; foo.eval = {};",
1596 "var foo = { }; foo.arguments = {};", 1637 "var foo = { }; foo.arguments = {};",
1597 NULL 1638 NULL
1598 }; 1639 };
1599 1640
1641 i::FLAG_harmony_arrow_functions = true;
1600 RunParserSyncTest(context_data, statement_data, kSuccess); 1642 RunParserSyncTest(context_data, statement_data, kSuccess);
1601 } 1643 }
1602 1644
1603 1645
1604 TEST(ErrorsFutureStrictReservedWords) { 1646 TEST(ErrorsFutureStrictReservedWords) {
1605 // Tests that both preparsing and parsing produce the right kind of errors for 1647 // Tests that both preparsing and parsing produce the right kind of errors for
1606 // using future strict reserved words as identifiers. Without the strict mode, 1648 // using future strict reserved words as identifiers. Without the strict mode,
1607 // it's ok to use future strict reserved words as identifiers. With the strict 1649 // it's ok to use future strict reserved words as identifiers. With the strict
1608 // mode, it isn't. 1650 // mode, it isn't.
1609 const char* context_data[][2] = { 1651 const char* context_data[][2] = {
1610 { "\"use strict\";", "" }, 1652 { "\"use strict\";", "" },
1611 { "function test_func() {\"use strict\"; ", "}"}, 1653 { "function test_func() {\"use strict\"; ", "}"},
1654 { "() => { \"use strict\"; ", "}" },
1612 { NULL, NULL } 1655 { NULL, NULL }
1613 }; 1656 };
1614 1657
1615 const char* statement_data[] = { 1658 const char* statement_data[] = {
1616 "var interface;", 1659 "var interface;",
1617 "var foo, interface;", 1660 "var foo, interface;",
1618 "try { } catch (interface) { }", 1661 "try { } catch (interface) { }",
1619 "function interface() { }", 1662 "function interface() { }",
1620 "function foo(interface) { }", 1663 "function foo(interface) { }",
1621 "function foo(bar, interface) { }", 1664 "function foo(bar, interface) { }",
1665 "(interface) => { }",
1666 "(bar, interface) => { }",
1622 "interface = 1;", 1667 "interface = 1;",
1623 "var foo = interface = 1;", 1668 "var foo = interface = 1;",
1624 "++interface;", 1669 "++interface;",
1625 "interface++;", 1670 "interface++;",
1626 NULL 1671 NULL
1627 }; 1672 };
1628 1673
1674 i::FLAG_harmony_arrow_functions = true;
1629 RunParserSyncTest(context_data, statement_data, kError); 1675 RunParserSyncTest(context_data, statement_data, kError);
1630 } 1676 }
1631 1677
1632 1678
1633 TEST(NoErrorsFutureStrictReservedWords) { 1679 TEST(NoErrorsFutureStrictReservedWords) {
1634 const char* context_data[][2] = { 1680 const char* context_data[][2] = {
1635 { "", "" }, 1681 { "", "" },
1636 { "function test_func() {", "}"}, 1682 { "function test_func() {", "}"},
1683 { "() => {", "}" },
1637 { NULL, NULL } 1684 { NULL, NULL }
1638 }; 1685 };
1639 1686
1640 const char* statement_data[] = { 1687 const char* statement_data[] = {
1641 "var interface;", 1688 "var interface;",
1642 "var foo, interface;", 1689 "var foo, interface;",
1643 "try { } catch (interface) { }", 1690 "try { } catch (interface) { }",
1644 "function interface() { }", 1691 "function interface() { }",
1645 "function foo(interface) { }", 1692 "function foo(interface) { }",
1646 "function foo(bar, interface) { }", 1693 "function foo(bar, interface) { }",
1694 "(interface) => { }",
1695 "(bar, interface) => { }",
1647 "interface = 1;", 1696 "interface = 1;",
1648 "var foo = interface = 1;", 1697 "var foo = interface = 1;",
1649 "++interface;", 1698 "++interface;",
1650 "interface++;", 1699 "interface++;",
1651 NULL 1700 NULL
1652 }; 1701 };
1653 1702
1703 i::FLAG_harmony_arrow_functions = true;
1654 RunParserSyncTest(context_data, statement_data, kSuccess); 1704 RunParserSyncTest(context_data, statement_data, kSuccess);
1655 } 1705 }
1656 1706
1657 1707
1658 TEST(ErrorsReservedWords) { 1708 TEST(ErrorsReservedWords) {
1659 // Tests that both preparsing and parsing produce the right kind of errors for 1709 // Tests that both preparsing and parsing produce the right kind of errors for
1660 // using future reserved words as identifiers. These tests don't depend on the 1710 // using future reserved words as identifiers. These tests don't depend on the
1661 // strict mode. 1711 // strict mode.
1662 const char* context_data[][2] = { 1712 const char* context_data[][2] = {
1663 { "", "" }, 1713 { "", "" },
1664 { "\"use strict\";", "" }, 1714 { "\"use strict\";", "" },
1665 { "var eval; function test_func() {", "}"}, 1715 { "var eval; function test_func() {", "}"},
1666 { "var eval; function test_func() {\"use strict\"; ", "}"}, 1716 { "var eval; function test_func() {\"use strict\"; ", "}"},
1717 { "var eval; () => {", "}" },
1718 { "var eval; () => {\"use strict\"; ", "}" },
1667 { NULL, NULL } 1719 { NULL, NULL }
1668 }; 1720 };
1669 1721
1670 const char* statement_data[] = { 1722 const char* statement_data[] = {
1671 "var super;", 1723 "var super;",
1672 "var foo, super;", 1724 "var foo, super;",
1673 "try { } catch (super) { }", 1725 "try { } catch (super) { }",
1674 "function super() { }", 1726 "function super() { }",
1675 "function foo(super) { }", 1727 "function foo(super) { }",
1676 "function foo(bar, super) { }", 1728 "function foo(bar, super) { }",
1729 "(super) => { }",
1730 "(bar, super) => { }",
1677 "super = 1;", 1731 "super = 1;",
1678 "var foo = super = 1;", 1732 "var foo = super = 1;",
1679 "++super;", 1733 "++super;",
1680 "super++;", 1734 "super++;",
1681 "function foo super", 1735 "function foo super",
1682 NULL 1736 NULL
1683 }; 1737 };
1684 1738
1739 i::FLAG_harmony_arrow_functions = true;
1685 RunParserSyncTest(context_data, statement_data, kError); 1740 RunParserSyncTest(context_data, statement_data, kError);
1686 } 1741 }
1687 1742
1688 1743
1689 TEST(NoErrorsYieldSloppy) { 1744 TEST(NoErrorsYieldSloppy) {
1690 // In sloppy mode, it's okay to use "yield" as identifier, *except* inside a 1745 // In sloppy mode, it's okay to use "yield" as identifier, *except* inside a
1691 // generator (see next test). 1746 // generator (see next test).
1692 const char* context_data[][2] = { 1747 const char* context_data[][2] = {
1693 { "", "" }, 1748 { "", "" },
1694 { "function is_not_gen() {", "}" }, 1749 { "function is_not_gen() {", "}" },
1750 { "() => {", "}" },
1695 { NULL, NULL } 1751 { NULL, NULL }
1696 }; 1752 };
1697 1753
1698 const char* statement_data[] = { 1754 const char* statement_data[] = {
1699 "var yield;", 1755 "var yield;",
1700 "var foo, yield;", 1756 "var foo, yield;",
1701 "try { } catch (yield) { }", 1757 "try { } catch (yield) { }",
1702 "function yield() { }", 1758 "function yield() { }",
1703 "function foo(yield) { }", 1759 "function foo(yield) { }",
1704 "function foo(bar, yield) { }", 1760 "function foo(bar, yield) { }",
1761 "(yield) => { }",
1762 "(bar, yield) => { }",
1705 "yield = 1;", 1763 "yield = 1;",
1706 "var foo = yield = 1;", 1764 "var foo = yield = 1;",
1707 "++yield;", 1765 "++yield;",
1708 "yield++;", 1766 "yield++;",
1709 NULL 1767 NULL
1710 }; 1768 };
1711 1769
1770 i::FLAG_harmony_arrow_functions = true;
1712 RunParserSyncTest(context_data, statement_data, kSuccess); 1771 RunParserSyncTest(context_data, statement_data, kSuccess);
1713 } 1772 }
1714 1773
1715 1774
1716 TEST(ErrorsYieldSloppyGenerator) { 1775 TEST(ErrorsYieldSloppyGenerator) {
1717 const char* context_data[][2] = { 1776 const char* context_data[][2] = {
1718 { "function * is_gen() {", "}" }, 1777 { "function * is_gen() {", "}" },
1719 { NULL, NULL } 1778 { NULL, NULL }
1720 }; 1779 };
1721 1780
1722 const char* statement_data[] = { 1781 const char* statement_data[] = {
1723 "var yield;", 1782 "var yield;",
1724 "var foo, yield;", 1783 "var foo, yield;",
1725 "try { } catch (yield) { }", 1784 "try { } catch (yield) { }",
1726 "function yield() { }", 1785 "function yield() { }",
1727 // BUG: These should not be allowed, but they are (if kAllowGenerators is 1786 // BUG: These should not be allowed, but they are (if kAllowGenerators is
1728 // set) 1787 // set)
1729 // "function foo(yield) { }", 1788 // "function foo(yield) { }",
1730 // "function foo(bar, yield) { }", 1789 // "function foo(bar, yield) { }",
1731 "yield = 1;", 1790 "yield = 1;",
1732 "var foo = yield = 1;", 1791 "var foo = yield = 1;",
1733 "++yield;", 1792 "++yield;",
1734 "yield++;", 1793 "yield++;",
1735 NULL 1794 NULL
1736 }; 1795 };
1737 1796
1738 // If generators are not allowed, the error will be produced at the '*' token, 1797 // If generators are not allowed, the error will be produced at the '*' token,
1739 // so this test works both with and without the kAllowGenerators flag. 1798 // so this test works both with and without the kAllowGenerators flag.
1799 i::FLAG_harmony_arrow_functions = true;
1740 RunParserSyncTest(context_data, statement_data, kError); 1800 RunParserSyncTest(context_data, statement_data, kError);
1741 } 1801 }
1742 1802
1743 1803
1744 TEST(ErrorsYieldStrict) { 1804 TEST(ErrorsYieldStrict) {
1745 const char* context_data[][2] = { 1805 const char* context_data[][2] = {
1746 { "\"use strict\";", "" }, 1806 { "\"use strict\";", "" },
1747 { "\"use strict\"; function is_not_gen() {", "}" }, 1807 { "\"use strict\"; function is_not_gen() {", "}" },
1748 { "function test_func() {\"use strict\"; ", "}"}, 1808 { "function test_func() {\"use strict\"; ", "}"},
1809 { "() => {\"use strict\"; ", "}" },
1749 { NULL, NULL } 1810 { NULL, NULL }
1750 }; 1811 };
1751 1812
1752 const char* statement_data[] = { 1813 const char* statement_data[] = {
1753 "var yield;", 1814 "var yield;",
1754 "var foo, yield;", 1815 "var foo, yield;",
1755 "try { } catch (yield) { }", 1816 "try { } catch (yield) { }",
1756 "function yield() { }", 1817 "function yield() { }",
1757 "function foo(yield) { }", 1818 "function foo(yield) { }",
1758 "function foo(bar, yield) { }", 1819 "function foo(bar, yield) { }",
1820 "(yield) => { }",
1821 "(bar, yield) => { }",
1759 "yield = 1;", 1822 "yield = 1;",
1760 "var foo = yield = 1;", 1823 "var foo = yield = 1;",
1761 "++yield;", 1824 "++yield;",
1762 "yield++;", 1825 "yield++;",
1763 NULL 1826 NULL
1764 }; 1827 };
1765 1828
1829 i::FLAG_harmony_arrow_functions = true;
1766 RunParserSyncTest(context_data, statement_data, kError); 1830 RunParserSyncTest(context_data, statement_data, kError);
1767 } 1831 }
1768 1832
1769 1833
1770 TEST(ErrorsYield) { 1834 TEST(ErrorsYield) {
1771 const char* context_data[][2] = { 1835 const char* context_data[][2] = {
1772 { "function * is_gen() {", "}" }, 1836 { "function * is_gen() {", "}" },
1773 { NULL, NULL } 1837 { NULL, NULL }
1774 }; 1838 };
1775 1839
1776 const char* statement_data[] = { 1840 const char* statement_data[] = {
1777 "yield 2;", // this is legal inside generator 1841 "yield 2;", // this is legal inside generator
1778 "yield * 2;", // this is legal inside generator 1842 "yield * 2;", // this is legal inside generator
1779 NULL 1843 NULL
1780 }; 1844 };
1781 1845
1782 // Here we cannot assert that there is no error, since there will be without 1846 // Here we cannot assert that there is no error, since there will be without
1783 // the kAllowGenerators flag. However, we test that Parser and PreParser 1847 // the kAllowGenerators flag. However, we test that Parser and PreParser
1784 // produce the same errors. 1848 // produce the same errors.
1849 i::FLAG_harmony_arrow_functions = true;
1785 RunParserSyncTest(context_data, statement_data, kSuccessOrError); 1850 RunParserSyncTest(context_data, statement_data, kSuccessOrError);
1786 } 1851 }
1787 1852
1788 1853
1789 TEST(ErrorsNameOfStrictFunction) { 1854 TEST(ErrorsNameOfStrictFunction) {
1790 // Tests that illegal tokens as names of a strict function produce the correct 1855 // Tests that illegal tokens as names of a strict function produce the correct
1791 // errors. 1856 // errors.
1792 const char* context_data[][2] = { 1857 const char* context_data[][2] = {
1793 { "", ""}, 1858 { "", ""},
1794 { "\"use strict\";", ""}, 1859 { "\"use strict\";", ""},
1795 { NULL, NULL } 1860 { NULL, NULL }
1796 }; 1861 };
1797 1862
1798 const char* statement_data[] = { 1863 const char* statement_data[] = {
1799 "function eval() {\"use strict\";}", 1864 "function eval() {\"use strict\";}",
1800 "function arguments() {\"use strict\";}", 1865 "function arguments() {\"use strict\";}",
1801 "function interface() {\"use strict\";}", 1866 "function interface() {\"use strict\";}",
1802 "function yield() {\"use strict\";}", 1867 "function yield() {\"use strict\";}",
1803 // Future reserved words are always illegal 1868 // Future reserved words are always illegal
1804 "function super() { }", 1869 "function super() { }",
1805 "function super() {\"use strict\";}", 1870 "function super() {\"use strict\";}",
1806 NULL 1871 NULL
1807 }; 1872 };
1808 1873
1874 i::FLAG_harmony_arrow_functions = true;
1809 RunParserSyncTest(context_data, statement_data, kError); 1875 RunParserSyncTest(context_data, statement_data, kError);
1810 } 1876 }
1811 1877
1812 1878
1813 TEST(NoErrorsNameOfStrictFunction) { 1879 TEST(NoErrorsNameOfStrictFunction) {
1814 const char* context_data[][2] = { 1880 const char* context_data[][2] = {
1815 { "", ""}, 1881 { "", ""},
1816 { NULL, NULL } 1882 { NULL, NULL }
1817 }; 1883 };
1818 1884
1819 const char* statement_data[] = { 1885 const char* statement_data[] = {
1820 "function eval() { }", 1886 "function eval() { }",
1821 "function arguments() { }", 1887 "function arguments() { }",
1822 "function interface() { }", 1888 "function interface() { }",
1823 "function yield() { }", 1889 "function yield() { }",
1824 NULL 1890 NULL
1825 }; 1891 };
1826 1892
1893 i::FLAG_harmony_arrow_functions = true;
1827 RunParserSyncTest(context_data, statement_data, kSuccess); 1894 RunParserSyncTest(context_data, statement_data, kSuccess);
1828 } 1895 }
1829 1896
1830 1897
1831 1898
1832 TEST(ErrorsIllegalWordsAsLabelsSloppy) { 1899 TEST(ErrorsIllegalWordsAsLabelsSloppy) {
1833 // Using future reserved words as labels is always an error. 1900 // Using future reserved words as labels is always an error.
1834 const char* context_data[][2] = { 1901 const char* context_data[][2] = {
1835 { "", ""}, 1902 { "", ""},
1836 { "function test_func() {", "}" }, 1903 { "function test_func() {", "}" },
1904 { "() => {", "}" },
1837 { NULL, NULL } 1905 { NULL, NULL }
1838 }; 1906 };
1839 1907
1840 const char* statement_data[] = { 1908 const char* statement_data[] = {
1841 "super: while(true) { break super; }", 1909 "super: while(true) { break super; }",
1842 NULL 1910 NULL
1843 }; 1911 };
1844 1912
1913 i::FLAG_harmony_arrow_functions = true;
1845 RunParserSyncTest(context_data, statement_data, kError); 1914 RunParserSyncTest(context_data, statement_data, kError);
1846 } 1915 }
1847 1916
1848 1917
1849 TEST(ErrorsIllegalWordsAsLabelsStrict) { 1918 TEST(ErrorsIllegalWordsAsLabelsStrict) {
1850 // Tests that illegal tokens as labels produce the correct errors. 1919 // Tests that illegal tokens as labels produce the correct errors.
1851 const char* context_data[][2] = { 1920 const char* context_data[][2] = {
1852 { "\"use strict\";", "" }, 1921 { "\"use strict\";", "" },
1853 { "function test_func() {\"use strict\"; ", "}"}, 1922 { "function test_func() {\"use strict\"; ", "}"},
1923 { "() => {\"use strict\"; ", "}" },
1854 { NULL, NULL } 1924 { NULL, NULL }
1855 }; 1925 };
1856 1926
1857 const char* statement_data[] = { 1927 const char* statement_data[] = {
1858 "super: while(true) { break super; }", 1928 "super: while(true) { break super; }",
1859 "interface: while(true) { break interface; }", 1929 "interface: while(true) { break interface; }",
1860 "yield: while(true) { break yield; }", 1930 "yield: while(true) { break yield; }",
1861 NULL 1931 NULL
1862 }; 1932 };
1863 1933
1934 i::FLAG_harmony_arrow_functions = true;
1864 RunParserSyncTest(context_data, statement_data, kError); 1935 RunParserSyncTest(context_data, statement_data, kError);
1865 } 1936 }
1866 1937
1867 1938
1868 TEST(NoErrorsIllegalWordsAsLabels) { 1939 TEST(NoErrorsIllegalWordsAsLabels) {
1869 // Using eval and arguments as labels is legal even in strict mode. 1940 // Using eval and arguments as labels is legal even in strict mode.
1870 const char* context_data[][2] = { 1941 const char* context_data[][2] = {
1871 { "", ""}, 1942 { "", ""},
1872 { "function test_func() {", "}" }, 1943 { "function test_func() {", "}" },
1944 { "() => {", "}" },
1873 { "\"use strict\";", "" }, 1945 { "\"use strict\";", "" },
1874 { "\"use strict\"; function test_func() {", "}" }, 1946 { "\"use strict\"; function test_func() {", "}" },
1947 { "\"use strict\"; () => {", "}" },
1875 { NULL, NULL } 1948 { NULL, NULL }
1876 }; 1949 };
1877 1950
1878 const char* statement_data[] = { 1951 const char* statement_data[] = {
1879 "mylabel: while(true) { break mylabel; }", 1952 "mylabel: while(true) { break mylabel; }",
1880 "eval: while(true) { break eval; }", 1953 "eval: while(true) { break eval; }",
1881 "arguments: while(true) { break arguments; }", 1954 "arguments: while(true) { break arguments; }",
1882 NULL 1955 NULL
1883 }; 1956 };
1884 1957
1958 i::FLAG_harmony_arrow_functions = true;
1885 RunParserSyncTest(context_data, statement_data, kSuccess); 1959 RunParserSyncTest(context_data, statement_data, kSuccess);
1886 } 1960 }
1887 1961
1888 1962
1889 TEST(ErrorsParenthesizedLabels) { 1963 TEST(ErrorsParenthesizedLabels) {
1890 // Parenthesized identifiers shouldn't be recognized as labels. 1964 // Parenthesized identifiers shouldn't be recognized as labels.
1891 const char* context_data[][2] = { 1965 const char* context_data[][2] = {
1892 { "", ""}, 1966 { "", ""},
1893 { "function test_func() {", "}" }, 1967 { "function test_func() {", "}" },
1968 { "() => {", "}" },
1894 { NULL, NULL } 1969 { NULL, NULL }
1895 }; 1970 };
1896 1971
1897 const char* statement_data[] = { 1972 const char* statement_data[] = {
1898 "(mylabel): while(true) { break mylabel; }", 1973 "(mylabel): while(true) { break mylabel; }",
1899 NULL 1974 NULL
1900 }; 1975 };
1901 1976
1977 i::FLAG_harmony_arrow_functions = true;
1902 RunParserSyncTest(context_data, statement_data, kError); 1978 RunParserSyncTest(context_data, statement_data, kError);
1903 } 1979 }
1904 1980
1905 1981
1906 TEST(NoErrorsParenthesizedDirectivePrologue) { 1982 TEST(NoErrorsParenthesizedDirectivePrologue) {
1907 // Parenthesized directive prologue shouldn't be recognized. 1983 // Parenthesized directive prologue shouldn't be recognized.
1908 const char* context_data[][2] = { 1984 const char* context_data[][2] = {
1909 { "", ""}, 1985 { "", ""},
1910 { NULL, NULL } 1986 { NULL, NULL }
1911 }; 1987 };
1912 1988
1913 const char* statement_data[] = { 1989 const char* statement_data[] = {
1914 "(\"use strict\"); var eval;", 1990 "(\"use strict\"); var eval;",
1915 NULL 1991 NULL
1916 }; 1992 };
1917 1993
1994 i::FLAG_harmony_arrow_functions = true;
1918 RunParserSyncTest(context_data, statement_data, kSuccess); 1995 RunParserSyncTest(context_data, statement_data, kSuccess);
1919 } 1996 }
1920 1997
1921 1998
1922 TEST(ErrorsNotAnIdentifierName) { 1999 TEST(ErrorsNotAnIdentifierName) {
1923 const char* context_data[][2] = { 2000 const char* context_data[][2] = {
1924 { "", ""}, 2001 { "", ""},
1925 { "\"use strict\";", ""}, 2002 { "\"use strict\";", ""},
1926 { NULL, NULL } 2003 { NULL, NULL }
1927 }; 2004 };
1928 2005
1929 const char* statement_data[] = { 2006 const char* statement_data[] = {
1930 "var foo = {}; foo.{;", 2007 "var foo = {}; foo.{;",
1931 "var foo = {}; foo.};", 2008 "var foo = {}; foo.};",
1932 "var foo = {}; foo.=;", 2009 "var foo = {}; foo.=;",
1933 "var foo = {}; foo.888;", 2010 "var foo = {}; foo.888;",
1934 "var foo = {}; foo.-;", 2011 "var foo = {}; foo.-;",
1935 "var foo = {}; foo.--;", 2012 "var foo = {}; foo.--;",
1936 NULL 2013 NULL
1937 }; 2014 };
1938 2015
2016 i::FLAG_harmony_arrow_functions = true;
1939 RunParserSyncTest(context_data, statement_data, kError); 2017 RunParserSyncTest(context_data, statement_data, kError);
1940 } 2018 }
1941 2019
1942 2020
1943 TEST(NoErrorsIdentifierNames) { 2021 TEST(NoErrorsIdentifierNames) {
1944 // Keywords etc. are valid as property names. 2022 // Keywords etc. are valid as property names.
1945 const char* context_data[][2] = { 2023 const char* context_data[][2] = {
1946 { "", ""}, 2024 { "", ""},
1947 { "\"use strict\";", ""}, 2025 { "\"use strict\";", ""},
1948 { NULL, NULL } 2026 { NULL, NULL }
1949 }; 2027 };
1950 2028
1951 const char* statement_data[] = { 2029 const char* statement_data[] = {
1952 "var foo = {}; foo.if;", 2030 "var foo = {}; foo.if;",
1953 "var foo = {}; foo.yield;", 2031 "var foo = {}; foo.yield;",
1954 "var foo = {}; foo.super;", 2032 "var foo = {}; foo.super;",
1955 "var foo = {}; foo.interface;", 2033 "var foo = {}; foo.interface;",
1956 "var foo = {}; foo.eval;", 2034 "var foo = {}; foo.eval;",
1957 "var foo = {}; foo.arguments;", 2035 "var foo = {}; foo.arguments;",
1958 NULL 2036 NULL
1959 }; 2037 };
1960 2038
2039 i::FLAG_harmony_arrow_functions = true;
1961 RunParserSyncTest(context_data, statement_data, kSuccess); 2040 RunParserSyncTest(context_data, statement_data, kSuccess);
1962 } 2041 }
1963 2042
1964 2043
1965 TEST(DontRegressPreParserDataSizes) { 2044 TEST(DontRegressPreParserDataSizes) {
1966 // These tests make sure that Parser doesn't start producing less "preparse 2045 // These tests make sure that Parser doesn't start producing less "preparse
1967 // data" (data which the embedder can cache). 2046 // data" (data which the embedder can cache).
1968 v8::V8::Initialize(); 2047 v8::V8::Initialize();
2048 i::FLAG_harmony_arrow_functions = true;
1969 v8::Isolate* isolate = CcTest::isolate(); 2049 v8::Isolate* isolate = CcTest::isolate();
1970 v8::HandleScope handles(isolate); 2050 v8::HandleScope handles(isolate);
1971 2051
1972 int marker; 2052 int marker;
1973 CcTest::i_isolate()->stack_guard()->SetStackLimit( 2053 CcTest::i_isolate()->stack_guard()->SetStackLimit(
1974 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 2054 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
1975 2055
1976 struct TestCase { 2056 struct TestCase {
1977 const char* program; 2057 const char* program;
1978 int functions; 2058 int functions;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2029 {"function interface() {", "}"}, 2109 {"function interface() {", "}"},
2030 {"function foo(eval) {", "}"}, 2110 {"function foo(eval) {", "}"},
2031 {"function foo(arguments) {", "}"}, 2111 {"function foo(arguments) {", "}"},
2032 {"function foo(yield) {", "}"}, 2112 {"function foo(yield) {", "}"},
2033 {"function foo(interface) {", "}"}, 2113 {"function foo(interface) {", "}"},
2034 {"function foo(bar, eval) {", "}"}, 2114 {"function foo(bar, eval) {", "}"},
2035 {"function foo(bar, arguments) {", "}"}, 2115 {"function foo(bar, arguments) {", "}"},
2036 {"function foo(bar, yield) {", "}"}, 2116 {"function foo(bar, yield) {", "}"},
2037 {"function foo(bar, interface) {", "}"}, 2117 {"function foo(bar, interface) {", "}"},
2038 {"function foo(bar, bar) {", "}"}, 2118 {"function foo(bar, bar) {", "}"},
2119 {"eval => {", "}"},
2120 {"arguments => {", "}"},
2121 {"yield => {", "}"},
2122 {"interface => {", "}"},
2123 {"(eval) => {", "}"},
2124 {"(arguments) => {", "}"},
2125 {"(yield) => {", "}"},
2126 {"(interface) => {", "}"},
2127 {"(eval, bar) => {", "}"},
2128 {"(bar, eval) => {", "}"},
2129 {"(bar, arguments) => {", "}"},
2130 {"(bar, yield) => {", "}"},
2131 {"(bar, interface) => {", "}"},
2132 {"(bar, bar) => {", "}"},
2039 { NULL, NULL } 2133 { NULL, NULL }
2040 }; 2134 };
2041 2135
2042 const char* strict_statement_data[] = { 2136 const char* strict_statement_data[] = {
2043 "\"use strict\";", 2137 "\"use strict\";",
2044 NULL 2138 NULL
2045 }; 2139 };
2046 2140
2047 const char* non_strict_statement_data[] = { 2141 const char* non_strict_statement_data[] = {
2048 ";", 2142 ";",
2049 NULL 2143 NULL
2050 }; 2144 };
2051 2145
2146 i::FLAG_harmony_arrow_functions = true;
2052 RunParserSyncTest(context_data, strict_statement_data, kError); 2147 RunParserSyncTest(context_data, strict_statement_data, kError);
2053 RunParserSyncTest(context_data, non_strict_statement_data, kSuccess); 2148 RunParserSyncTest(context_data, non_strict_statement_data, kSuccess);
2054 } 2149 }
2055 2150
2056 2151
2057 TEST(ErrorsTryWithoutCatchOrFinally) { 2152 TEST(ErrorsTryWithoutCatchOrFinally) {
2058 const char* context_data[][2] = { 2153 const char* context_data[][2] = {
2059 {"", ""}, 2154 {"", ""},
2060 { NULL, NULL } 2155 { NULL, NULL }
2061 }; 2156 };
2062 2157
2063 const char* statement_data[] = { 2158 const char* statement_data[] = {
2064 "try { }", 2159 "try { }",
2065 "try { } foo();", 2160 "try { } foo();",
2066 "try { } catch (e) foo();", 2161 "try { } catch (e) foo();",
2067 "try { } catch { }", 2162 "try { } catch { }",
2068 "try { } finally foo();", 2163 "try { } finally foo();",
2069 NULL 2164 NULL
2070 }; 2165 };
2071 2166
2167 i::FLAG_harmony_arrow_functions = true;
2072 RunParserSyncTest(context_data, statement_data, kError); 2168 RunParserSyncTest(context_data, statement_data, kError);
2073 } 2169 }
2074 2170
2075 2171
2076 TEST(NoErrorsTryCatchFinally) { 2172 TEST(NoErrorsTryCatchFinally) {
2077 const char* context_data[][2] = { 2173 const char* context_data[][2] = {
2078 {"", ""}, 2174 {"", ""},
2079 { NULL, NULL } 2175 { NULL, NULL }
2080 }; 2176 };
2081 2177
2082 const char* statement_data[] = { 2178 const char* statement_data[] = {
2083 "try { } catch (e) { }", 2179 "try { } catch (e) { }",
2084 "try { } catch (e) { } finally { }", 2180 "try { } catch (e) { } finally { }",
2085 "try { } finally { }", 2181 "try { } finally { }",
2086 NULL 2182 NULL
2087 }; 2183 };
2088 2184
2185 i::FLAG_harmony_arrow_functions = true;
2089 RunParserSyncTest(context_data, statement_data, kSuccess); 2186 RunParserSyncTest(context_data, statement_data, kSuccess);
2090 } 2187 }
2091 2188
2092 2189
2093 TEST(ErrorsRegexpLiteral) { 2190 TEST(ErrorsRegexpLiteral) {
2094 const char* context_data[][2] = { 2191 const char* context_data[][2] = {
2095 {"var r = ", ""}, 2192 {"var r = ", ""},
2096 { NULL, NULL } 2193 { NULL, NULL }
2097 }; 2194 };
2098 2195
2099 const char* statement_data[] = { 2196 const char* statement_data[] = {
2100 "/unterminated", 2197 "/unterminated",
2101 NULL 2198 NULL
2102 }; 2199 };
2103 2200
2201 i::FLAG_harmony_arrow_functions = true;
2104 RunParserSyncTest(context_data, statement_data, kError); 2202 RunParserSyncTest(context_data, statement_data, kError);
2105 } 2203 }
2106 2204
2107 2205
2108 TEST(NoErrorsRegexpLiteral) { 2206 TEST(NoErrorsRegexpLiteral) {
2109 const char* context_data[][2] = { 2207 const char* context_data[][2] = {
2110 {"var r = ", ""}, 2208 {"var r = ", ""},
2111 { NULL, NULL } 2209 { NULL, NULL }
2112 }; 2210 };
2113 2211
2114 const char* statement_data[] = { 2212 const char* statement_data[] = {
2115 "/foo/", 2213 "/foo/",
2116 "/foo/g", 2214 "/foo/g",
2117 "/foo/whatever", // This is an error but not detected by the parser. 2215 "/foo/whatever", // This is an error but not detected by the parser.
2118 NULL 2216 NULL
2119 }; 2217 };
2120 2218
2219 i::FLAG_harmony_arrow_functions = true;
2121 RunParserSyncTest(context_data, statement_data, kSuccess); 2220 RunParserSyncTest(context_data, statement_data, kSuccess);
2122 } 2221 }
2123 2222
2124 2223
2125 TEST(Intrinsics) { 2224 TEST(Intrinsics) {
2126 const char* context_data[][2] = { 2225 const char* context_data[][2] = {
2127 {"", ""}, 2226 {"", ""},
2128 { NULL, NULL } 2227 { NULL, NULL }
2129 }; 2228 };
2130 2229
2131 const char* statement_data[] = { 2230 const char* statement_data[] = {
2132 "%someintrinsic(arg)", 2231 "%someintrinsic(arg)",
2133 NULL 2232 NULL
2134 }; 2233 };
2135 2234
2136 // Parsing will fail or succeed depending on whether we allow natives syntax 2235 // Parsing will fail or succeed depending on whether we allow natives syntax
2137 // or not. 2236 // or not.
2237 i::FLAG_harmony_arrow_functions = true;
2138 RunParserSyncTest(context_data, statement_data, kSuccessOrError); 2238 RunParserSyncTest(context_data, statement_data, kSuccessOrError);
2139 } 2239 }
2140 2240
2141 2241
2142 TEST(NoErrorsNewExpression) { 2242 TEST(NoErrorsNewExpression) {
2143 const char* context_data[][2] = { 2243 const char* context_data[][2] = {
2144 {"", ""}, 2244 {"", ""},
2145 {"var f =", ""}, 2245 {"var f =", ""},
2146 { NULL, NULL } 2246 { NULL, NULL }
2147 }; 2247 };
(...skipping 19 matching lines...) Expand all
2167 "new foo[bar]()[baz];", 2267 "new foo[bar]()[baz];",
2168 "new foo[bar].baz(baz)()[bar].baz;", 2268 "new foo[bar].baz(baz)()[bar].baz;",
2169 "new \"foo\"", // Runtime error 2269 "new \"foo\"", // Runtime error
2170 "new 1", // Runtime error 2270 "new 1", // Runtime error
2171 // This even runs: 2271 // This even runs:
2172 "(new new Function(\"this.x = 1\")).x;", 2272 "(new new Function(\"this.x = 1\")).x;",
2173 "new new Test_Two(String, 2).v(0123).length;", 2273 "new new Test_Two(String, 2).v(0123).length;",
2174 NULL 2274 NULL
2175 }; 2275 };
2176 2276
2277 i::FLAG_harmony_arrow_functions = true;
2177 RunParserSyncTest(context_data, statement_data, kSuccess); 2278 RunParserSyncTest(context_data, statement_data, kSuccess);
2178 } 2279 }
2179 2280
2180 2281
2181 TEST(ErrorsNewExpression) { 2282 TEST(ErrorsNewExpression) {
2182 const char* context_data[][2] = { 2283 const char* context_data[][2] = {
2183 {"", ""}, 2284 {"", ""},
2184 {"var f =", ""}, 2285 {"var f =", ""},
2185 { NULL, NULL } 2286 { NULL, NULL }
2186 }; 2287 };
2187 2288
2188 const char* statement_data[] = { 2289 const char* statement_data[] = {
2189 "new foo bar", 2290 "new foo bar",
2190 "new ) foo", 2291 "new ) foo",
2191 "new ++foo", 2292 "new ++foo",
2192 "new foo ++", 2293 "new foo ++",
2193 NULL 2294 NULL
2194 }; 2295 };
2195 2296
2297 i::FLAG_harmony_arrow_functions = true;
2196 RunParserSyncTest(context_data, statement_data, kError); 2298 RunParserSyncTest(context_data, statement_data, kError);
2197 } 2299 }
2198 2300
2199 2301
2200 TEST(StrictObjectLiteralChecking) { 2302 TEST(StrictObjectLiteralChecking) {
2201 const char* strict_context_data[][2] = { 2303 const char* strict_context_data[][2] = {
2202 {"\"use strict\"; var myobject = {", "};"}, 2304 {"\"use strict\"; var myobject = {", "};"},
2203 { NULL, NULL } 2305 { NULL, NULL }
2204 }; 2306 };
2205 const char* non_strict_context_data[][2] = { 2307 const char* non_strict_context_data[][2] = {
2206 {"var myobject = {", "};"}, 2308 {"var myobject = {", "};"},
2207 { NULL, NULL } 2309 { NULL, NULL }
2208 }; 2310 };
2209 2311
2210 // These are only errors in strict mode. 2312 // These are only errors in strict mode.
2211 const char* statement_data[] = { 2313 const char* statement_data[] = {
2212 "foo: 1, foo: 2", 2314 "foo: 1, foo: 2",
2213 "\"foo\": 1, \"foo\": 2", 2315 "\"foo\": 1, \"foo\": 2",
2214 "foo: 1, \"foo\": 2", 2316 "foo: 1, \"foo\": 2",
2215 "1: 1, 1: 2", 2317 "1: 1, 1: 2",
2216 "1: 1, \"1\": 2", 2318 "1: 1, \"1\": 2",
2217 "get: 1, get: 2", // Not a getter for real, just a property called get. 2319 "get: 1, get: 2", // Not a getter for real, just a property called get.
2218 "set: 1, set: 2", // Not a setter for real, just a property called set. 2320 "set: 1, set: 2", // Not a setter for real, just a property called set.
2219 NULL 2321 NULL
2220 }; 2322 };
2221 2323
2324 i::FLAG_harmony_arrow_functions = true;
2222 RunParserSyncTest(non_strict_context_data, statement_data, kSuccess); 2325 RunParserSyncTest(non_strict_context_data, statement_data, kSuccess);
2223 RunParserSyncTest(strict_context_data, statement_data, kError); 2326 RunParserSyncTest(strict_context_data, statement_data, kError);
2224 } 2327 }
2225 2328
2226 2329
2227 TEST(ErrorsObjectLiteralChecking) { 2330 TEST(ErrorsObjectLiteralChecking) {
2228 const char* context_data[][2] = { 2331 const char* context_data[][2] = {
2229 {"\"use strict\"; var myobject = {", "};"}, 2332 {"\"use strict\"; var myobject = {", "};"},
2230 {"var myobject = {", "};"}, 2333 {"var myobject = {", "};"},
2231 { NULL, NULL } 2334 { NULL, NULL }
(...skipping 21 matching lines...) Expand all
2253 "get bar(x) {}", 2356 "get bar(x) {}",
2254 "get bar(x, y) {}", 2357 "get bar(x, y) {}",
2255 "set bar() {}", 2358 "set bar() {}",
2256 "set bar(x, y) {}", 2359 "set bar(x, y) {}",
2257 // Parsing FunctionLiteral for getter or setter fails 2360 // Parsing FunctionLiteral for getter or setter fails
2258 "get foo( +", 2361 "get foo( +",
2259 "get foo() \"error\"", 2362 "get foo() \"error\"",
2260 NULL 2363 NULL
2261 }; 2364 };
2262 2365
2366 i::FLAG_harmony_arrow_functions = true;
2263 RunParserSyncTest(context_data, statement_data, kError); 2367 RunParserSyncTest(context_data, statement_data, kError);
2264 } 2368 }
2265 2369
2266 2370
2267 TEST(NoErrorsObjectLiteralChecking) { 2371 TEST(NoErrorsObjectLiteralChecking) {
2268 const char* context_data[][2] = { 2372 const char* context_data[][2] = {
2269 {"var myobject = {", "};"}, 2373 {"var myobject = {", "};"},
2270 {"\"use strict\"; var myobject = {", "};"}, 2374 {"\"use strict\"; var myobject = {", "};"},
2271 { NULL, NULL } 2375 { NULL, NULL }
2272 }; 2376 };
(...skipping 23 matching lines...) Expand all
2296 // Keywords, future reserved and strict future reserved are also allowed as 2400 // Keywords, future reserved and strict future reserved are also allowed as
2297 // property names. 2401 // property names.
2298 "if: 4", 2402 "if: 4",
2299 "interface: 5", 2403 "interface: 5",
2300 "super: 6", 2404 "super: 6",
2301 "eval: 7", 2405 "eval: 7",
2302 "arguments: 8", 2406 "arguments: 8",
2303 NULL 2407 NULL
2304 }; 2408 };
2305 2409
2410 i::FLAG_harmony_arrow_functions = true;
2306 RunParserSyncTest(context_data, statement_data, kSuccess); 2411 RunParserSyncTest(context_data, statement_data, kSuccess);
2307 } 2412 }
2308 2413
2309 2414
2310 TEST(TooManyArguments) { 2415 TEST(TooManyArguments) {
2311 const char* context_data[][2] = { 2416 const char* context_data[][2] = {
2312 {"foo(", "0)"}, 2417 {"foo(", "0)"},
2313 { NULL, NULL } 2418 { NULL, NULL }
2314 }; 2419 };
2315 2420
2316 using v8::internal::Code; 2421 using v8::internal::Code;
2317 char statement[Code::kMaxArguments * 2 + 1]; 2422 char statement[Code::kMaxArguments * 2 + 1];
2318 for (int i = 0; i < Code::kMaxArguments; ++i) { 2423 for (int i = 0; i < Code::kMaxArguments; ++i) {
2319 statement[2 * i] = '0'; 2424 statement[2 * i] = '0';
2320 statement[2 * i + 1] = ','; 2425 statement[2 * i + 1] = ',';
2321 } 2426 }
2322 statement[Code::kMaxArguments * 2] = 0; 2427 statement[Code::kMaxArguments * 2] = 0;
2323 2428
2324 const char* statement_data[] = { 2429 const char* statement_data[] = {
2325 statement, 2430 statement,
2326 NULL 2431 NULL
2327 }; 2432 };
2328 2433
2329 // The test is quite slow, so run it with a reduced set of flags. 2434 // The test is quite slow, so run it with a reduced set of flags.
2435 i::FLAG_harmony_arrow_functions = true;
2330 static const ParserFlag empty_flags[] = {kAllowLazy}; 2436 static const ParserFlag empty_flags[] = {kAllowLazy};
2331 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1); 2437 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1);
2332 } 2438 }
2333 2439
2334 2440
2335 TEST(StrictDelete) { 2441 TEST(StrictDelete) {
2336 // "delete <Identifier>" is not allowed in strict mode. 2442 // "delete <Identifier>" is not allowed in strict mode.
2337 const char* strict_context_data[][2] = { 2443 const char* strict_context_data[][2] = {
2338 {"\"use strict\"; ", ""}, 2444 {"\"use strict\"; ", ""},
2339 { NULL, NULL } 2445 { NULL, NULL }
(...skipping 28 matching lines...) Expand all
2368 "delete new foo(bar);", 2474 "delete new foo(bar);",
2369 NULL 2475 NULL
2370 }; 2476 };
2371 2477
2372 // These are always errors 2478 // These are always errors
2373 const char* bad_statement_data[] = { 2479 const char* bad_statement_data[] = {
2374 "delete if;", 2480 "delete if;",
2375 NULL 2481 NULL
2376 }; 2482 };
2377 2483
2484 i::FLAG_harmony_arrow_functions = true;
2485
2378 RunParserSyncTest(strict_context_data, sloppy_statement_data, kError); 2486 RunParserSyncTest(strict_context_data, sloppy_statement_data, kError);
2379 RunParserSyncTest(sloppy_context_data, sloppy_statement_data, kSuccess); 2487 RunParserSyncTest(sloppy_context_data, sloppy_statement_data, kSuccess);
2380 2488
2381 RunParserSyncTest(strict_context_data, good_statement_data, kSuccess); 2489 RunParserSyncTest(strict_context_data, good_statement_data, kSuccess);
2382 RunParserSyncTest(sloppy_context_data, good_statement_data, kSuccess); 2490 RunParserSyncTest(sloppy_context_data, good_statement_data, kSuccess);
2383 2491
2384 RunParserSyncTest(strict_context_data, bad_statement_data, kError); 2492 RunParserSyncTest(strict_context_data, bad_statement_data, kError);
2385 RunParserSyncTest(sloppy_context_data, bad_statement_data, kError); 2493 RunParserSyncTest(sloppy_context_data, bad_statement_data, kError);
2386 } 2494 }
2387 2495
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2444 }; 2552 };
2445 2553
2446 // These are not okay for assignment, but okay for prefix / postix. 2554 // These are not okay for assignment, but okay for prefix / postix.
2447 const char* bad_statement_data_for_assignment[] = { 2555 const char* bad_statement_data_for_assignment[] = {
2448 "++foo", 2556 "++foo",
2449 "foo++", 2557 "foo++",
2450 "foo + bar", 2558 "foo + bar",
2451 NULL 2559 NULL
2452 }; 2560 };
2453 2561
2562 i::FLAG_harmony_arrow_functions = true;
2563
2454 RunParserSyncTest(assignment_context_data, good_statement_data, kSuccess); 2564 RunParserSyncTest(assignment_context_data, good_statement_data, kSuccess);
2455 RunParserSyncTest(assignment_context_data, bad_statement_data_common, kError); 2565 RunParserSyncTest(assignment_context_data, bad_statement_data_common, kError);
2456 RunParserSyncTest(assignment_context_data, bad_statement_data_for_assignment, 2566 RunParserSyncTest(assignment_context_data, bad_statement_data_for_assignment,
2457 kError); 2567 kError);
2458 2568
2459 RunParserSyncTest(prefix_context_data, good_statement_data, kSuccess); 2569 RunParserSyncTest(prefix_context_data, good_statement_data, kSuccess);
2460 RunParserSyncTest(prefix_context_data, bad_statement_data_common, kError); 2570 RunParserSyncTest(prefix_context_data, bad_statement_data_common, kError);
2461 2571
2462 RunParserSyncTest(postfix_context_data, good_statement_data, kSuccess); 2572 RunParserSyncTest(postfix_context_data, good_statement_data, kSuccess);
2463 RunParserSyncTest(postfix_context_data, bad_statement_data_common, kError); 2573 RunParserSyncTest(postfix_context_data, bad_statement_data_common, kError);
2464 } 2574 }
2465 2575
2466 2576
2467 TEST(FuncNameInferrerBasic) { 2577 TEST(FuncNameInferrerBasic) {
2468 // Tests that function names are inferred properly. 2578 // Tests that function names are inferred properly.
2469 i::FLAG_allow_natives_syntax = true; 2579 i::FLAG_allow_natives_syntax = true;
2580 i::FLAG_harmony_arrow_functions = true;
2470 v8::Isolate* isolate = CcTest::isolate(); 2581 v8::Isolate* isolate = CcTest::isolate();
2471 v8::HandleScope scope(isolate); 2582 v8::HandleScope scope(isolate);
2472 LocalContext env; 2583 LocalContext env;
2473 CompileRun("var foo1 = function() {}; " 2584 CompileRun("var foo1 = function() {}; "
2474 "var foo2 = function foo3() {}; " 2585 "var foo2 = function foo3() {}; "
2475 "function not_ctor() { " 2586 "function not_ctor() { "
2476 " var foo4 = function() {}; " 2587 " var foo4 = function() {}; "
2477 " return %FunctionGetInferredName(foo4); " 2588 " return %FunctionGetInferredName(foo4); "
2478 "} " 2589 "} "
2479 "function Ctor() { " 2590 "function Ctor() { "
(...skipping 21 matching lines...) Expand all
2501 ExpectString("%FunctionGetInferredName(obj4[1])", ""); 2612 ExpectString("%FunctionGetInferredName(obj4[1])", "");
2502 ExpectString("%FunctionGetInferredName(obj5['foo9'])", "obj5.foo9"); 2613 ExpectString("%FunctionGetInferredName(obj5['foo9'])", "obj5.foo9");
2503 ExpectString("%FunctionGetInferredName(obj6.obj7.foo10)", "obj6.obj7.foo10"); 2614 ExpectString("%FunctionGetInferredName(obj6.obj7.foo10)", "obj6.obj7.foo10");
2504 } 2615 }
2505 2616
2506 2617
2507 TEST(FuncNameInferrerTwoByte) { 2618 TEST(FuncNameInferrerTwoByte) {
2508 // Tests function name inferring in cases where some parts of the inferred 2619 // Tests function name inferring in cases where some parts of the inferred
2509 // function name are two-byte strings. 2620 // function name are two-byte strings.
2510 i::FLAG_allow_natives_syntax = true; 2621 i::FLAG_allow_natives_syntax = true;
2622 i::FLAG_harmony_arrow_functions = true;
2511 v8::Isolate* isolate = CcTest::isolate(); 2623 v8::Isolate* isolate = CcTest::isolate();
2512 v8::HandleScope scope(isolate); 2624 v8::HandleScope scope(isolate);
2513 LocalContext env; 2625 LocalContext env;
2514 uint16_t* two_byte_source = AsciiToTwoByteString( 2626 uint16_t* two_byte_source = AsciiToTwoByteString(
2515 "var obj1 = { oXj2 : { foo1: function() {} } }; " 2627 "var obj1 = { oXj2 : { foo1: function() {} } }; "
2516 "%FunctionGetInferredName(obj1.oXj2.foo1)"); 2628 "%FunctionGetInferredName(obj1.oXj2.foo1)");
2517 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1"); 2629 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1");
2518 // Make it really non-ASCII (replace the Xs with a non-ASCII character). 2630 // Make it really non-ASCII (replace the Xs with a non-ASCII character).
2519 two_byte_source[14] = two_byte_source[78] = two_byte_name[6] = 0x010d; 2631 two_byte_source[14] = two_byte_source[78] = two_byte_name[6] = 0x010d;
2520 v8::Local<v8::String> source = 2632 v8::Local<v8::String> source =
2521 v8::String::NewFromTwoByte(isolate, two_byte_source); 2633 v8::String::NewFromTwoByte(isolate, two_byte_source);
2522 v8::Local<v8::Value> result = CompileRun(source); 2634 v8::Local<v8::Value> result = CompileRun(source);
2523 CHECK(result->IsString()); 2635 CHECK(result->IsString());
2524 v8::Local<v8::String> expected_name = 2636 v8::Local<v8::String> expected_name =
2525 v8::String::NewFromTwoByte(isolate, two_byte_name); 2637 v8::String::NewFromTwoByte(isolate, two_byte_name);
2526 CHECK(result->Equals(expected_name)); 2638 CHECK(result->Equals(expected_name));
2527 i::DeleteArray(two_byte_source); 2639 i::DeleteArray(two_byte_source);
2528 i::DeleteArray(two_byte_name); 2640 i::DeleteArray(two_byte_name);
2529 } 2641 }
2530 2642
2531 2643
2532 TEST(FuncNameInferrerEscaped) { 2644 TEST(FuncNameInferrerEscaped) {
2533 // The same as FuncNameInferrerTwoByte, except that we express the two-byte 2645 // The same as FuncNameInferrerTwoByte, except that we express the two-byte
2534 // character as a unicode escape. 2646 // character as a unicode escape.
2535 i::FLAG_allow_natives_syntax = true; 2647 i::FLAG_allow_natives_syntax = true;
2648 i::FLAG_harmony_arrow_functions = true;
2536 v8::Isolate* isolate = CcTest::isolate(); 2649 v8::Isolate* isolate = CcTest::isolate();
2537 v8::HandleScope scope(isolate); 2650 v8::HandleScope scope(isolate);
2538 LocalContext env; 2651 LocalContext env;
2539 uint16_t* two_byte_source = AsciiToTwoByteString( 2652 uint16_t* two_byte_source = AsciiToTwoByteString(
2540 "var obj1 = { o\\u010dj2 : { foo1: function() {} } }; " 2653 "var obj1 = { o\\u010dj2 : { foo1: function() {} } }; "
2541 "%FunctionGetInferredName(obj1.o\\u010dj2.foo1)"); 2654 "%FunctionGetInferredName(obj1.o\\u010dj2.foo1)");
2542 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1"); 2655 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1");
2543 // Fix to correspond to the non-ASCII name in two_byte_source. 2656 // Fix to correspond to the non-ASCII name in two_byte_source.
2544 two_byte_name[6] = 0x010d; 2657 two_byte_name[6] = 0x010d;
2545 v8::Local<v8::String> source = 2658 v8::Local<v8::String> source =
2546 v8::String::NewFromTwoByte(isolate, two_byte_source); 2659 v8::String::NewFromTwoByte(isolate, two_byte_source);
2547 v8::Local<v8::Value> result = CompileRun(source); 2660 v8::Local<v8::Value> result = CompileRun(source);
2548 CHECK(result->IsString()); 2661 CHECK(result->IsString());
2549 v8::Local<v8::String> expected_name = 2662 v8::Local<v8::String> expected_name =
2550 v8::String::NewFromTwoByte(isolate, two_byte_name); 2663 v8::String::NewFromTwoByte(isolate, two_byte_name);
2551 CHECK(result->Equals(expected_name)); 2664 CHECK(result->Equals(expected_name));
2552 i::DeleteArray(two_byte_source); 2665 i::DeleteArray(two_byte_source);
2553 i::DeleteArray(two_byte_name); 2666 i::DeleteArray(two_byte_name);
2554 } 2667 }
2555 2668
2556 2669
2557 TEST(RegressionLazyFunctionWithErrorWithArg) { 2670 TEST(RegressionLazyFunctionWithErrorWithArg) {
2558 // The bug occurred when a lazy function had an error which requires a 2671 // The bug occurred when a lazy function had an error which requires a
2559 // parameter (such as "unknown label" here). The error message was processed 2672 // parameter (such as "unknown label" here). The error message was processed
2560 // before the AstValueFactory containing the error message string was 2673 // before the AstValueFactory containing the error message string was
2561 // internalized. 2674 // internalized.
2675 i::FLAG_harmony_arrow_functions = true;
2562 v8::Isolate* isolate = CcTest::isolate(); 2676 v8::Isolate* isolate = CcTest::isolate();
2563 v8::HandleScope scope(isolate); 2677 v8::HandleScope scope(isolate);
2564 LocalContext env; 2678 LocalContext env;
2565 i::FLAG_lazy = true; 2679 i::FLAG_lazy = true;
2566 i::FLAG_min_preparse_length = 0; 2680 i::FLAG_min_preparse_length = 0;
2567 CompileRun("function this_is_lazy() {\n" 2681 CompileRun("function this_is_lazy() {\n"
2568 " break p;\n" 2682 " break p;\n"
2569 "}\n" 2683 "}\n"
2570 "this_is_lazy();\n"); 2684 "this_is_lazy();\n");
2571 } 2685 }
2686
2687
2688 TEST(ErrorsArrowFunctions) {
2689 // Tests that parser and preparser generate the same kind of errors
2690 // on invalid arrow function syntax.
2691 const char* context_data[][2] = {
2692 {"", ";"},
2693 {"v = ", ";"},
2694 {"bar ? (", ") : baz;"},
2695 {"bar ? baz : (", ");"},
2696 {"bar[", "];"},
2697 {"bar, ", ";"},
2698 {"", ", bar;"},
2699 { NULL, NULL }
2700 };
2701
2702 const char* statement_data[] = {
2703 "=> 0",
2704 "=>",
2705 "() =>",
2706 "=> {}",
2707 ") => {}",
2708 ", => {}",
2709 "(,) => {}",
2710 "return => {}",
2711 "() => {'value': 42}",
2712
2713 // Check that the early return introduced in ParsePrimaryExpression
2714 // does not accept stray closing parentheses.
2715 ")",
2716 ") => 0",
2717 "foo[()]",
2718 "()",
2719
2720 // Parameter lists with extra parens should be recognized as errors.
2721 "(()) => 0",
2722 "((x)) => 0",
2723 "((x, y)) => 0",
2724 "(x, (y)) => 0",
2725 "((x, y, z)) => 0",
2726 "(x, (y, z)) => 0",
2727 "((x, y), z) => 0",
2728
2729 // The parameter list is parsed as an expression, but only
2730 // a comma-separated list of identifier is valid.
2731 "32 => {}",
2732 "(32) => {}",
2733 "(a, 32) => {}",
2734 "if => {}",
2735 "(if) => {}",
2736 "(a, if) => {}",
2737 "a + b => {}",
2738 "(a + b) => {}",
2739 "(a + b, c) => {}",
2740 "(a, b - c) => {}",
2741 "\"a\" => {}",
2742 "(\"a\") => {}",
2743 "(\"a\", b) => {}",
2744 "(a, \"b\") => {}",
2745 "-a => {}",
2746 "(-a) => {}",
2747 "(-a, b) => {}",
2748 "(a, -b) => {}",
2749 "{} => {}",
2750 "({}) => {}",
2751 "(a, {}) => {}",
2752 "({}, a) => {}",
2753 "a++ => {}",
2754 "(a++) => {}",
2755 "(a++, b) => {}",
2756 "(a, b++) => {}",
2757 "[] => {}",
2758 "([]) => {}",
2759 "(a, []) => {}",
2760 "([], a) => {}",
2761 "(a = b) => {}",
2762 "(a = b, c) => {}",
2763 "(a, b = c) => {}",
2764 "(foo ? bar : baz) => {}",
2765 "(a, foo ? bar : baz) => {}",
2766 "(foo ? bar : baz, a) => {}",
2767
2768 NULL
2769 };
2770
2771 i::FLAG_harmony_arrow_functions = true;
2772 RunParserSyncTest(context_data, statement_data, kError);
2773 }
2774
2775
2776 TEST(NoErrorsArrowFunctions) {
2777 // Tests that parser and preparser accept valid arrow functions syntax.
2778 const char* context_data[][2] = {
2779 {"", ";"},
2780 {"bar ? (", ") : baz;"},
2781 {"bar ? baz : (", ");"},
2782 {"bar, ", ";"},
2783 {"", ", bar;"},
2784 { NULL, NULL }
2785 };
2786
2787 const char* statement_data[] = {
2788 "() => {}",
2789 "() => { return 42 }",
2790 "x => { return x; }",
2791 "(x) => { return x; }",
2792 "(x, y) => { return x + y; }",
2793 "(x, y, z) => { return x + y + z; }",
2794 "(x, y) => { x.a = y; }",
2795 "() => 42",
2796 "x => x",
2797 "x => x * x",
2798 "(x) => x",
2799 "(x) => x * x",
2800 "(x, y) => x + y",
2801 "(x, y, z) => x, y, z",
2802 "(x, y) => x.a = y",
2803 "() => ({'value': 42})",
2804 "x => y => x + y",
2805 "(x, y) => (u, v) => x*u + y*v",
2806 "(x, y) => z => z * (x + y)",
2807 "x => (y, z) => z * (x + y)",
2808
2809 // Arrow has more precedence, this is the same as: foo ? bar : (baz = {})
2810 "foo ? bar : baz => {}",
2811
2812 NULL
2813 };
2814
2815 i::FLAG_harmony_arrow_functions = true;
2816 RunParserSyncTest(context_data, statement_data, kSuccess);
2817 }
OLDNEW
« src/scanner.h ('K') | « src/token.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698