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

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

Issue 310063002: Add tests for FuncNameInferrer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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
« test/cctest/cctest.h ('K') | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2439 matching lines...) Expand 10 before | Expand all | Expand 10 after
2450 RunParserSyncTest(assignment_context_data, bad_statement_data_common, kError); 2450 RunParserSyncTest(assignment_context_data, bad_statement_data_common, kError);
2451 RunParserSyncTest(assignment_context_data, bad_statement_data_for_assignment, 2451 RunParserSyncTest(assignment_context_data, bad_statement_data_for_assignment,
2452 kError); 2452 kError);
2453 2453
2454 RunParserSyncTest(prefix_context_data, good_statement_data, kSuccess); 2454 RunParserSyncTest(prefix_context_data, good_statement_data, kSuccess);
2455 RunParserSyncTest(prefix_context_data, bad_statement_data_common, kError); 2455 RunParserSyncTest(prefix_context_data, bad_statement_data_common, kError);
2456 2456
2457 RunParserSyncTest(postfix_context_data, good_statement_data, kSuccess); 2457 RunParserSyncTest(postfix_context_data, good_statement_data, kSuccess);
2458 RunParserSyncTest(postfix_context_data, bad_statement_data_common, kError); 2458 RunParserSyncTest(postfix_context_data, bad_statement_data_common, kError);
2459 } 2459 }
2460
2461
2462 TEST(FuncNameInferrerBasic) {
2463 // Tests that function names are inferred properly.
2464 i::FLAG_allow_natives_syntax = true;
2465 v8::Isolate* isolate = CcTest::isolate();
2466 v8::HandleScope scope(isolate);
2467 LocalContext env;
2468 CompileRun("var foo1 = function() {}; "
2469 "var foo2 = function foo3() {}; "
2470 "function lazy_not_ctor() { "
2471 " var foo3 = function() {}; "
2472 " return %FunctionGetInferredName(foo3); "
2473 "} "
2474 "function not_lazy_not_ctor() { "
rossberg 2014/06/03 13:48:46 How does this differ from the previous?
marja 2014/06/03 14:16:35 Oops yes, this was supposed to be forcibly non-laz
2475 " var foo4 = function() {}; "
2476 " return %FunctionGetInferredName(foo4); "
2477 "} "
2478 "function Ctor() { "
2479 " var foo5 = function() {}; "
2480 " return %FunctionGetInferredName(foo5); "
2481 "} "
2482 "var obj1 = { foo6: function() {} }; "
2483 "var obj2 = { 'foo7': function() {} }; "
2484 "var obj3 = {}; "
2485 "obj3[1] = function() {}; "
2486 "var obj4 = {}; "
2487 "obj4[1] = function bar() {}; "
2488 "var obj5 = {}; "
2489 "obj5['foo8'] = function() {}; "
2490 "var obj6 = { obj7 : { foo9: function() {} } };");
2491 ExpectString("%FunctionGetInferredName(foo1)", "foo1");
2492 // foo2 is not unnamed -> its name is not inferred.
2493 ExpectString("%FunctionGetInferredName(foo2)", "");
2494 ExpectString("lazy_not_ctor()", "foo3");
2495 ExpectString("not_lazy_not_ctor()", "foo4");
2496 ExpectString("Ctor()", "Ctor.foo5");
rossberg 2014/06/03 13:48:46 Wow...
2497 ExpectString("%FunctionGetInferredName(obj1.foo6)", "obj1.foo6");
2498 ExpectString("%FunctionGetInferredName(obj2.foo7)", "obj2.foo7");
2499 ExpectString("%FunctionGetInferredName(obj3[1])",
2500 "obj3.(anonymous function)");
2501 ExpectString("%FunctionGetInferredName(obj4[1])", "");
2502 ExpectString("%FunctionGetInferredName(obj5['foo8'])", "obj5.foo8");
2503 ExpectString("%FunctionGetInferredName(obj6.obj7.foo9)", "obj6.obj7.foo9");
2504 }
2505
2506
2507 TEST(FuncNameInferrerTwoByte) {
2508 // Tests function name inferring in cases where some parts of the inferred
2509 // function name are two-byte strings.
2510 i::FLAG_allow_natives_syntax = true;
2511 v8::Isolate* isolate = CcTest::isolate();
2512 v8::HandleScope scope(isolate);
2513 LocalContext env;
2514 uint16_t* two_byte_source = AsciiToTwoByteString(
2515 "var obj1 = { oXj2 : { foo1: function() {} } }; "
2516 "%FunctionGetInferredName(obj1.oXj2.foo1)");
2517 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1");
2518 // 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;
2520 v8::Local<v8::String> source =
2521 v8::String::NewFromTwoByte(isolate, two_byte_source);
2522 v8::Local<v8::Value> result = CompileRun(source);
2523 CHECK(result->IsString());
2524 v8::Local<v8::String> expected_name =
2525 v8::String::NewFromTwoByte(isolate, two_byte_name);
2526 CHECK(result->Equals(expected_name));
2527 }
2528
2529
2530 TEST(FuncNameInferrerEscaped) {
2531 // The same as FuncNameInferrerTwoByte, except that we express the two-byte
2532 // character as a unicode escape.
2533 i::FLAG_allow_natives_syntax = true;
2534 v8::Isolate* isolate = CcTest::isolate();
2535 v8::HandleScope scope(isolate);
2536 LocalContext env;
2537 uint16_t* two_byte_source = AsciiToTwoByteString(
2538 "var obj1 = { o\\u010dj2 : { foo1: function() {} } }; "
2539 "%FunctionGetInferredName(obj1.o\\u010dj2.foo1)");
2540 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1");
2541 // Fix to correspond to the non-ASCII name in two_byte_source.
2542 two_byte_name[6] = 0x010d;
2543 v8::Local<v8::String> source =
2544 v8::String::NewFromTwoByte(isolate, two_byte_source);
2545 v8::Local<v8::Value> result = CompileRun(source);
2546 CHECK(result->IsString());
2547 v8::Local<v8::String> expected_name =
2548 v8::String::NewFromTwoByte(isolate, two_byte_name);
2549 CHECK(result->Equals(expected_name));
2550 }
OLDNEW
« test/cctest/cctest.h ('K') | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698