OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 2439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 not_ctor() { " |
| 2471 " var foo4 = function() {}; " |
| 2472 " return %FunctionGetInferredName(foo4); " |
| 2473 "} " |
| 2474 "function Ctor() { " |
| 2475 " var foo5 = function() {}; " |
| 2476 " return %FunctionGetInferredName(foo5); " |
| 2477 "} " |
| 2478 "var obj1 = { foo6: function() {} }; " |
| 2479 "var obj2 = { 'foo7': function() {} }; " |
| 2480 "var obj3 = {}; " |
| 2481 "obj3[1] = function() {}; " |
| 2482 "var obj4 = {}; " |
| 2483 "obj4[1] = function foo8() {}; " |
| 2484 "var obj5 = {}; " |
| 2485 "obj5['foo9'] = function() {}; " |
| 2486 "var obj6 = { obj7 : { foo10: function() {} } };"); |
| 2487 ExpectString("%FunctionGetInferredName(foo1)", "foo1"); |
| 2488 // foo2 is not unnamed -> its name is not inferred. |
| 2489 ExpectString("%FunctionGetInferredName(foo2)", ""); |
| 2490 ExpectString("not_ctor()", "foo4"); |
| 2491 ExpectString("Ctor()", "Ctor.foo5"); |
| 2492 ExpectString("%FunctionGetInferredName(obj1.foo6)", "obj1.foo6"); |
| 2493 ExpectString("%FunctionGetInferredName(obj2.foo7)", "obj2.foo7"); |
| 2494 ExpectString("%FunctionGetInferredName(obj3[1])", |
| 2495 "obj3.(anonymous function)"); |
| 2496 ExpectString("%FunctionGetInferredName(obj4[1])", ""); |
| 2497 ExpectString("%FunctionGetInferredName(obj5['foo9'])", "obj5.foo9"); |
| 2498 ExpectString("%FunctionGetInferredName(obj6.obj7.foo10)", "obj6.obj7.foo10"); |
| 2499 } |
| 2500 |
| 2501 |
| 2502 TEST(FuncNameInferrerTwoByte) { |
| 2503 // Tests function name inferring in cases where some parts of the inferred |
| 2504 // function name are two-byte strings. |
| 2505 i::FLAG_allow_natives_syntax = true; |
| 2506 v8::Isolate* isolate = CcTest::isolate(); |
| 2507 v8::HandleScope scope(isolate); |
| 2508 LocalContext env; |
| 2509 uint16_t* two_byte_source = AsciiToTwoByteString( |
| 2510 "var obj1 = { oXj2 : { foo1: function() {} } }; " |
| 2511 "%FunctionGetInferredName(obj1.oXj2.foo1)"); |
| 2512 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1"); |
| 2513 // Make it really non-ASCII (replace the Xs with a non-ASCII character). |
| 2514 two_byte_source[14] = two_byte_source[78] = two_byte_name[6] = 0x010d; |
| 2515 v8::Local<v8::String> source = |
| 2516 v8::String::NewFromTwoByte(isolate, two_byte_source); |
| 2517 v8::Local<v8::Value> result = CompileRun(source); |
| 2518 CHECK(result->IsString()); |
| 2519 v8::Local<v8::String> expected_name = |
| 2520 v8::String::NewFromTwoByte(isolate, two_byte_name); |
| 2521 CHECK(result->Equals(expected_name)); |
| 2522 } |
| 2523 |
| 2524 |
| 2525 TEST(FuncNameInferrerEscaped) { |
| 2526 // The same as FuncNameInferrerTwoByte, except that we express the two-byte |
| 2527 // character as a unicode escape. |
| 2528 i::FLAG_allow_natives_syntax = true; |
| 2529 v8::Isolate* isolate = CcTest::isolate(); |
| 2530 v8::HandleScope scope(isolate); |
| 2531 LocalContext env; |
| 2532 uint16_t* two_byte_source = AsciiToTwoByteString( |
| 2533 "var obj1 = { o\\u010dj2 : { foo1: function() {} } }; " |
| 2534 "%FunctionGetInferredName(obj1.o\\u010dj2.foo1)"); |
| 2535 uint16_t* two_byte_name = AsciiToTwoByteString("obj1.oXj2.foo1"); |
| 2536 // Fix to correspond to the non-ASCII name in two_byte_source. |
| 2537 two_byte_name[6] = 0x010d; |
| 2538 v8::Local<v8::String> source = |
| 2539 v8::String::NewFromTwoByte(isolate, two_byte_source); |
| 2540 v8::Local<v8::Value> result = CompileRun(source); |
| 2541 CHECK(result->IsString()); |
| 2542 v8::Local<v8::String> expected_name = |
| 2543 v8::String::NewFromTwoByte(isolate, two_byte_name); |
| 2544 CHECK(result->Equals(expected_name)); |
| 2545 } |
OLD | NEW |